geopandas
Python library for working with geospatial vector data including shapefiles, GeoJSON, and GeoPackage files. Use when working with geographic data for spatial analysis, geometric operations, coordinate transformations, spatial joins, overlay operations, choropleth mapping, or any task involving reading/writing/analyzing vector geographic data. Supports PostGIS databases, interactive maps, and integration with matplotlib/folium/cartopy. Use for tasks like buffer analysis, spatial joins between datasets, dissolving boundaries, clipping data, calculating areas/distances, reprojecting coordinate systems, creating maps, or converting between spatial file formats.
Author
Category
Development ToolsInstall
Download and extract to your skills directory
Copy command and send to OpenClaw for auto-install:
GeoPandas - Python Geospatial Data Analysis Skills
Skill Overview
GeoPandas is a powerful Python library for handling and analyzing geospatial vector data. It combines pandas' data processing capabilities with shapely's geometric operations, making geospatial data analysis simple and efficient.
Applicable Scenarios
1. Geospatial Data Analysis
When you need to work with data that contains geographic location information, GeoPandas is an ideal choice. Whether analyzing urban population distribution, studying environmental change patterns, or performing site selection analysis for business, it helps you efficiently perform spatial statistics, aggregation, and geometric operations.
2. Map Making and Visualization
Need to create professional map charts? GeoPandas supports everything from simple thematic maps to complex multi-layer overlay maps. You can easily create choropleth maps, heat maps, and even generate interactive web maps, integrating seamlessly with visualization libraries like matplotlib, folium, and cartopy.
3. Spatial Data Processing and Conversion
When handling various formats of geospatial data files, GeoPandas provides a unified interface. It supports mainstream formats such as Shapefile, GeoJSON, and GeoPackage, and can connect directly to PostGIS databases. Need coordinate transformations, format conversions, or geometric operations? Often just one line of code is enough.
Core Features
1. Read and Write Multiple Formats
GeoPandas supports more than 10 geospatial data formats, including Shapefile, GeoJSON, GeoPackage, KML, and more. You can precisely read needed data using bounding box filtering, spatial masks, etc., and it supports Arrow acceleration for 2–4x read/write performance improvements. It can also read spatial data directly from PostGIS databases, enabling seamless integration with databases.
2. Spatial Analysis and Geometric Operations
It provides a comprehensive set of spatial analysis tools: buffer analysis, spatial joins, overlay analysis, boundary merging, and more. It supports various spatial predicates (intersects, contains, nearest, etc.) for data association and can calculate geometric attributes like area, distance, and centroid. Advanced operations like geometry simplification and affine transformations are also supported.
3. Coordinate Reference System Management
Built-in comprehensive coordinate reference system (CRS) management features support EPSG code recognition and transformations. You can flexibly convert between geographic and projected coordinate systems to ensure accurate area and distance calculations. It automatically handles the complex details of coordinate transformations, making spatial analysis results more reliable.
Frequently Asked Questions
What is GeoPandas? What is it used for?
GeoPandas is a geospatial data analysis library for Python that extends pandas to support geometric types and spatial operations. It is mainly used to read/write vector geospatial data files (like Shapefile, GeoJSON), perform spatial analysis (such as buffers and spatial joins), create maps, and perform CRS transformations. It is applicable to urban planning, environmental science, transportation, epidemiology, and any scenario that involves geographic location data.
How to install GeoPandas and its dependencies?
For a basic install, use pip install geopandas. Optional dependencies can be added as needed: folium (interactive maps), mapclassify (classification schemes), pyarrow (I/O acceleration), psycopg2 and geoalchemy2 (PostGIS support), contextily (basemaps), cartopy (map projections). It is recommended to use a virtual environment to manage dependencies and avoid version conflicts.
Which geospatial data formats does GeoPandas support?
GeoPandas, via the Fiona library, supports many vector formats: Shapefile (.shp), GeoJSON (.geojson), GeoPackage (.gpkg), KML, GML, FileGDB, and more. It also supports reading spatial tables from PostGIS databases and geospatial data in Parquet format. For writing, GeoPackage is recommended as a modern open standard that is more efficient and reliable than Shapefile.
How to perform Coordinate Reference System (CRS) transformations?
Use the gdf.to_crs("EPSG:XXXX") method to transform the CRS. Before doing so, it is recommended to check the current CRS (gdf.crs) and ensure both datasets use the same CRS before performing spatial analysis. Use projected coordinate systems (e.g., UTM) when computing area and distance; geographic coordinate systems (e.g., WGS84/EPSG:4326) are commonly used for mapping.
Can GeoPandas read PostGIS databases?
Yes. After installing psycopg2 and geoalchemy2, use gpd.read_postgis() to read spatial data from a PostGIS database. You need to provide a database connection engine, an SQL query, and the name of the geometry column. This approach is suitable for handling large amounts of geospatial data or integrating with existing GIS systems.
How to create interactive maps?
Use the gdf.explore() method to quickly generate interactive maps, with options to specify color columns, add legends, set popups, etc. The generated maps can be saved as HTML files and opened in a browser to support zooming, panning, and clicking to view details. Under the hood it uses the folium library and integrates seamlessly with the Leaflet.js ecosystem.
What is the difference between GeoPandas and pandas?
GeoPandas is an extension of pandas specifically for geospatial data. The core difference is that a GeoDataFrame has a special geometry column (geometry) that stores spatial information and supports spatial operations and CRS. A regular DataFrame can only handle tabular data and cannot understand geographic relationships. GeoPandas inherits all of pandas' data analysis capabilities while adding GIS functions like buffering, spatial joins, and overlay analysis.
How to calculate the area and distance of geographic regions?
First convert your data to a projected coordinate system (gdf.to_crs()), then use gdf.geometry.area to calculate area and gdf.geometry.distance() to calculate distance. Distance calculations can be between two geometry objects or by using sjoin_nearest() to find nearest neighbors. Note that calculating area and distance directly in geographic coordinates (e.g., latitude/longitude) is inaccurate; you must project first.