make geopandas dataframe from points, then project the gpd, got error: Cannot transform naive geometries. Please set a crs on the object first

make geopandas dataframe from points, then project the gpd, got error: Cannot transform naive geometries. Please set a crs on the object first

我将 lat/lon 的数据集转换为 geopandas 数据框(我们称之为 gpd)。 gpd 没有 CRS,我试图将此 gpd 投影到“EPSG:3857”,使用:

gpd = gpd.to_crs("EPSG:3857")

我收到一条错误消息“无法转换原始几何体。请先在对象上设置 CRS”。这是否意味着对于任何没有CRS的gpd,我必须先为其分配一个CRS,然后将其重新投影到我感兴趣的CRS,例如从4326到3857:

gpd.crs = "EPSG:4326"

gpd = gpd.to_crs("EPSG:3857")

我的疑惑是CRS和projection的区别,这种情况下为什么不能直接用3857。另外,pyproj 项目已经提到 there are some changes in reprojecting geodata 并给出了关于如何投影地理数据的建议,我不太清楚细节,有人可以就如何 project/reproject 地理数据给出一些建议吗?考虑到他们所做的更改?谢谢

您需要先定义crs,然后才能对其进行投影。如果您的 .shp 文件没有附带的 .prj 文件,就会经常发生这种情况。

import geopandas as gpd
gdf = gpd.read_file('GSHHS_c_L1.shp')
print(gdf.crs)
None

#this is how we define the projection
gdf.crs = "EPSG:4326"
print(gdf.crs)
EPSG:4326

#In Jupyter if you don't use a print statement, but shift+enter, you'll get this for your 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
- Ellipsoid: WGS 84
- Prime Meridian: Greenwich

定义好crs后,就可以投影了。

#this is how we project the data
gdf = gdf.to_crs("EPSG:3857")
# this will display crs information in jupyter
gdf.crs

<Projected CRS: EPSG:3857>
Name: WGS 84 / Pseudo-Mercator
Axis Info [cartesian]:
- X[east]: Easting (metre)
- Y[north]: Northing (metre)
Area of Use:
- name: World - 85°S to 85°N
- bounds: (-180.0, -85.06, 180.0, 85.06)
Coordinate Operation:
- name: Popular Visualisation Pseudo-Mercator
- method: Popular Visualisation Pseudo Mercator
Datum: World Geodetic System 1984
- Ellipsoid: WGS 84
- Prime Meridian: Greenwich