GeoPandas Spatial Projections
SkillDev toolsUsing GeoPandas coordinate projections for accurate distance calculations on geospatial data.
Available today. Use it from your connected AI after setup.
No other account needed.
Connect ahel once, and every AI you use reads what you have installed.
Then ask your AI: use the GeoPandas Spatial Projections skill
What this skill tells your AI
The instructions your AI receives, as published by cxcscmu/skilllearnbench in skills/b1-one-shot-claude-opus-4-6/earthquake-plate-calculation/geopandas-projections/SKILL.md and read by ahel’s review.
Overview
GeoPandas is built on top of Shapely and Fiona, enabling geographic data manipulation with proper coordinate reference systems (CRS). Using correct projections is critical for accurate distance calculations and spatial operations.
Installation
pip install geopandas shapely fiona pyproj
Key Concepts
Coordinate Reference Systems (CRS)
- EPSG:4326: WGS84 (lat/lon), commonly used for geographic data but NOT suitable for distance calculations
- EPSG:3857: Web Mercator, used for web mapping
- Regional Projected CRS: For accurate local distance calculations (e.g., UTM zones)
Distance Calculations
Always project to a projected CRS before calculating distances. Geographic CRS (like EPSG:4326) measure in degrees, not kilometers.
Code Examples
Creating GeoDataFrames from Points
import geopandas as gpd
from shapely.geometry import Point
import pandas as pd
# From earthquake data
earthquakes_df = pd.read_json('/root/earthquakes_2024.json')
geometry = [Point(xy) for xy in zip(earthquakes_df['longitude'], earthquakes_df['latitude'])]
gdf = gpd.GeoDataFrame(earthquakes_df, geometry=geometry, crs='EPSG:4326')
Loading GeoJSON with Boundaries
import json
# Load GeoJSON and convert to GeoDataFrame
with open('/root/PB2002_boundaries.json', 'r') as f:
geojson_data = json.load(f)
boundaries_gdf = gpd.GeoDataFrame.from_features(geojson_data['features'], crs='EPSG:4326')
Projecting to Projected CRS
# Project to a suitable CRS for distance calculations
# Example: project to Mercator for global analysis
gdf_projected = gdf.to_crs('EPSG:3857')
boundaries_projected = boundaries_gdf.to_crs('EPSG:3857')
# Or use a specific UTM zone for a region
# EPSG:32633 is UTM zone 33N
Spatial Filtering (Point in Polygon)
# Check if points fall within polygons
earthquakes_in_plate = gpd.sjoin(gdf, plate_polygons, how='inner', predicate='within')
Distance to Nearest Geometry
# Calculate distance from each point to nearest boundary
def min_distance_to_boundary(row, boundary_geom):
return row['geometry'].distance(boundary_geom)
# Distance in projected CRS (meters) or geographic CRS (degrees)
gdf['distance'] = gdf.geometry.distance(boundary_geometry)
Common Pitfalls
- Calculating distances in geographic CRS - Use projected CRS for kilometers
- Mixing CRS - Always ensure geometries have the same CRS before operations
- Not checking polygon orientation - Invalid/reversed rings can cause issues
Best Practices
- Always set CRS explicitly when creating GeoDataFrames
- Project to appropriate CRS before distance calculations
- Use
gdf.to_crs()to transform, notgdf.crs = new_crs - Validate geometries:
gdf.is_valid.all()
Signals
- GitHub stars
- 83
- Forks
- 5
- Last commit
- Jul 2026
Advanced
- Catalog kind
- skill
- Gateway key
geopandas-projections- Source
- github.com/cxcscmu/skilllearnbench