Python Rasterio – Masking a Raster Using a Shapefile

pythonrasterioshapefile

This question refers to the doc of rasterio:
https://rasterio.readthedocs.io/en/latest/topics/masking-by-shapefile.html

I used the given code on the website.

out_meta.update({"driver": "GTiff",
                 "height": out_image.shape[1],
                 "width": out_image.shape[2],
                 "transform": out_transform})

with rasterio.open("RGB.byte.masked.tif", "w", **out_meta) as dest:
    dest.write(out_image)

How do they create the RGB.byte.masked.tif file ?

Best Answer

The line below opens "RGB.byte.masked.tif" for writing (note the "w" argument). It creates the file if it does not exist and completely overwrites it if it does exist.

with rasterio.open("RGB.byte.masked.tif", "w", **out_meta) as dest:
Related Question