Manipulating geospatial data with Cartopy
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 (http://www.naturalearthdata.com) to display the countries of Africa, color coded with their population and Gross Domestic Product (GDP). This type of graph is called a choropleth map.
Shapefile (https://en.wikipedia.org/wiki/Shapefile) is a popular geospatial vector data format for GIS software. It can be read by Cartopy
, a GIS package in Python.
Getting ready
You need Cartopy, available at http://scitools.org.uk/cartopy/. You can install it with conda install -c conda-forge cartopy
.
How to do it...
- Let's import the packages:
>>> import io import requests import zipfile import numpy as np import matplotlib.pyplot as plt import matplotlib.collections as col from matplotlib.colors import Normalize import cartopy.crs as ccrs from cartopy.feature import ShapelyFeature...