An update-to-date solution to following questions:
- https://gis.stackexchange.com/questions/26893/creating-shapefile-showing-footprints-of-rasters
- https://gis.stackexchange.com/questions/61512/calculating-image-boundary-footprint-of-satellite-images-using-open-source-too
Variables used:
- RASTER1: the raster to be masked
- RASTER2: the raster to act as mask, usually with NoData (around data)
- MASK.geojson: the footprint of valid data from RASTER2
- OUT_RASTER: the output file path
Steps:
- Convert RASTER2 to vector MASK.geojson
rio shapes raster.tif --mask --collection --crop > MASK.geojson- Use vector MASK.geojson to mask RASTER1
rio mask RASTER1 OUT_RASTER --geojson-mask MASK.geojson
--cropoption to change the extent of the output raster to the mask extent. This is much faster when the mask area is small comparing to the raster extent.