Home / Market / geospatial python

geospatial python

Process vector and raster geospatial data with GeoPandas, Shapely, PyProj, and Rasterio. Prevent CRS/unit errors, lon-lat flips, invalid geometries, and misaligned raster-vector clips.

skill★ 507520 dlgithubCC-BY-4.0 content; MIT code; upstream exceptions applyInstall in CosmosUpstream Source

Documentation & Preview

--- name: geospatial-python description: "Process vector and raster geospatial data with GeoPandas, Shapely, PyProj, and Rasterio. Prevent CRS/unit errors, lon-lat flips, invalid geometries, and misaligned raster-vector clips." category: science risk: safe source: self source_type: self date_added: "2026-11-30" author: ShianMike tags: [geospatial, geopandas, shapely, pyproj, rasterio, gis, crs]

---

Geospatial Python

When to Use

Prerequisites

Identify installed versions of geopandas, shapely, pyproj, and rasterio, the CRS of every vector and raster input (gdf.crs, src.crs), coordinate axis order (GeoJSON and Shapely use (x, y) = (lon, lat) for geographic CRS), and the spatial extent of the study area. Never assume an input file is in EPSG:4326 without inspecting its metadata first.

Enforce CRS hygiene before geometry math

  1. Distinguish setting a missing CRS (set_crs("EPSG:4326") only when the file lacks metadata and you know the true CRS) from reprojecting coordinates (to_crs("EPSG:32610")). Calling set_crs(..., allow_override=True) on already-projected coordinates corrupts the data without transforming values.
  2. Never compute area, length, centroids, or metric buffers in a geographic CRS (EPSG:4326, degrees). Reproject to an appropriate projected CRS first: a local UTM zone (for example gdf.estimate_utm_crs()) for city/regional work, or an equal-area CRS (such as EPSG:6933 or a regional Albers/Lambert projection) for continental or multi-zone area totals.
  3. Verify that both inputs share the exact same CRS (left.crs == right.crs) before gpd.sjoin, gpd.overlay, or raster sampling/masking. Reproject the lighter layer explicitly with to_crs(target_crs) rather than hoping downstream functions reject a mismatch.

Repair invalid geometries and check raster alignment

Example

> A pipeline computed polygon areas directly in EPSG:4326, encountered a self-intersecting bowtie polygon, and sampled a projected GeoTIFF using unaligned WGS84 coordinates.

Run the worked CRS, geometry repair, and raster alignment test to reproduce the geographic-area warning, verify metric reprojection to 1.0 km², repair the bowtie with make_valid, and align vector coordinates to an in-memory GeoTIFF before sampling.

Limitations

Safety and Side Effects

Work on read-only copies or temporary output directories before overwriting geospatial datasets. Verify CRS metadata and sample values after reprojection or resampling. Keep private location tracks or restricted imagery out of examples and logs.

Related Skills and Documentation