GeoPandas Spatial Operations on Shapely Objects
GeoPandas extends the Python geospatial stack by wrapping Shapely
geometric objects inside pandas data structures (GeoSeries
and GeoDataFrame). While Shapely provides the foundation
for individual geometric objects (such as points, linestrings, and
polygons), GeoPandas applies these operations across entire datasets
using vectorized operations. This article outlines the core spatial
operations supported by GeoPandas, ranging from basic geometric
measurements and spatial predicates to complex spatial joins, overlays,
and aggregations.
Geometric Measurements and Properties
GeoPandas exposes standard geometric properties directly as
vectorized attributes on GeoSeries and
GeoDataFrame objects:
area: Computes the 2D surface area of polygon or multipolygon geometries.length: Calculates the perimeter of polygon geometries or the length of line geometries.bounds: Returns a DataFrame containing the minimum and maximum coordinate values (minx,miny,maxx,maxy) for each geometry.total_bounds: Returns an array with the overall bounding box of the entire series.distance(other): Calculates the minimum Euclidean distance from each geometry in the series to another geometry or aligned series.
Geometric Transformations and Constructors
GeoPandas allows you to construct new geometries from existing ones element-by-element:
buffer(distance): Generates a new polygon representing all points within a specified distance of the geometry.centroid: Computes the geometric center point of each geometry.representative_point(): Returns a point guaranteed to lie within the geometry (unlike centroids, which can fall outside concave polygons).convex_hull: Computes the smallest convex polygon that encloses all points of the geometry.envelope: Returns the minimum axis-aligned bounding rectangle containing each geometry.simplify(tolerance): Reduces the number of vertices in geometries using algorithms such as Douglas-Peucker.boundary: Extracts the lower-dimensional boundary of each geometry (e.g., lines from polygons, points from lines).
Spatial Predicates (Binary Relationships)
Spatial predicates evaluate the topological relationship between two geometries and return boolean values. GeoPandas vectorizes these operations against single geometries or aligned series:
intersects(other): ReturnsTrueif geometries share any point in common.contains(other): ReturnsTrueif no points of the other geometry lie outside the base geometry.within(other): ReturnsTrueif the base geometry lies entirely inside the other geometry.crosses(other): ReturnsTrueif geometries intersect, but neither fully contains the other.touches(other): ReturnsTrueif geometries have at least one common boundary point, but their interiors do not intersect.disjoint(other): ReturnsTrueif geometries share no points in common.overlaps(other): ReturnsTrueif geometries share interior space of the same dimension without one containing the other.covers(other)/covered_by(other): Similar tocontainsandwithin, but also includes boundaries.
Set-Theoretic Operations
GeoPandas supports element-wise set operations to produce new geometries derived from intersections and differences:
intersection(other): Generates the common portion shared by pairs of geometries.union(other): Combines the geometric spaces of pairs of geometries.difference(other): Subtracts the portion of the other geometry from the base geometry.symmetric_difference(other): Retains regions found in either geometry, excluding their overlap.
Dataset-Level Spatial Operations
Beyond element-wise operations, GeoPandas offers dataset-level tools that operate on entire tables:
Spatial Joins
(sjoin and sjoin_nearest)
gpd.sjoin(): Merges attributes from twoGeoDataFrameobjects based on their spatial relationship (using predicates likeintersects,within, orcontains).gpd.sjoin_nearest(): Joins attributes based on proximity, matching features in one dataset to their nearest geometric neighbor in another.
Spatial Overlays
(overlay)
gpd.overlay(): Computes new geometries by combining two polygon layers using set-theoretic algorithms (intersection,union,difference,symmetric_difference, oridentity). Unlike element-wise methods,overlaycomputes interactions across all intersecting features in the layers.
Spatial Aggregation
(dissolve)
GeoDataFrame.dissolve(): Mirrors the pandasgroupbyfunction, aggregating rows based on common column values and merging their associated geometries using Shapely'sunary_union.