光栅矢量化多边形拓扑处理工具
rastachimp的Python项目详细描述
RastachImp
rastachimp是一个实用程序库,用于执行从raster矢量化的多边形的拓扑处理,如rasterio.features.shapes function:
- 简化,使用douglas peucker:Shapely(和geos)可用于简化多边形,但会在共享边界的多边形之间创建间隙和重叠(即使preserve_topology=true)
- 平滑,使用chaikin方法
- 致密化
rastachimp将多边形分解为边(使用shapely),对其应用操作,然后重建转换的多边形。只要rasterio.features.shapes的输出是像素坐标(默认值),或者到世界坐标的转换没有旋转组件(通常是这种情况),它就可以正常工作。由于有限的浮动精度,在更一般的情况下可能无法很好地工作,尽管如果多边形是节点化的(例如,使用bpol tool of v.clean in GRASS)则可以。
安装
pip install rastachimp
使用量
执行简化的函数是simplify_dp
。作为输入,它将元组(几何体、值)作为rasterio.features.shapes和公差(与输入几何体的单位相同)的输出。它返回元组(几何体、值)的迭代器,就像rasterio.features.shapes一样。
fromrasterioimportfeaturesfromrastachimpimportas_shapely,simplify_dp# 2D array with classification valuesimage=np.array(....,dtype=np.uint8)# no transform => in pixel coordinatesshapes=features.shapes(image)# convert to Shapely geometry (features.shapes returns a GeoJSON dict)shapes=as_shapely(shapes)tolerance=2# simpl is an interator of tuples (geometry, value)simpl=simplify_dp(shapes,tolerance)
问题
在https://github.com/gvellut/rastachimp/issues报告问题
待办事项
- 更好地检测和处理不良输入
- 其他泛化算法(visvalingam)
- 其他平滑算法(贝塞尔曲线)