技能创建器
skill-creator
创建、改进和评估自定义技能,把专业流程转化为可重复使用的 AI 能力。
geospatial-ml【数据与研究】Use when applying machine learning to geospatial data, including spatial feature engineering, morphometric indicators, urban analysis, spatial cross-validation, library selection, or integrating geopandas, momepy, pysal, osmnx, torchgeo, or rasterio into an ML pipeline.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Use this skill when the task involves building or evaluating a machine learning pipeline that consumes geospatial data as input, or when spatial structure must be respected during modelling.
| Library | Role |
|---|---|
| geopandas | GeoDataFrame with CRS awareness; primary table for vector ML features |
| shapely | Geometry primitives and operations behind geopandas |
| pyproj | CRS and coordinate transforms |
| osmnx | Download and analyse OpenStreetMap road and place networks |
| momepy | Urban morphometrics from building footprints, street networks, and city blocks |
| pysal / libpysal | Spatial weights matrices, spatial statistics |
| esda | Moran's I, local spatial autocorrelation (LISA), spatial clustering |
| mgwr | Multiscale Geographically Weighted Regression |
| spopt | Spatial optimisation (p-median, regionalisation) |
| h3 / h3-pandas | Uber Hexagonal Hierarchical Spatial Index for grid aggregation |
| Library | Role |
|---|---|
| rasterio | Read/write rasters, window reads, masking |
| xarray / rioxarray | N-dimensional arrays with spatial metadata and lazy loading |
| numpy | Array arithmetic for raster band math |
| torchgeo | PyTorch datasets, samplers, and transforms for geospatial rasters |
| segmentation-models-pytorch | Pre-built encoder-decoder architectures for semantic segmentation |
| Library | Role |
|---|---|
| scikit-learn | Standard ML; works with geopandas DataFrames |
| mlxtend | Spatial feature selection helpers |
| lightgbm / xgboost | Gradient boosting; handles spatial tabular features well |
| pytorch / lightning | Deep learning backbone for point clouds, rasters, graphs |
| torch-geometric | Graph neural networks over spatial neighbourhood graphs |
From building footprints / urban blocks (momepy)
momepy.Area, momepy.Perimeter, momepy.CircularCompactness, momepy.Elongationmomepy.CoveredArea, momepy.NeighboringStreetOrientationDeviationmomepy.BlocksCount, momepy.Reached — network-based reach metricslibpysal.weights.Queen tessellation before computing context metricsFrom street networks (osmnx)
osmnx.graph_from_place or bounding boxosmnx.stats.basic_stats for global network measuresosmnx.project_graph before any distance-dependent metricFrom vector attributes (geopandas)
gpd.sjoin) to attach context from neighbouring layersGeoSeries.distanceFrom raster bands (rasterio / xarray)
rasterstats.zonal_stats(NIR - Red) / (NIR + Red), NDWI, NDBIskimage.feature.graycomatrix)df.drop(columns='geometry')esda.Moran) before modellingsklearn-spatial or manual): divide study area into geographic blocks, treat each block as a foldtrain_test_split with shuffle=True when geometry exhibits autocorrelationtorchgeo.datasets for standard benchmarks (LandCover.AI, EuroSAT, SpaceNet)torchgeo.samplers.RandomGeoSampler for patch-based trainingtorchgeo.transforms for normalisation, augmentation respecting CRSrasterio.open(..., 'w') and matching transform + crs| Pitfall | Risk | Fix |
|---|---|---|
| Random train/test split on autocorrelated data | Inflated metrics; model fails in new areas | Block or buffered spatial CV |
| momepy metrics before CRS projection | Wrong metric units (degrees not meters) | Always project to a local CRS first |
| Mixing CRS across joined layers | Geometry misalignment | Reproject all layers to one CRS before any join |
| Including coordinates as raw ML features | Model memorises study-area location | Use derived features (distance, density) not raw lat/lon |
| Nodata as a valid pixel value | Corrupts raster statistics | Confirm nodata mask before band math |
| Graph distance in angular CRS | Incorrect network centrality | Project graph before computing metrics |
When reporting on a geospatial ML pipeline:
Target variable:
Geometry type and source:
Feature groups constructed:
- Morphometrics:
- Network:
- Raster / remote sensing:
- Context / aggregated:
Spatial autocorrelation check (Moran's I):
CV strategy:
Baseline model and metric:
Candidate model and metric:
Spatial bias in residuals:
Recommended next step: