Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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)
Add Comment
Please, Sign In to add comment