使用rasterio创建多边形,并根据lon,lat和0'和1' s的阵列形成整齐地创建多边形
我有一个带有0和1的数组。我试图将1转换为多边形。我已经设法使用rasterio进行操作,并像下面的代码中那样全身:
im = np.array([[0, 0, 0, 0, 0],
[0, 1, 1, 1, 0],
[0, 0, 1, 0, 0],
[0, 1, 1, 1, 0],
[0, 0, 0, 0, 0]])
shapes = rasterio.features.shapes(im)
polygons = [shapely.geometry.Polygon(shape[0]["coordinates"][0]) for shape in shapes if shape[1] == 1]
print(polygon[0])
但是,每个行和列都倒入经度和纬度坐标,存储在不同的数组中。例如:
lon = np.array([125. , 125.25, 125.5 , 125.75, 126. ])
lat = np.array([-35. , -35.25, -35.5 , -35.75, -36. ])
有人知道如何创建与正确的坐标相关的多边形吗?我认为我必须使用rasterio.features.features.shapes函数的转换参数。但是我还没有弄清楚。
I have an numpy array with 0 and 1's. I am trying to convert the 1's into polygons. I have managed to do so using rasterio and shapely as seen in the code below:
im = np.array([[0, 0, 0, 0, 0],
[0, 1, 1, 1, 0],
[0, 0, 1, 0, 0],
[0, 1, 1, 1, 0],
[0, 0, 0, 0, 0]])
shapes = rasterio.features.shapes(im)
polygons = [shapely.geometry.Polygon(shape[0]["coordinates"][0]) for shape in shapes if shape[1] == 1]
print(polygon[0])
however, each row and column reffers to longitude and latitude coordinates stored in different arrays. for example:
lon = np.array([125. , 125.25, 125.5 , 125.75, 126. ])
lat = np.array([-35. , -35.25, -35.5 , -35.75, -36. ])
Does anyone know how to create the polygons associated with the correct coordinates? I think I have to use the transform parameter of the rasterio.features.shapes function. Yet I haven't been able to figure it out yet.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
找到了解决方案。确实需要转换参数。此参数为仿射截止性,定义为:
可用于用rasterio创建多边形和摇摆
Found the solution. The transform parameter indeed is needed. This parameter is and affine trasnformation which is defined as:
that can be used to create the polygons with rasterio and shapely