鱼皮AI导航
鱼皮AI导航
  • 主页
  • 社区
  • AI工具
  • AI知识库
  • AI提示词
  • MCP
  • Skills
  • AI学习资源
  • AI资讯
  • GitHub开源
登录/注册

geopandas

提供地理空间矢量数据的全流程处理能力,涵盖多种格式的读写、坐标系管理、几何运算、空间分析、可视化及数据库集成,支持缓冲区分析、空间连接、叠加分析、边界融合、地图绘制等专业地理信息任务。

数据与分析
访问 GitHub
文档Skills.MD
name
geopandas
description
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.

GeoPandas

GeoPandas extends pandas to enable spatial operations on geometric types. It combines the capabilities of pandas and shapely for geospatial data analysis.

Installation

▼
bash
复制代码
uv pip install geopandas

Optional Dependencies

▼
bash
复制代码
# For interactive maps uv pip install folium # For classification schemes in mapping uv pip install mapclassify # For faster I/O operations (2-4x speedup) uv pip install pyarrow # For PostGIS database support uv pip install psycopg2 uv pip install geoalchemy2 # For basemaps uv pip install contextily # For cartographic projections uv pip install cartopy

Quick Start

▼
python
复制代码
import geopandas as gpd # Read spatial data gdf = gpd.read_file("data.geojson") # Basic exploration print(gdf.head()) print(gdf.crs) print(gdf.geometry.geom_type) # Simple plot gdf.plot() # Reproject to different CRS gdf_projected = gdf.to_crs("EPSG:3857") # Calculate area (use projected CRS for accuracy) gdf_projected['area'] = gdf_projected.geometry.area # Save to file gdf.to_file("output.gpkg")

Core Concepts

Data Structures

  • GeoSeries: Vector of geometries with spatial operations
  • GeoDataFrame: Tabular data structure with geometry column

See data-structures.md for details.

Reading and Writing Data

GeoPandas reads/writes multiple formats: Shapefile, GeoJSON, GeoPackage, PostGIS, Parquet.

▼
python
复制代码
# Read with filtering gdf = gpd.read_file("data.gpkg", bbox=(xmin, ymin, xmax, ymax)) # Write with Arrow acceleration gdf.to_file("output.gpkg", use_arrow=True)

See data-io.md for comprehensive I/O operations.

Coordinate Reference Systems

Always check and manage CRS for accurate spatial operations:

▼
python
复制代码
# Check CRS print(gdf.crs) # Reproject (transforms coordinates) gdf_projected = gdf.to_crs("EPSG:3857") # Set CRS (only when metadata missing) gdf = gdf.set_crs("EPSG:4326")

See crs-management.md for CRS operations.

Common Operations

Geometric Operations

Buffer, simplify, centroid, convex hull, affine transformations:

▼
python
复制代码
# Buffer by 10 units buffered = gdf.geometry.buffer(10) # Simplify with tolerance simplified = gdf.geometry.simplify(tolerance=5, preserve_topology=True) # Get centroids centroids = gdf.geometry.centroid

See geometric-operations.md for all operations.

Spatial Analysis

Spatial joins, overlay operations, dissolve:

▼
python
复制代码
# Spatial join (intersects) joined = gpd.sjoin(gdf1, gdf2, predicate='intersects') # Nearest neighbor join nearest = gpd.sjoin_nearest(gdf1, gdf2, max_distance=1000) # Overlay intersection intersection = gpd.overlay(gdf1, gdf2, how='intersection') # Dissolve by attribute dissolved = gdf.dissolve(by='region', aggfunc='sum')

See spatial-analysis.md for analysis operations.

Visualization

Create static and interactive maps:

▼
python
复制代码
# Choropleth map gdf.plot(column='population', cmap='YlOrRd', legend=True) # Interactive map gdf.explore(column='population', legend=True).save('map.html') # Multi-layer map import matplotlib.pyplot as plt fig, ax = plt.subplots() gdf1.plot(ax=ax, color='blue') gdf2.plot(ax=ax, color='red')

See visualization.md for mapping techniques.

Detailed Documentation

  • Data Structures - GeoSeries and GeoDataFrame fundamentals
  • Data I/O - Reading/writing files, PostGIS, Parquet
  • Geometric Operations - Buffer, simplify, affine transforms
  • Spatial Analysis - Joins, overlay, dissolve, clipping
  • Visualization - Plotting, choropleth maps, interactive maps
  • CRS Management - Coordinate reference systems and projections

Common Workflows

Load, Transform, Analyze, Export

▼
python
复制代码
# 1. Load data gdf = gpd.read_file("data.shp") # 2. Check and transform CRS print(gdf.crs) gdf = gdf.to_crs("EPSG:3857") # 3. Perform analysis gdf['area'] = gdf.geometry.area buffered = gdf.copy() buffered['geometry'] = gdf.geometry.buffer(100) # 4. Export results gdf.to_file("results.gpkg", layer='original') buffered.to_file("results.gpkg", layer='buffered')

Spatial Join and Aggregate

▼
python
复制代码
# Join points to polygons points_in_polygons = gpd.sjoin(points_gdf, polygons_gdf, predicate='within') # Aggregate by polygon aggregated = points_in_polygons.groupby('index_right').agg({ 'value': 'sum', 'count': 'size' }) # Merge back to polygons result = polygons_gdf.merge(aggregated, left_index=True, right_index=True)

Multi-Source Data Integration

▼
python
复制代码
# Read from different sources roads = gpd.read_file("roads.shp") buildings = gpd.read_file("buildings.geojson") parcels = gpd.read_postgis("SELECT * FROM parcels", con=engine, geom_col='geom') # Ensure matching CRS buildings = buildings.to_crs(roads.crs) parcels = parcels.to_crs(roads.crs) # Perform spatial operations buildings_near_roads = buildings[buildings.geometry.distance(roads.union_all()) < 50]

Performance Tips

  1. Use spatial indexing: GeoPandas creates spatial indexes automatically for most operations
  2. Filter during read: Use bbox, mask, or where parameters to load only needed data
  3. Use Arrow for I/O: Add use_arrow=True for 2-4x faster reading/writing
  4. Simplify geometries: Use .simplify() to reduce complexity when precision isn't critical
  5. Batch operations: Vectorized operations are much faster than iterating rows
  6. Use appropriate CRS: Projected CRS for area/distance, geographic for visualization

Best Practices

  1. Always check CRS before spatial operations
  2. Use projected CRS for area and distance calculations
  3. Match CRS before spatial joins or overlays
  4. Validate geometries with .is_valid before operations
  5. Use .copy() when modifying geometry columns to avoid side effects
  6. Preserve topology when simplifying for analysis
  7. Use GeoPackage format for modern workflows (better than Shapefile)
  8. Set max_distance in sjoin_nearest for better performance
数据与分析

快捷安装

复制到终端去安装 Skill

npxskillsadddavila7/claude-code-templates--skill"geopandas"
站长:程序员鱼皮 老鱼简历 商务合作 增值电信业务经营许可证
2026 鱼皮AI导航 | 沪ICP备19026706号-6
站长:程序员鱼皮 老鱼简历 商务合作 增值电信业务经营许可证
2026 鱼皮AI导航 | 沪ICP备19026706号-6
🔥热门工具
朱雀AI检测朱雀AI检测
朱雀AI检测助手朱雀AI检测助手
LovartLovart
老鱼简历老鱼简历
WritePass官网WritePass官网
面多多面多多
CursorCursor
星月写作星月写作
朱雀AI检测助手朱雀AI检测助手
零感AI零感AI
Skills 推荐
definition-of-done-generator
自动生成项目完成标准的规范定义与配置文件,提供符合企业级工作流要求的最佳实践指导,输出可直接投入生产环境的代码和验证结果,适用于需要标准化流程审批、合规审查及跨系统集成的复杂项目管理场景。
sagemaker-endpoint-deployer
自动化部署机器学习模型至云端服务端点,支持从配置生成到生产验证的全流程,适用于模型上线、服务监控与推理优化等场景,确保部署方案符合工业级标准。
docx
支持专业级 Word 文档的全生命周期处理,包括从零创建结构化文档、精准编辑内容、管理修订痕迹与批注、提取纯文本或原始 XML 数据、转换为 PDF 或图像用于视觉分析,适用于法律、学术及企业场景下的高保真文档协作与自动化处理。
skills-search
提供对 Claude Code 技能生态的全周期管理能力,支持按功能关键词检索技能、查看详细信息、安装或卸载指定技能,并区分用户级与项目级作用域,覆盖发现、评估、部署及维护各环节。
moai-foundation-core
构建高质量、可扩展的AI开发工作流,通过领域驱动设计与模块化架构实现需求规范先行,结合自动化质量门禁、精细化上下文管理与渐进式知识呈现,在保障安全与可维护性的同时提升开发效率与协作清晰度。