GeoPandas extends pandas functionality to handle geographic and geospatial data operations with GeoSeries and GeoDataFrame classes.
npx @tessl/cli install tessl/pypi-geopandas@1.1.0GeoPandas is a comprehensive Python library that extends pandas functionality to handle geographic and geospatial data operations. It provides GeoSeries and GeoDataFrame classes as subclasses of pandas Series and DataFrame, enabling users to work with shapely geometry objects and perform geometric operations directly within the familiar pandas data manipulation framework.
pip install geopandasimport geopandas as gpdCommon imports for working with geometry data:
import geopandas as gpd
import pandas as pd
from shapely.geometry import Point, Polygon, LineStringimport geopandas as gpd
import pandas as pd
from shapely.geometry import Point
# Create a GeoDataFrame from points
geometry = [Point(xy) for xy in zip([-1, 0, 1], [1, 0, -1])]
df = pd.DataFrame({'City': ['City A', 'City B', 'City C']})
gdf = gpd.GeoDataFrame(df, geometry=geometry)
# Read geospatial data from file
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
cities = gpd.read_file(gpd.datasets.get_path('naturalearth_cities'))
# Basic geospatial operations
world_area = world.geometry.area
world_centroid = world.geometry.centroid
world_bounds = world.total_bounds
# Coordinate reference system transformations
world_utm = world.to_crs('EPSG:3857') # Web Mercator projection
# Spatial joins
cities_in_countries = gpd.sjoin(cities, world, how='left', predicate='within')
# Create a simple plot
world.plot(figsize=(10, 6))GeoPandas extends the pandas ecosystem with geospatial capabilities:
This design provides seamless integration with pandas workflows while adding comprehensive geospatial functionality through shapely geometric objects, coordinate system management, and spatial file I/O capabilities.
GeoDataFrame and GeoSeries classes that extend pandas functionality with geometry column support, spatial properties, and coordinate reference system management.
class GeoDataFrame(DataFrame):
def __init__(data=None, index=None, columns=None, dtype=None, copy=None, geometry=None, crs=None): ...
class GeoSeries(Series):
def __init__(data=None, index=None, crs=None, **kwargs): ...Reading and writing various geospatial file formats including Shapefile, GeoJSON, GeoPackage, Parquet, and database connections.
def read_file(filename, **kwargs): ...
def read_parquet(path, **kwargs): ...
def read_feather(path, **kwargs): ...
def read_postgis(sql, con, **kwargs): ...
def list_layers(filename): ...CRS management and coordinate transformations enabling work with different spatial reference systems and projections.
def set_crs(crs, allow_override=False, inplace=False): ...
def to_crs(crs, **kwargs): ...
def estimate_utm_crs(datum_name='WGS 84'): ...Spatial analysis and geometric computations including buffering, simplification, area calculations, and spatial predicates.
def buffer(distance, resolution=16, **kwargs): ...
def simplify(tolerance, preserve_topology=True): ...
def area(): ...
def length(): ...
def centroid(): ...
def boundary(): ...
def convex_hull(): ...
def envelope(): ...Spatial joins, overlays, and relationship testing between geometric objects including intersection, union, and containment operations.
def sjoin(left_df, right_df, how='inner', predicate='intersects', lsuffix='left', rsuffix='right', **kwargs): ...
def sjoin_nearest(left_df, right_df, how='inner', max_distance=None, lsuffix='left', rsuffix='right', **kwargs): ...
def overlay(df1, df2, how='intersection', keep_geom_type=None, make_valid=True): ...
def clip(gdf, mask, keep_geom_type=False, sort=False): ...Static and interactive mapping capabilities for creating publication-quality maps and exploratory data visualizations.
def plot(ax=None, figsize=None, color=None, edgecolor=None, **kwargs): ...
def explore(color=None, marker_type='marker', tiles='OpenStreetMap', **kwargs): ...Assertion functions and version information utilities for testing geospatial data structures and debugging dependency issues.
def assert_geoseries_equal(left, right, **kwargs): ...
def assert_geodataframe_equal(left, right, **kwargs): ...
def show_versions(): ...