18  GeoPandas

18.1 Read a spatial file

import geopandas as gpd

gdf = gpd.read_file("data/municipalities.gpkg")
gdf.head()

18.2 Inspect the CRS and geometry

print(gdf.crs)
print(gdf.geometry.geom_type.value_counts())

18.3 Reproject

projected = gdf.to_crs("EPSG:6372")

18.4 Attribute join

joined = gdf.merge(attributes, on="cve_geo", how="left")

18.5 Things to remember

  • A GeoDataFrame has one active geometry column.
  • Use merge for attribute keys and sjoin for spatial relationships.
  • Check the CRS before spatial operations.