Working with Geospatial Data in Python
Joris Van den Bossche
Open source software developer and teacher, GeoPandas maintainer
The .crs
attribute of a GeoDataFrame/GeoSeries:
import geopandas
gdf = geopandas.read_file("countries.shp")
print(gdf.crs)
{'init': 'epsg:4326'}
gdf_noCRS = geopandas.read_file("countries_noCRS.shp")
print(gdf_noCRS.crs)
{}
Add CRS information to crs
:
# Option 1
gdf.crs = {'init': 'epsg:4326'}
# Option 2
gdf.crs = {'proj': 'longlat', 'datum': 'WGS84', 'no_defs': True}
import geopandas
gdf = geopandas.read_file("countries_web_mercator.shp")
print(gdf.crs)
{'init': 'epsg:3857', 'no_defs': True}
The to_crs()
method:
# Option 1 gdf2 = gdf.to_crs({'proj': 'longlat', 'datum': 'WGS84', 'no_defs': True})
# Option 2 gdf2 = gdf.to_crs(epsg=4326)
1) Sources with a different CRS
df1 = geopandas.read_file(...)
df2 = geopandas.read_file(...)
df2 = df2.to_crs(df1.crs)
1) Sources with a different CRS
2) Mapping (distortion of shape and distances)
1) Sources with a different CRS
2) Mapping (distortion of shape and distances)
3) Distance / area based calculations
Tips:
Useful sites:
to_crs()
methodUseful sites:
Working with Geospatial Data in Python