A Tutorial On geopandas

Article by:
Date Published:
Last Modified:

Overview

geopandas is a Python library that adds extra functionality to pandas to make it more useful for dealing with geospatial data.

Most of the code examples below assume you have imported geopandas into the current module with:

1
import geopandas

Plotting

geopandas makes it very easy to plot geospatial data onto graphs.

1
2
world = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres'))
world.plot(figsize=(10,10))
The plot generated by the 'naturalearth_lowres' dataset that is bundled with geopandas.

The plot generated by the ’naturalearth_lowres’ dataset that is bundled with geopandas.

If you want to save the plot, you can import matplotlib.pyplot and use the standard save_fig() function:

1
2
import matplotlib.pyplot as plt
plt.save_fig('plot.png')

Common Warnings/Errors

Missing package rtree

1
/usr/local/lib/python3.7/site-packages/geopandas/base.py:116: UserWarning: Cannot generate spatial index: Missing package `rtree`.

You are missing the package rtree. rtree can not usually easily be installed with pip alone because it depends on a number of dependencies that pip does not manage. It is best to use your systems package manager to install rtree instead.

No module named descartes

1
ModuleNotFoundError: No module named 'descartes'

Running pip install geopandas does not install the dependency descartes automatically. descartes is needed when plotting, for example when you call .plot(). Install with:

1
pip install descartes

Authors

Geoffrey Hunter

Dude making stuff.

Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License .

Related Content:

Tags

comments powered by Disqus