I have a script which clips raster data by a shapefile using rasterio and fiona:
import fiona
import rasterio
import rasterio.mask
def clip_raster(shp, imagery, out_imagery):
with fiona.open(shp, "r") as shapefile:
features = [feature["geometry"] for feature in shapefile]
with rasterio.open(imagery) as src:
out_image, out_transform = rasterio.mask.mask(src, features, 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,
"compress": "LZW",
"nodata": 255})
with rasterio.open(out_imagery, "w", **out_meta) as dest:
dest.write(out_image)
if __name__ == "__main__":
shp = r'/path/to/shapefile.shp'
imagery = r'/path/to/input_imagery.tif'
out_imagery = r'/path/to/output_imagery.tif'
clip_raster(shp, imagery, out_imagery)
You can see that the .update()
method has a variety of options such as setting the compression type ("compress": "LZW"
) or nodata value ("nodata": 255
):
out_meta.update({"driver": "GTiff",
"height": out_image.shape[1],
"width": out_image.shape[2],
"transform": out_transform,
"compress": "LZW",
"nodata": 255})
Is there a list or documentation of all the available options available to the .update()
method when writing raster data using rasterio?