我试图在卫星图像上运行后将scikit-image.measure.find_contours()函数的结果导出为shapefile或geojson .
输出是一个像(行,列)这样的数组,沿着轮廓有坐标,其中有许多 .
如何绘制各种轮廓的坐标,并将其导出到shapefile(可以设置适当的投影等)?
我当前的代码'mask'是我处理过的图片:
from skimage import measure
import matplotlib.pyplot as plt
contours = measure.find_contours(mask, 0.5)
plt.imshow(mask)
for n, contour in enumerate(contours):
plt.plot(contour[:,1], contour[:, 0], linewidth=1)
3 回答
由
rasterio
和fiona
的主要开发人员改编自post的以下内容应该有效,尽管我需要进一步调整 . 它使用rasterio.features.shapes
来识别图像中具有某些值的连续区域,并根据栅格的变换返回关联的坐标 . 然后使用fiona
将这些记录写入shapefile .你应该安装python库
geojson
并使用它 .为了使用图像中存在的坐标和标记对象,您应该使用库
shapely
.@Cate你可以使用那些
row, column
坐标矩阵并通过http://scikit-image.org/docs/dev/api/skimage.draw.html#skimage.draw.polygon(填充多边形),http://scikit-image.org/docs/dev/api/skimage.draw.html#skimage.draw.polygon_perimeter(仅周长)绘制它们,或者在http://matplotlib.org/api/patches_api.html#matplotlib.patches.Polygon之上创建自定义多边形绘图功能 .