GeoPandas
GeoPandas extends the popular Python data analysis library pandas by adding support for geographic data. It introduces GeoSeries and GeoDataFrame types, which are subclasses of pandas.Series and pandas.DataFrame, respectively, allowing for the manipulation and analysis of geometric objects. GeoPandas is currently at version 1.1.3, with frequent patch releases addressing compatibility and bug fixes, and major releases periodically introducing significant changes and dependency updates.
Warnings
- breaking GeoPandas 1.0 dropped support for Shapely < 2 and PyGEOS. It strictly requires Shapely >= 2. The `rtree` package for spatial indexing was also removed. If your project relied on older Shapely versions or PyGEOS, you must upgrade Shapely to version 2.0 or newer.
- breaking The default I/O engine for reading and writing files (`gpd.read_file`, `gdf.to_file`) changed from Fiona to Pyogrio in GeoPandas 1.0. While `pyogrio` is now installed by default, ensure compatibility if you had specific configurations or relied on Fiona's unique behaviors.
- breaking The `geopandas.datasets` module (e.g., `geopandas.datasets.get_path('naturalearth_lowres')`) has been removed in GeoPandas 1.0. Sample datasets are now available through the `geodatasets` library.
- deprecated Manually setting the Coordinate Reference System (CRS) via direct assignment (e.g., `gdf.crs = 'EPSG:4326'`) is deprecated. This method can lead to unexpected behavior or data corruption.
- gotcha Installing GeoPandas with `pip` can be challenging on some systems due to its dependencies on low-level C libraries like GEOS, GDAL, and PROJ. Missing or incorrectly compiled C libraries often lead to installation failures or import errors.
- gotcha Spatial join operations (`gpd.sjoin()`) and spatial indexing (`sindex`) can fail with `RTreeError: Coordinates must not have minimums more than maximums` or similar errors if geometries are invalid (e.g., self-intersections, empty geometries) or if DataFrame indices are not clean and sequential.
- breaking GeoPandas 1.1 requires Python 3.10 or greater, and updated minimum versions for core dependencies: pandas 2.0, numpy 1.24, and pyproj 3.5.
Install
-
pip install geopandas -
conda install -c conda-forge geopandas
Imports
- GeoDataFrame
from geopandas import GeoDataFrame
- GeoSeries
from geopandas import GeoSeries
- read_file
import geopandas as gpd gdf = gpd.read_file(...)
Quickstart
import geopandas as gpd
import geodatasets
import matplotlib.pyplot as plt
# Load a sample dataset (New York City boroughs)
path = geodatasets.get_path('ny.bb')
nybb = gpd.read_file(path)
print("GeoDataFrame Head:")
print(nybb.head())
print("\nCoordinate Reference System (CRS):")
print(nybb.crs)
# Plot the GeoDataFrame
fig, ax = plt.subplots(1, 1, figsize=(10, 10))
nybb.plot(ax=ax, color='lightgray', edgecolor='black')
ax.set_title('New York City Boroughs')
plt.show()