1

I wish to apply one raster (GeoTIFF) as a mask to another raster. How can I do this using GDAL tools? I'd be happy to achieve this as a virtual raster because these images are large.

Will it be necessary to customise a .vrt using a text editor, i.e., is there no way in gdalbuildvrt to insert a <MaskBand>? Or is the simplest approach to use gdal_calc.py to multiply the rasters together?

4
  • What would be the effect of the mask? Is it that the image that is on the top would hide all pixels of the image that is on the bottom and show them as transparent, or nodata, or with some fixed color?
    – user30184
    Jan 24, 2018 at 8:07
  • @user30184 The mask has values of 1 or zero, and the effect would be the same as multiplication (i.e. overwriting with the implicit nodata fill value of zero).
    – benjimin
    Jan 25, 2018 at 0:29
  • Ok, you should explain better in your question that "one raster" is a ready mask with ones and zeroes only.
    – user30184
    Jan 25, 2018 at 5:40
  • 1
    Try with two steps: gdalbuildvrt interim.vrt image1.tif image2.tif and then gdal_translate -of VRT -b 1 -mask 2 interim.vrt final.vrt.
    – user30184
    Jan 25, 2018 at 10:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.