chip-from-vrt.py 文件源码

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

项目:chip-from-vrt 作者: PlatformStories 项目源码 文件源码
def mask_chip(feature):
    '''
    Apply polygon mask to bounding-box chips. Chips must be named
        'feature_id.tif' and exist in the current working directory.
    '''
    fn = feature[:-4] + '.geojson'
    chip = gdal.Open(feature)

    # Create ogr vector file for gdal_rasterize
    vectordata = {'type': 'FeatureCollection', 'features': [feature]}

    with open(fn, 'wb') as f:
        geojson.dump(vectordata, f)

    # Mask raster
    cmd = 'gdal_rasterize -q -i -b 1 -b 2 -b 3 -burn 0 -burn 0 -burn 0 {} {}'.format(fn, feature)
    subprocess.call(cmd, shell=True)

    # Remove ogr vector file
    os.remove(fn)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号