I am using rasterio to cut out the shape of a lake outlined in my shapefile from a geotiff. When using a shapefile of a singular lake with a geotiff, this works perfectly, but not when cutting out a geotiff of a single lake with a different shapefile that contains a lot of different lake outlines. I'm wondering if there is a problem with the way my code is written or the files I'm using?
Here's my code:
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)
out_image
before you write it to see what it looks like? Also check the minimum value ofout_image
and see if it makes sense. I don't see any obvious issues with your code.