我将带有纬度/经度的数据集转换为 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 和投影之间的差异,以及为什么在这种情况下我不能直接使用 3857。另外, pyproj 项目提到了重新投影地理数据有一些变化 https://pyproj4.github.io/pyproj/stable/gotchas.html并给出了有关如何投影地理数据的建议,我不清楚细节,有人可以根据他们所做的更改就如何适当地投影/重新投影地理数据提供一些建议吗?谢谢。
您需要先定义 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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)