Manipulating geospatial data with Shapely and basemap

In this recipe, we will show how to load and display geographical data in the Shapefile format. Specifically, we will use data from Natural Earth (www.naturalearthdata.com) to display the countries of Africa, color coded with their population and Gross Domestic Product (GDP).

Shapefile (http://en.wikipedia.org/wiki/Shapefile) is a popular geospatial vector data format for GIS software. It can be read by Fiona, a Python wrapper to GDAL/OGR (a C++ library supporting GIS file formats). We will also use Shapely, a Python package used to handle two-dimensional geometrical shapes, and descartes, used to render Shapely shapes in matplotlib. Finally, we will use basemap to plot maps.

Getting ready

Get IPython Interactive Computing and Visualization Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.