geopandas by davila7/claude-code-templates
npx skills add https://github.com/davila7/claude-code-templates --skill geopandasGeoPandas 扩展了 pandas 的功能,使其能够对几何类型进行空间操作。它结合了 pandas 和 shapely 的能力,用于地理空间数据分析。
uv pip install geopandas
# 用于交互式地图
uv pip install folium
# 用于地图中的分类方案
uv pip install mapclassify
# 用于更快的 I/O 操作(2-4 倍加速)
uv pip install pyarrow
# 用于 PostGIS 数据库支持
uv pip install psycopg2
uv pip install geoalchemy2
# 用于底图
uv pip install contextily
# 用于制图投影
uv pip install cartopy
import geopandas as gpd
# 读取空间数据
gdf = gpd.read_file("data.geojson")
# 基础探索
print(gdf.head())
print(gdf.crs)
print(gdf.geometry.geom_type)
# 简单绘图
gdf.plot()
# 重新投影到不同的 CRS
gdf_projected = gdf.to_crs("EPSG:3857")
# 计算面积(使用投影后的 CRS 以获得准确结果)
gdf_projected['area'] = gdf_projected.geometry.area
# 保存到文件
gdf.to_file("output.gpkg")
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
详情请参阅 data-structures.md。
GeoPandas 可以读取/写入多种格式:Shapefile、GeoJSON、GeoPackage、PostGIS、Parquet。
# 带过滤条件的读取
gdf = gpd.read_file("data.gpkg", bbox=(xmin, ymin, xmax, ymax))
# 使用 Arrow 加速写入
gdf.to_file("output.gpkg", use_arrow=True)
全面的 I/O 操作请参阅 data-io.md。
为确保空间操作的准确性,请始终检查和管理 CRS:
# 检查 CRS
print(gdf.crs)
# 重新投影(转换坐标)
gdf_projected = gdf.to_crs("EPSG:3857")
# 设置 CRS(仅在元数据缺失时使用)
gdf = gdf.set_crs("EPSG:4326")
CRS 操作请参阅 crs-management.md。
缓冲区、简化、质心、凸包、仿射变换:
# 创建 10 个单位的缓冲区
buffered = gdf.geometry.buffer(10)
# 使用容差简化
simplified = gdf.geometry.simplify(tolerance=5, preserve_topology=True)
# 获取质心
centroids = gdf.geometry.centroid
所有操作请参阅 geometric-operations.md。
空间连接、叠加操作、融合:
# 空间连接(相交)
joined = gpd.sjoin(gdf1, gdf2, predicate='intersects')
# 最近邻连接
nearest = gpd.sjoin_nearest(gdf1, gdf2, max_distance=1000)
# 叠加求交
intersection = gpd.overlay(gdf1, gdf2, how='intersection')
# 按属性融合
dissolved = gdf.dissolve(by='region', aggfunc='sum')
分析操作请参阅 spatial-analysis.md。
创建静态和交互式地图:
# 分级统计图
gdf.plot(column='population', cmap='YlOrRd', legend=True)
# 交互式地图
gdf.explore(column='population', legend=True).save('map.html')
# 多图层地图
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
gdf1.plot(ax=ax, color='blue')
gdf2.plot(ax=ax, color='red')
制图技术请参阅 visualization.md。
# 1. 加载数据
gdf = gpd.read_file("data.shp")
# 2. 检查并转换 CRS
print(gdf.crs)
gdf = gdf.to_crs("EPSG:3857")
# 3. 执行分析
gdf['area'] = gdf.geometry.area
buffered = gdf.copy()
buffered['geometry'] = gdf.geometry.buffer(100)
# 4. 导出结果
gdf.to_file("results.gpkg", layer='original')
buffered.to_file("results.gpkg", layer='buffered')
# 将点连接到面
points_in_polygons = gpd.sjoin(points_gdf, polygons_gdf, predicate='within')
# 按面聚合
aggregated = points_in_polygons.groupby('index_right').agg({
'value': 'sum',
'count': 'size'
})
# 合并回面数据
result = polygons_gdf.merge(aggregated, left_index=True, right_index=True)
# 从不同来源读取
roads = gpd.read_file("roads.shp")
buildings = gpd.read_file("buildings.geojson")
parcels = gpd.read_postgis("SELECT * FROM parcels", con=engine, geom_col='geom')
# 确保 CRS 匹配
buildings = buildings.to_crs(roads.crs)
parcels = parcels.to_crs(roads.crs)
# 执行空间操作
buildings_near_roads = buildings[buildings.geometry.distance(roads.union_all()) < 50]
bbox、mask 或 where 参数仅加载所需数据use_arrow=True 以获得 2-4 倍更快的读取/写入速度.simplify() 来降低复杂度.is_valid 在操作之前.copy() 当修改几何列时,以避免副作用每周安装量
142
代码仓库
GitHub 星标数
22.6K
首次出现
2026 年 1 月 21 日
安全审计
已安装于
claude-code119
opencode110
cursor107
gemini-cli102
antigravity93
codex93
GeoPandas extends pandas to enable spatial operations on geometric types. It combines the capabilities of pandas and shapely for geospatial data analysis.
uv pip install geopandas
# 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
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")
See data-structures.md for details.
GeoPandas reads/writes multiple formats: Shapefile, GeoJSON, GeoPackage, PostGIS, Parquet.
# 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.
Always check and manage CRS for accurate spatial operations:
# 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.
Buffer, simplify, centroid, convex hull, affine transformations:
# 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 joins, overlay operations, dissolve:
# 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.
Create static and interactive maps:
# 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.
# 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')
# 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)
# 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]
bbox, mask, or where parameters to load only needed datause_arrow=True for 2-4x faster reading/writing.simplify() to reduce complexity when precision isn't critical.is_valid before operations.copy() when modifying geometry columns to avoid side effectsWeekly Installs
142
Repository
GitHub Stars
22.6K
First Seen
Jan 21, 2026
Security Audits
Gen Agent Trust HubFailSocketPassSnykWarn
Installed on
claude-code119
opencode110
cursor107
gemini-cli102
antigravity93
codex93
DOCX文件创建、编辑与分析完整指南 - 使用docx-js、Pandoc和Python脚本
47,500 周安装