gpt4 book ai didi

python - Geopandas:无法更改 geopandas 对象的 crs

转载 作者:太空宇宙 更新时间:2023-11-04 01:58:27 30 4
gpt4 key购买 nike

我正在尝试按照描述设置 geopandas 对象的 crs here .

示例文件可以从here下载。

import geopandas as gdp
df = pd.read_pickle('myShp.pickle')

我上传屏幕截图以显示坐标值

enter image description here

然后,如果我尝试更改 crs,则多边形的值不会更改

tmp = gpd.GeoDataFrame(df, geometry='geometry')
tmp.crs = {'init' :'epsg:32618'}

我再次显示截图

enter image description here

如果我尝试:

import geopandas as gdp
df = pd.read_pickle('myShp.pickle')
df = gpd.GeoDataFrame(df, geometry='geometry')
dfNew=df.to_crs(epsg=32618)

我得到:

ValueError: Cannot transform naive geometries.  Please set a crs on the object first.

最佳答案

像这样设置 crs:

gdf.crs = {'init' :'epsg:32618'}

不会转换您的数据,它只会设置 CRS(它基本上是说:“我的数据在此 CRS 中表示”)。在大多数情况下,在使用 geopandas.read_file 读取数据时已经设置了 CRS(如果您的文件具有 CRS 信息)。所以只有当你的数据还没有CRS信息的时候,你才需要以上。

如果您真的想将坐标转换为不同的 CRS,您可以使用 to_crs方法:

gdf_new = gdf.to_crs(epsg=32618)

参见 https://geopandas.readthedocs.io/en/latest/projections.html

关于python - Geopandas:无法更改 geopandas 对象的 crs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56274566/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com