Exercises
If you are interested in exploring the techniques used in this chapter further, you might like to challenge yourself with the following tasks:
Change the bounding box calculation to exclude outlying islands.
Tip
Hint
You can split each country's MultiPolygon into individual Polygon objects and then check the area of each polygon to exclude those that are smaller than a given total value.
Use the World Borders Dataset to create a new shapefile, where each country is represented by a single Point geometry containing the geographical center of each country.
Tip
Hint
You can start with the country bounding boxes we calculated earlier and then calculate the midpoint using this:
midLat = (minLat + maxLat) / 2 midLong = (minLong + maxLong) / 2
For an extra challenge, you could use Shapely's
centroid()
method to calculate a more accurate representation of each country's center. To do this, you would have to convert the country's outline into a Shapely geometry, calculate the centroid, and then...