Reputation: 12385
I create a GeoDataFrame
like this
gdf = gp.GeoDataFrame([], columns=['foo', 'geometry'], crs = "epsg:4326")
Then I fill gdf
with data. Then I want to transform the CRS
of gdf
gdf.to_crs(epsg = "25833")
This gives me
ValueError: Cannot transform naive geometries. Please set a crs on the object first.
This confuses me. The output of gdf.crs
is
<Geographic 2D CRS: EPSG:4326>
Name: WGS 84
Axis Info [ellipsoidal]:
- Lat[north]: Geodetic latitude (degree)
- Lon[east]: Geodetic longitude (degree)
Area of Use:
- name: World.
- bounds: (-180.0, -90.0, 180.0, 90.0)
Datum: World Geodetic System 1984 ensemble
- Ellipsoid: WGS 84
- Prime Meridian: Greenwich
I tried
gdf.set_crs(epsg = "4326")
and then
gdf.to_crs(epsg = "25833")
and got the same result.
Why can't GeoPandas reproject the coordinates?
Upvotes: 1
Views: 1705
Reputation: 12385
Doing this crs = "epsg:4326"
upon intialization of the GeoDataFrame
(gdf = gp.GeoDataFrame(...)
) does not seem like a good idea.
Besides that, setting the CRS
must be done with an inplace = True
.
gdf.set_crs(epsg = "4326", inplace = True)
Transforming too:
gdf.to_crs(epsg = "25833", inplace = True)
Upvotes: 3