有谁知道为什么我将这个shapefile从rasterio中的另一个geotiff中剪下来而得到一个全黑色的geotiff?

时间:2018-07-18 17:35:46

标签: python shapefile geotiff rasterio

我正在使用rasterio从geotiff剪切出shapefile中概述的湖泊形状。当使用带有geotiff的奇异湖的shapefile时,这是完美的方法,但是当使用包含许多不同湖轮廓的shapefile剪切单个湖的geitiff时,效果并不理想。我想知道我的代码编写方式或正在使用的文件是否存在问题?

这是我的代码:

import rasterio
import rasterio.mask
import fiona

with fiona.open("liag_shapes/liag_shapes.shp", "r") as shapefile:
    features = [feature["geometry"]for feature in shapefile]

with rasterio.open("lakesimcoe11.tif") as src:
    out_image, out_transform = rasterio.mask.mask(src, features, filled=True,
crop=True)
    out_meta = src.meta.copy()

out_meta.update({"driver": "GTiff",
                 "height": out_image.shape[1],
                 "width": out_image.shape[2],
                 "transform": out_transform})

with rasterio.open("new_test.tif", "w", **out_meta) as dest:
    dest.write(out_image)

0 个答案:

没有答案