从点制作geopandas数据框,然后投影gpd,出现错误:无法转换原始几何.请先在对象上设置crs [英] make geopandas dataframe from points, then project the gpd, got error: Cannot transform naive geometries. Please set a crs on the object first

查看:613
本文介绍了从点制作geopandas数据框,然后投影gpd,出现错误:无法转换原始几何.请先在对象上设置crs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将经纬度的数据集转换为geopandas数据框(我们称其为gpd). gpd没有CRS,我正在尝试将此gpd投影到"EPSG:3857".使用:

I converted a dataset with lat/lon to a geopandas dataframe (let's call it gpd). The gpd has no CRS, I was trying to project this gpd to "EPSG:3857" using:

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

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

我收到一个错误消息,说无法转换朴素的几何图形.请首先在对象上设置CRS".这是否意味着对于任何没有CRS的gpd,我必须先为其分配一个CRS,然后将其重新投影到我感兴趣的CRS,例如,从4326到3857:

I got an error saying that "Cannot transform naive geometries. Please set a CRS on the object first". Does this mean that for any gpd without CRS, I have to assign a CRS to it first, then reproject it to CRS I am interested in, for example, from 4326 to 3857:

gpd.crs ="EPSG:4326"

gpd.crs = "EPSG:4326"

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

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

我的困惑是CRS和投影之间的区别,为什么在这种情况下我不能直接使用3857.此外,pyproj项目还提到在重新投影地理数据时发生了一些变化,给出了有关如何投影地理数据的建议,我不太清楚这些细节,有人可以给出一些有关如何适当地投影/重新投影地理数据的建议吗?谢谢.

My confusions are the differences between CRS and projection, and why can not I use 3857 directly in this case. Also, the pyproj project has mentioned that there are some changes in reprojecting geodata and gave suggestions about how to project geodata, I do not clearly understand the details, can somebody give some advice on how to project/reproject geodata appropriately given the changes they made? Thanks.

推荐答案

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

You need to define the crs before you can project it. This often happens if your .shp file doesn't have an accompanying .prj file.

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之后,就可以对其进行投影了.

After you've defined your crs, then you can project it.

#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

这篇关于从点制作geopandas数据框,然后投影gpd,出现错误:无法转换原始几何.请先在对象上设置crs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆