Guest User

Untitled

a guest
Jul 18th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. import rasterio
  2. import rasterio.mask
  3. import fiona
  4.  
  5. with fiona.open("liag_shapes/liag_shapes.shp", "r") as shapefile:
  6. features = [feature["geometry"]for feature in shapefile]
  7.  
  8. with rasterio.open("lakesimcoe11.tif") as src:
  9. out_image, out_transform = rasterio.mask.mask(src, features,
  10. filled=True, crop=True)
  11. out_meta = src.meta.copy()
  12.  
  13. out_meta.update({"driver": "GTiff",
  14. "height": out_image.shape[1],
  15. "width": out_image.shape[2],
  16. "transform": out_transform})
  17.  
  18. with rasterio.open("new_test.tif", "w", **out_meta) as dest:
  19. dest.write(out_image)
Add Comment
Please, Sign In to add comment