Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- from osgeo import gdal
- import numpy as np
- import pandas as pd
- import ogr
- import rasterio as rio
- import fiona
- import rasterio
- import rasterio.mask
- inDir = 'F:/python/Doy_2000/'
- driver = ogr.GetDriverByName('ESRI Shapefile')
- os.chdir(inDir)
- with fiona.open("F:/python/Doy_2000/poly2000.shp", "r") as shapefile:
- shapes = [feature["geometry"] for feature in shapefile]
- with rasterio.open("F:/python/Doy_2000/raster1.tif") as src:
- out_image, out_transform = rasterio.mask.mask(src, shapes, 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("2000mask.tif", "w", **out_meta) as dest:
- dest.write(out_image)
Add Comment
Please, Sign In to add comment