[英]Geopandas: not able to change the crs of a geopandas object
我正在尝试按照此处所述设置 geopandas object 的crs
。
示例文件可以从这里下载
import geopandas as gdp
df = pd.read_pickle('myShp.pickle')
我上传屏幕截图以显示坐标值
然后,如果我尝试更改crs
,则多边形的值不会更改
tmp = gpd.GeoDataFrame(df, geometry='geometry')
tmp.crs = {'init' :'epsg:32618'}
我再次显示屏幕截图
如果我尝试:
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
超晚的答案,但它是:
tmp.set_crs(...)
使用它来定义数据所在的任何坐标系,即“告诉计算机我们开始使用的坐标系”
然后;
tmp.to_crs(...)
使用它来更改为您新的首选 crs。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.