raster.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:CHaMP_Metrics 作者: SouthForkResearch 项目源码 文件源码
def get_data_polygon(rasterfile):

    import rasterio
    from rasterio.features import shapes
    from shapely.geometry import shape

    r = Raster(rasterfile)
    array = np.array(r.array.mask*1, dtype=np.int16)

#    with rasterio.drivers():
    with rasterio.open(rasterfile) as src:
        image = src.read(1)
        mask_array = image != src.nodata
        results = ({'properties': {'raster_val': v}, 'geometry': s}
                    for i, (s, v) in enumerate(shapes(array, mask=mask_array, transform=src.affine)))

    geoms = list(results)
    polygons = [shape(geom['geometry']) for geom in geoms]

    return polygons
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号