How to Reproject Spatial Data in Python (GeoPandas)
On this page
Problem statement
Reprojecting converts a layer's coordinates from one coordinate reference system to another: to line it up with a layer in a different system, to put it on web tiles, or to measure lengths and areas in metres. In GeoPandas that is one call, to_crs(). The decisions around it are where the work is: which layer to convert to match which, which target to choose for the job, and whether the CRS survives being saved.
The examples use three real layers for the county of Rutland that arrive in two different systems: OpenStreetMap roads and the council boundary in longitude and latitude, and HM Land Registry's parcels in British National Grid.
Quick answer
Check what the layer is in, then call .to_crs() with the target:
roads = gpd.read_file(ROADS)
print(roads.crs, roads.total_bounds.round(3))
roads_bng = roads.to_crs(epsg=27700)
print(roads_bng.crs, roads_bng.total_bounds.round(0))
EPSG:4326 [-0.847 52.523 -0.395 52.762]
EPSG:27700 [478090. 292420. 508533. 319193.]
The same roads, first in degrees and then in metres east and north of British National Grid's origin. (No CRS at all? That is cannot transform naive geometries.)
Before you reproject: is the CRS right?
Check the units, convert to a target that suits the job, save
Check the current CRS
Before changing anything, inspect the CRS of every layer you will combine.
parcels = gpd.read_file(PARCELS, DOWNLOAD_SCHEMA="NO")
boundary = gpd.read_file("data/rutland_boundary.geojson")
for name, layer in (("roads", roads), ("parcels", parcels), ("boundary", boundary)):
print(f"{name:9} {layer.crs.to_string():11} {layer.crs.name:28} units: {layer.crs.axis_info[0].unit_name}")
roads EPSG:4326 WGS 84 units: degree
parcels EPSG:27700 OSGB36 / British National Grid units: metre
boundary EPSG:4326 WGS 84 units: degree
Two layers are in degrees and one is in metres, so anything that combines them needs one of the two converted first. Printing the unit beside each code makes that visible at a glance; the EPSG code alone does not.
Reproject the GeoDataFrame with to_crs()
The target depends on the job. Sum the road network's length in four systems:
lengths_km = {
"EPSG:4326 (degrees)": roads.length.sum(),
"EPSG:3857 Web Mercator": roads.to_crs(3857).length.sum() / 1000,
"EPSG:27700 British National Grid": roads.to_crs(27700).length.sum() / 1000,
f"{roads.estimate_utm_crs().to_string()} (estimate_utm_crs)": roads.to_crs(roads.estimate_utm_crs()).length.sum() / 1000,
}
for crs, total in lengths_km.items():
print(f"{crs:36} {total:10,.1f}")
EPSG:4326 (degrees) 19.5
EPSG:3857 Web Mercator 2,646.8
EPSG:27700 British National Grid 1,606.3
EPSG:32630 (estimate_utm_crs) 1,606.6
The first number is a sum of degrees — meaningless, and GeoPandas warns about it. Web Mercator's is too long by the factor 1/cos(latitude), about 1.65 at 52.6°N. British National Grid and UTM zone 30N agree to within a fraction of a percent. Use EPSG:3857 for display, not for measurement.
For areas the Web Mercator error is squared:
for code in (3857, 27700, 32630, 3035):
area = boundary.to_crs(code).area.iloc[0] / 1e6
print(f"EPSG:{code:<6} {boundary.to_crs(code).crs.name:42} {area:8,.1f} km²")
EPSG:3857 WGS 84 / Pseudo-Mercator 1,069.0 km²
EPSG:27700 OSGB36 / British National Grid 393.7 km²
EPSG:32630 WGS 84 / UTM zone 30N 393.9 km²
EPSG:3035 ETRS89-extended / LAEA Europe 394.0 km²
Web Mercator makes Rutland about 2.7 times its size. The national grid, UTM and the European equal-area projection (EPSG:3035) agree closely. So: EPSG:3857 only for putting the layer on web tiles, and a national grid, a UTM zone or an equal-area system for anything measured — choosing a projected CRS for your study area goes through that choice.
Save the reprojected data
After reprojection, save the output to a new file and read it back to confirm the CRS travelled with it:
roads_3857 = roads.to_crs(epsg=3857)
Path("output").mkdir(exist_ok=True)
for suffix in ("gpkg", "shp", "geojson"):
roads_3857.to_file(f"output/roads_3857.{suffix}")
print(f"{suffix:8} read back as {gpd.read_file(f'output/roads_3857.{suffix}').crs}")
gpkg read back as EPSG:3857
shp read back as EPSG:3857
geojson read back as EPSG:3857
All three kept EPSG:3857. A GeoJSON in anything but WGS 84 is outside the current GeoJSON specification (RFC 7946), though: GDAL writes a legacy crs member that GDAL reads back, but a web map or another library may ignore it and assume longitude and latitude. Keep GeoJSON in EPSG:4326 and put projected data in a GeoPackage.
Rutland layers reprojected and matched, with a UTM estimate
The data used on this page
Rutland's roads from Geofabrik's OpenStreetMap extract of 1 January 2026 (© OpenStreetMap contributors, ODbL), HM Land Registry's INSPIRE parcels for the county (© Crown copyright and database rights; OGL), and the Rutland boundary from the ONS December 2024 local authority boundaries (OGL).
from pathlib import Path
import geopandas as gpd
import requests
Path("data").mkdir(exist_ok=True)
session = requests.Session()
downloads = {
"data/rutland.shp.zip": "https://download.geofabrik.de/europe/united-kingdom/england/rutland-260101-free.shp.zip",
"data/Rutland.zip": "https://use-land-property-data.service.gov.uk/datasets/inspire/download/Rutland.zip",
}
for target, url in downloads.items():
if not Path(target).exists():
Path(target).write_bytes(session.get(url, timeout=300).content)
if not Path("data/rutland_boundary.geojson").exists():
Path("data/rutland_boundary.geojson").write_bytes(session.get(
"https://services1.arcgis.com/ESMARspQHYMw9BZ9/arcgis/rest/services/"
"Local_Authority_Districts_December_2024_Boundaries_UK_BFC/FeatureServer/0/query",
params={"where": "LAD24NM='Rutland'", "outFields": "LAD24NM", "outSR": 4326, "f": "geojson"}, timeout=120).content)
ROADS = "/vsizip/data/rutland.shp.zip/gis_osm_roads_free_1.shp"
PARCELS = "/vsizip/data/Rutland.zip/Land_Registry_Cadastral_Parcels.gml"
print(len(gpd.read_file(ROADS)), "road segments")
7292 road segments
Example 1: Reproject in one short workflow
buildings = gpd.read_file("/vsizip/data/rutland.shp.zip/gis_osm_buildings_a_free_1.shp")
if buildings.crs is None:
buildings = buildings.set_crs(epsg=4326) # only because the source says so
buildings_bng = buildings.to_crs(epsg=27700)
buildings_bng["area_m2"] = buildings_bng.area.round(1)
buildings_bng.to_file("output/buildings_27700.gpkg", layer="buildings")
print(len(buildings_bng), "buildings, median footprint", buildings_bng["area_m2"].median(), "m²")
5513 buildings, median footprint 110.8 m²
Example 2: Match one layer to another layer's CRS
This is common before overlay, clipping, or spatial joins. Here is a join of roads to the parcels they cross, first without matching the CRSs:
import warnings
sample = parcels.head(2000)
with warnings.catch_warnings(record=True) as caught:
warnings.simplefilter("always")
try:
mismatched = len(gpd.sjoin(roads, sample, predicate="intersects"))
except Exception as exc:
mismatched = f"{type(exc).__name__}"
print("CRSs differ:", mismatched, "|", " ".join(str(caught[0].message).split())[:80] if caught else "no warning")
matched = gpd.sjoin(roads.to_crs(parcels.crs), sample, predicate="intersects")
print("after roads.to_crs(parcels.crs):", len(matched), "road-parcel pairs")
CRSs differ: 0 | CRS mismatch between the CRS of left geometries and the CRS of right geometries.
after roads.to_crs(parcels.crs): 796 road-parcel pairs
Unmatched, the join compared degrees with metres: GeoPandas warned about the mismatch and found nothing, because 52.6 and 300,000 never overlap. Reproject one layer to the other's CRS — to_crs(other.crs) rather than a typed code, so the two cannot drift apart.
Example 3: Reproject by estimating a UTM zone
utm = boundary.estimate_utm_crs()
print(utm.to_string(), "-", utm.name)
print("Rutland in UTM, km²:", round(boundary.to_crs(utm).area.iloc[0] / 1e6, 1))
EPSG:32630 - WGS 84 / UTM zone 30N
Rutland in UTM, km²: 393.9
estimate_utm_crs() chooses the zone from the layer's bounding box — for Rutland, just west of the Greenwich meridian, zone 30N. It is a good default when there is no national grid to hand, but a layer that straddles two zones gets the one containing its centre.
What reprojection does, and what it costs
Reprojection recomputes every vertex. Nothing about the features changes — the same roads, the same parcel boundaries — but the numbers describing them do, and so does everything computed from those numbers. That is why the choice of target is not cosmetic: the same 7,292 road segments measure 2,646.8 km in Web Mercator and 1,606.3 km in British National Grid, and both are "correct" for the projection they are in. Only one of them is the length of the roads.
The other cost is silence. A spatial join across two CRSs does not fail: GeoPandas warns and returns no matches (Example 2), because 52.6 and 300,000 never overlap. Converting one layer with to_crs(other.crs), rather than typing a code for each, keeps the two from drifting apart as a pipeline grows. Which of degrees and metres a layer should be in at all is the subject of projected vs geographic CRS.
Validity after reprojection
Recomputing every vertex can, in principle, turn a valid polygon invalid — a thin sliver whose edges cross once rounded in the new system. Check in the CRS you will work in:
invalid = ~parcels.is_valid
print(int(invalid.sum()), "invalid parcels of", len(parcels))
print("still invalid after to_crs(4326):", int((~parcels[invalid].to_crs(4326).is_valid).sum()))
0 invalid parcels of 21253
still invalid after to_crs(4326): 0
All 21,253 parcels are valid in British National Grid and still valid in WGS 84, so for this data the check costs a second and finds nothing. It is cheap insurance before an overlay, which fails on invalid input.
Internal links
- How to Set, Assign and Convert CRS in GeoPandas (set_crs vs to_crs) — when the label itself is missing or wrong
- How to Read a Shapefile in Python with GeoPandas
- How to Export GeoJSON in Python with GeoPandas
- How to Perform a Spatial Join in Python (GeoPandas)
- M values are lost when you export the route — what to_crs silently drops
FAQ
How do I reproject a GeoDataFrame in Python with GeoPandas?
Use gdf.to_crs(...) after confirming that gdf.crs is already set correctly.
gdf = gdf.to_crs(epsg=3857)
How do I pick the correct UTM zone for my data automatically?
GeoPandas can estimate it from the data extent with gdf.estimate_utm_crs(), which returns a projected UTM CRS suitable for metric analysis. Use it directly: gdf_utm = gdf.to_crs(gdf.estimate_utm_crs()).
Can I measure in EPSG:3857 because its units are metres?
No. Web Mercator's metres stretch with latitude: Rutland's road network came out 2,646.8 km long in EPSG:3857 against 1,606.3 km in British National Grid, and its area 1,069.0 km² against 393.7. Use it to put data on web tiles, and a national grid or UTM zone to measure.
How do I reproject to a UTM zone like 33N, and what EPSG code is that?
UTM zone 33N is EPSG:32633, a metre-based projected CRS: gdf_utm = gdf.to_crs(epsg=32633). Southern-hemisphere zones use the 327xx range (for example 32733 for UTM 33S).