关于 geospatial-analysis
geospatial-analysis 是面向地理空间分析任务的 Agent 技能,帮助分析人员构建可复现的栅格与矢量数据处理流程。它涵盖卫星影像、GeoPandas 操作、空间统计和制图,并强调坐标参考系与空间关系的正确处理。
主要功能
- 01处理 Sentinel、Landsat 等影像
- 02执行 GeoPandas 矢量操作
- 03计算空间统计量
- 04进行栅格与矢量整合
- 05生成制图输出
适用场景
- 01分析土地利用与覆盖变化
- 02开展城市热岛分析
- 03执行空间连接、缓冲区或叠加分析
- 04制作出版级地图
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ itallstartedwithaidea/ agent-skills --skill geospatial-analysis安装后在 Claude Code 中输入/geospatial-analysis确认已加载。
详细介绍
地理空间分析
Agent Skills™ 的一部分,由 googleadsagent.ai™ 提供
描述
地理空间分析提供卫星影像处理、使用 GeoPandas 进行 GIS 操作、空间统计和地球观测数据分析的工作流。Agent 会构建可复现的地理空间管线,将原始空间数据转化为可操作的地理情报,涵盖从栅格处理到矢量操作,再到出版级制图输出的全过程。
地理空间数据与表格数据有着本质区别:它具有必须遵循的坐标参考系统,空间关系会影响统计独立性,且依赖尺度的模式会随分辨率而变化。此技能整合了正确应对这些挑战所需的领域知识:CRS 转换、空间连接、缓冲区操作、栅格与矢量互操作,以及空间自相关检验。
此技能将卫星影像分析(Sentinel、Landsat)与矢量数据处理(shapefiles、GeoJSON)相结合,从而支持多光谱影像土地利用分类、利用热红外波段分析城市热岛,以及通过时间影像堆栈检测环境变化等工作流。
适用场景
- 处理卫星影像(Sentinel-2、Landsat、MODIS)
- 执行空间连接、缓冲区或叠加操作
- 计算空间统计量(Moran's I、热点分析)
- 创建出版级地图和制图输出
- 分析土地利用、土地覆盖或环境变化
- 使用坐标参考系统和投影
工作原理
graph TD
A[Spatial Data Input] --> B{Data Type}
B -->|Raster| C[Satellite Imagery Processing]
B -->|Vector| D[GeoPandas Operations]
C --> E[Band Math + Indices: NDVI, NDWI]
E --> F[Classification / Change Detection]
D --> G[Spatial Joins + Overlay]
G --> H[Spatial Statistics]
F --> I[Raster-Vector Integration]
H --> I
I --> J[Cartographic Output]
J --> K[Publication Map]
栅格和矢量路径会在集成步骤汇合,将分类后的影像与行政边界、点观测或基础设施数据相结合,以生成最终的分析产品。
实现
import geopandas as gpd
import rasterio
from rasterio.mask import mask
from shapely.geometry import Point
import numpy as np
from pysal.explore import esda
from pysal.lib import weights
import matplotlib.pyplot as plt
import contextily as cx
def load_and_reproject(filepath: str, target_crs: str = "EPSG:4326") -> gpd.GeoDataFrame:
gdf = gpd.read_file(filepath)
return gdf.to_crs(target_crs)
def spatial_join_points_to_polygons(
points: gpd.GeoDataFrame, polygons: gpd.GeoDataFrame
) -> gpd.GeoDataFrame:
assert points.crs == polygons.crs, "CRS mismatch: reproject before joining"
return gpd.sjoin(points, polygons, how="inner", predicate="within")
def compute_ndvi(nir_path: str, red_path: str) -> np.ndarray:
with rasterio.open(nir_path) as nir_src, rasterio.open(red_path) as red_src:
nir = nir_src.read(1).astype(np.float32)
red = red_src.read(1).astype(np.float32)
ndvi = np.where((nir + red) > 0, (nir - red) / (nir + red), 0)
return ndvi
def spatial_autocorrelation(gdf: gpd.GeoDataFrame, column: str) -> dict:
w = weights.Queen.from_dataframe(gdf)
w.transform = "r"
moran = esda.Moran(gdf[column], w)
return {
"morans_i": moran.I,
"p_value": moran.p_sim,
"z_score": moran.z_sim,
"significant": moran.p_sim < 0.05,
"interpretation": "Clustered" if moran.I > 0 and moran.p_sim < 0.05 else
"Dispersed" if moran.I < 0 and moran.p_sim < 0.05 else
"Random",
}
def publication_map(gdf: gpd.GeoDataFrame, column: str, title: str, output: str):
fig, ax = plt.subplots(1, 1, figsize=(10, 8))
gdf.plot(column=column, ax=ax, legend=True, cmap="YlOrRd", edgecolor="0.5", linewidth=0.3)
cx.add_basemap(ax, crs=gdf.crs.to_string(), source=cx.providers.CartoDB.Positron)
ax.set_title(title, fontsize=14, fontweight="bold")
ax.set_axis_off()
fig.tight_layout()
fig.savefig(output, dpi=300, bbox_inches="tight")
plt.close(fig)
最佳实践
- 执行空间操作前务必确认 CRS 对齐;CRS 不匹配会导致隐蔽错误
- 距离和面积计算使用投影 CRS(米),显示时使用地理 CRS(度)
- 使用非空间统计前,先通过 Moran's I 检验空间自相关
- 验证 NDVI 和其他指数的取值范围(NDVI 应为 -1 到 1),以检查数据质量
- 所有发布的地图都应包含比例尺、指北针和 CRS 标签
- 为提升性能,将地理空间数据存储为 GeoParquet;仅在交换数据时使用 GeoJSON
平台兼容性
| 平台 | 支持情况 | 备注 |
|---|---|---|
| Cursor | 完全支持 | Python + 地理空间库 |
| VS Code | 完全支持 | Jupyter + 地图渲染 |
| Windsurf | 完全支持 | 科学计算 Python |
| Claude Code | 完全支持 | 管线生成 |
| Cline | 完全支持 | GIS 工作流 |
| aider | 部分支持 | 仅代码生成 |
相关技能
关键词
geospatial geopandas satellite-imagery ndvi spatial-statistics gis rasterio cartography earth-observation
© 2026 googleadsagent.ai™ | Agent Skills™ | MIT License