GeoDataFrame.
set_crs
Set the Coordinate Reference System (CRS) of the GeoDataFrame.
GeoDataFrame
If there are multiple geometry columns within the GeoDataFrame, only the CRS of the active geometry column is set.
NOTE: The underlying geometries are not transformed to this CRS. To transform the geometries to a new CRS, use the to_crs method.
to_crs
The value can be anything accepted by pyproj.CRS.from_user_input(), such as an authority string (eg “EPSG:4326”) or a WKT string.
pyproj.CRS.from_user_input()
EPSG code specifying the projection.
If True, the CRS of the GeoDataFrame will be changed in place (while still returning the result) instead of making a copy of the GeoDataFrame.
If the the GeoDataFrame already has a CRS, allow to replace the existing CRS, even when both are not equal.
See also
GeoDataFrame.to_crs
re-project to another CRS
Examples
>>> from shapely.geometry import Point >>> d = {'col1': ['name1', 'name2'], 'geometry': [Point(1, 2), Point(2, 1)]} >>> gdf = geopandas.GeoDataFrame(d) >>> gdf col1 geometry 0 name1 POINT (1.00000 2.00000) 1 name2 POINT (2.00000 1.00000)
Setting CRS to a GeoDataFrame without one:
>>> gdf.crs is None True
>>> gdf = gdf.set_crs('epsg:3857') >>> gdf.crs <Projected CRS: EPSG:3857> Name: WGS 84 / Pseudo-Mercator Axis Info [cartesian]: - X[east]: Easting (metre) - Y[north]: Northing (metre) Area of Use: - name: World - 85°S to 85°N - bounds: (-180.0, -85.06, 180.0, 85.06) Coordinate Operation: - name: Popular Visualisation Pseudo-Mercator - method: Popular Visualisation Pseudo Mercator Datum: World Geodetic System 1984 - Ellipsoid: WGS 84 - Prime Meridian: Greenwich
Overriding existing CRS:
>>> gdf = gdf.set_crs(4326, allow_override=True)
Without allow_override=True, set_crs returns an error if you try to override CRS.
allow_override=True