geopandas-distance-calculation
How to calculate distance between points and other geometries (like lines or polygons) in metric units using GeoPandas.
- License 许可
- MIT
- 最近更新
- 2026-10-02
- Stars
- ★ 93
- Forks
- 7
01 前言 Front Matter
- name
- geopandas-distance-calculation
- description
- How to calculate distance between points and other geometries (like lines or polygons) in metric units using GeoPandas.
03 SKILL.md 正文
Distance Calculation with GeoPandas
This skill demonstrates how to calculate the distance between geographic features (like points and lines) accurately. The crucial step is projecting geographic coordinates (degrees) into a projected coordinate system (meters).
Prerequisites
pip install geopandas shapely
Basic Usage
When calculating distances on the Earth's surface, you must not calculate distance directly in EPSG:4326 (which uses degrees). Instead, you project the data into a metric coordinate system like EPSG:4087 (World Equidistant Cylindrical) or EPSG:3857 (Web Mercator, though it distorts distance). EPSG:4087 or EPSG:6933 (Cylindrical Equal Area) are common for global calculations, or a local UTM zone. EPSG:4087 provides distances in meters.
import geopandas as gpd
from shapely.geometry import Point
# 1. Load data
points_gdf = gpd.read_file('points.geojson')
lines_gdf = gpd.read_file('lines.geojson')
# 2. Define a metric CRS (e.g., EPSG:4087 for World Equidistant Cylindrical)
METRIC_CRS = "EPSG:4087"
# 3. Project both datasets to the metric CRS
points_proj = points_gdf.to_crs(METRIC_CRS)
lines_proj = lines_gdf.to_crs(METRIC_CRS)
# 4. Optional: If you want distance to any part of the lines network, combine them
network_geometry = lines_proj.geometry.unary_union
# 5. Calculate distance (the result will be in meters because of the CRS)
points_gdf['distance_m'] = points_proj.geometry.distance(network_geometry)
# 6. Convert to kilometers
points_gdf['distance_km'] = points_gdf['distance_m'] / 1000.0
# 7. Find the point furthest away
furthest_point = points_gdf.nlargest(1, 'distance_km').iloc[0]
print(f"Furthest point distance: {furthest_point['distance_km']:.2f} km")
Tips
- Always verify your metric CRS when doing distance calculations.
EPSG:4326will return distances in degrees. - Combining features with
.unary_unionbefore calling.distance()is significantly faster than calculating distances to each feature individually.
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.