【问题标题】:how to assign units to geometries and projection to polygon in python3?如何在python3中将单位分配给几何图形并投影到多边形?
【发布时间】:2020-08-06 16:11:49
【问题描述】:

我从 PNG 图像创建了一个多面体(shapefile)。 PNG 图像最初是 GeoTIFF。 我的多面体的几何形状是正常 x,y 轴的值(以 0,0 作为原点)。换句话说,几何图形不是经纬度。 查看示例:

geometry  
0  POLYGON ((0.000 0.000, 0.000 310.000, 5.000 31...  
1  POLYGON ((160.000 0.000, 160.000 3.000, 159.00...  
2  POLYGON ((794.000 219.000, 794.000 0.000, 443....  
3  POLYGON ((555.000 451.000, 793.000 451.000, 79...  
4  POLYGON ((417.000 451.000, 555.000 451.000, 55...  
5  POLYGON ((237.000 196.000, 237.000 205.000, 23...

我想将我的多边形投影到地球上的特定 CRS 和位置。此多边形应与原始 GeoTIFF 的 bbox 和 CRS 匹配。我的多面体没有定义 CRS。

如何投影我的多面体?我尝试了以下,并得到了错误: AttributeError: 'GeoDataFrame' 对象没有属性 'set_crs'

import geopandas as gpd

fp = r"C:\foo\intersection_all2.shp" 

data = gpd.read_file(fp)
data['geometry'].head()


# Let's make a copy of our data
orig = data.copy()

# Reproject the data
data = data.set_crs(epsg=32618)

我正在寻找适用于 Python 3.7、Windows 10 的解决方案。

【问题讨论】:

  • 我认为你需要更新 geopandas 才能使用set_crs
  • 谢谢,我试过了,但没有帮助

标签: python projection geopandas


【解决方案1】:

它说没有属性,所以像这样在对象属性上设置crs

gdf.crs = {"init":"epsg:4326"}

然后你可以通过to_crs()将它投影到另一个,例如

gdf.to_crs(epsg=3857)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-24
    • 2012-10-30
    • 2017-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多