GeoPandas .to_crs() method not converting

半世苍凉 提交于 2021-01-07 01:29:10

问题


I am trying to convert some datasets into the same coordinate system (NC2264)

NC2264 = 'EPSG:2264'

sfd_subs = pd.read_csv(r'FILE_LOCATION.csv')
wake_shapes = gpd.GeoDataFrame.from_file(r'FILE_LOCATION.shp').to_crs(NC2264)

sfd_subs = gpd.GeoDataFrame(sfd_subs, geometry=gpd.points_from_xy(sfd_subs.Longitude, sfd_subs.Latitude),crs='EPSG:4326')
sfd_subs.to_crs(NC2264)

print(sfd_subs.crs)

The shapefile conversion works perfectly but the 'sfd_subs' remains unchanged. I'm getting no errors.

I've included 5 of the correct conversions on top vs the unchanged conversion on the bottom.

EPSG:4326
0       POINT (2641914.208 1398556.771)
1       POINT (2642559.277 1398183.388)
2       POINT (2641705.300 1398352.924)
3       POINT (2641716.844 1397826.942)
4       POINT (2674989.747 1419749.281)
                     ...               
3332             POINT (-78.135 35.506)
3333             POINT (-78.130 35.504)
3334             POINT (-78.123 35.530)
3335             POINT (-78.104 35.537)
3336             POINT (-78.087 35.562)

Since I'm getting no errors I'm not sure what the best course of action is.


回答1:


You have to assign a converted GeoDataFrame to a variable, as the function doesn't modify it inplace.

# instead of only writing: sdf_subs.to_crs(NC2264), assign it back to variable
sdf_subs = sfd_subs.to_crs(NC2264)


来源:https://stackoverflow.com/questions/65566168/geopandas-to-crs-method-not-converting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!