Guest User

Untitled

a guest
Jan 17th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. import os
  2. from osgeo import gdal
  3. import numpy as np
  4. import pandas as pd
  5. import ogr
  6. import rasterio as rio
  7. import fiona
  8. import rasterio
  9. import rasterio.mask
  10.  
  11. inDir = 'F:/python/Doy_2000/'
  12. driver = ogr.GetDriverByName('ESRI Shapefile')
  13. os.chdir(inDir)
  14.  
  15. with fiona.open("F:/python/Doy_2000/poly2000.shp", "r") as shapefile:
  16. shapes = [feature["geometry"] for feature in shapefile]
  17.  
  18. with rasterio.open("F:/python/Doy_2000/raster1.tif") as src:
  19. out_image, out_transform = rasterio.mask.mask(src, shapes, crop=True)
  20. out_meta = src.meta.copy()
  21.  
  22. out_meta.update({"driver": "GTiff",
  23. "height": out_image.shape[1],
  24. "width": out_image.shape[2],
  25. "transform": out_transform})
  26.  
  27. with rasterio.open("2000mask.tif", "w", **out_meta) as dest:
  28. dest.write(out_image)
Add Comment
Please, Sign In to add comment