geopandas-distance-analysis
Calculate distances between geospatial points and boundaries using GeoPandas with proper metric projections (EPSG:4087).
- License 许可
- MIT
- 最近更新
- 2026-10-02
- Stars
- ★ 93
- Forks
- 8
01 前言 Front Matter
- name
- geopandas-distance-analysis
- description
- Calculate distances between geospatial points and boundaries using GeoPandas with proper metric projections (EPSG:4087).
03 SKILL.md 正文
GeoPandas Distance Analysis
Setup
pip install geopandas shapely
Core Workflow
1. Load GeoJSON files
import geopandas as gpd
from shapely.geometry import Point
gdf_plates = gpd.read_file("PB2002_plates.json")
gdf_boundaries = gpd.read_file("PB2002_boundaries.json")
2. Create GeoDataFrame from coordinate list
geometry = [Point(lon, lat) for lon, lat in zip(lons, lats)]
gdf_points = gpd.GeoDataFrame(data, geometry=geometry, crs="EPSG:4326")
3. Spatial filtering (points within polygon)
target_poly = gdf_plates[gdf_plates["Code"] == "PA"].geometry.unary_union
inside = gdf_points[gdf_points.within(target_poly)].copy()
4. Project to metric CRS before distance calculation
METRIC_CRS = "EPSG:4087" # World Equidistant Cylindrical (meters)
inside_proj = inside.to_crs(METRIC_CRS)
boundary_proj = gdf_boundaries.to_crs(METRIC_CRS).geometry.unary_union
inside["distance_km"] = inside_proj.geometry.distance(boundary_proj) / 1000.0
5. Find furthest point
result = inside.nlargest(1, "distance_km").iloc[0]
print(f"ID: {result['id']}, Distance: {result['distance_km']:.2f} km")
Key Rules
- NEVER calculate distances in EPSG:4326 (degrees != meters)
- Always project to EPSG:4087 or EPSG:3857 before
.distance() - Use
.unary_unionto combine multiple boundary segments into one geometry - Use
.within()for point-in-polygon tests (handles antimeridian better than manual checks) - Filter boundaries by PlateA/PlateB before combining:
gdf_boundaries[(gdf_boundaries["PlateA"]=="PA") | (gdf_boundaries["PlateB"]=="PA")]
04 同仓库更多 Skills
object_counter
Count occurrences of an object in the image using computer vision algorithm.
travel-planning-workflow
Invoke this skill when performing travel planning. It defines a structured workflow for generating itineraries. Following this workflow is essential to ensure the final plan satisfies user requirements.
bundled-dataset-search-tool
invoke this skill when you need to perform database search for travel planning. This skill provides some useful pre-packaged tools to look up accommodations, attractions, cities, driving distance, flights, and restaurants from the bundled dataset.
glm-output
Output-processing guidance for GLM tasks. Especially useful after glm-basics and glm-calibration when you need verifier-matching metrics from output.nc and a final /root/metrics.json.
glm-calibration
Calibration guidance for GLM tasks. Often most effective after glm-basics has clarified the setup; glm-output is the companion skill for exact final metric computation.
glm-basics
A good starting point for GLM calibration tasks. Use to inspect glm3.nml, confirm how GLM runs, and identify the relevant files before moving on to calibration and output evaluation.