繁体   English   中英

GeoPandas 转换 CRS:无法转换原始几何图形。 请先在对象上设置一个crs

[英]GeoPandas tranforming CRS: Cannot transform naive geometries. Please set a crs on the object first

我创建了一个这样的GeoDataFrame

gdf = gp.GeoDataFrame([], columns=['foo', 'geometry'], crs = "epsg:4326")

然后我用数据填充gdf 然后我想转换gdfCRS

gdf.to_crs(epsg = "25833")

这给了我

ValueError:无法转换简单的几何图形。 请先在对象上设置一个 crs。

这让我很困惑。 gdf.crs的输出是

<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

我试过

gdf.set_crs(epsg = "4326")

进而

gdf.to_crs(epsg = "25833")

并得到相同的结果。

为什么 GeoPandas 不能重新投影坐标?

在初始化GeoDataFrame ( gdf = gp.GeoDataFrame(...) ) 时执行crs = "epsg:4326"似乎不是一个好主意。

除此之外,必须使用inplace = True来设置CRS

gdf.set_crs(epsg = "4326", inplace = True)

也转型:

gdf.to_crs(epsg = "25833", inplace = True)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM