3 Best Geospatial Python Libraries

Python libraries for working with geospatial data, GIS, and mapping

Sean Knight

--

Photo by Kayla Duhon on Unsplash

1. GeoPandas

If you want to start working with geospatial data in Python (and you already know how to use Pandas), the GeoPandas library would be my first recommendation of where to start.

GeoPandas works a lot like regular Pandas, but GeoPandas adds support for the geographic component of geospatial data.

GeoPandas adds this support in many ways, but the most obvious difference you’ll notice is when you turn a Pandas DataFrame into a GeoPandas GeoDataFrame.

The GeoDataFrame has a column called “Geometry” that is used for the location information for that row of data. The geometry may be a Point, LineString, or a Polygon — the three shape configurations in GeoPandas.

GeoPandas also supports assigning and changing the map projection you are working with by providing functions for the coordinate reference system.

For example, if you use the to_crs() function to change the coordinate reference system of your map, it will alter all the coordinates in the geometry data column to match that new map projection.

Of course, GeoPandas also supports mapping with a wealth of features to explore. For mapping, Geopandas uses Fiona and Shapely, which are other common geospatial Python libraries.

And if all of that wasn’t enough, GeoPandas has a powerful function for importing geospatial data into a GeoDataFrame. This is done using the read_file() function, which can pull in data from GeoJSON, ESRI shapefiles, and other common spatial data formats.

Oddly the only exception here is that it cannot create a GeoDataFrame from a csv file. But there’s a quick workaround. You can use Pandas to import the csv file into a DataFrame and then convert the DataFrame to a GeoDataFrame. Here’s how that looks:

import geopandas as gpd
import pandas as pd
data_input_path = "../myDataPath"df = pd.read_csv(data_input_path)gdf = gpd.GeoDataFrame(df, geometry=gpd.points_from_xy(df.lon, df.lat))

2. Folium

--

--