7

I have 2 rasters in GeoTiff format. One has all of the land and water and the other is a mask file that shows either 0 for water or 1 for land. I basically want my output to just have the land values and all the areas that were water in the first image to just be 0,0,0. Is there a way to do this with any of the gdal command line tools?

Basically I want to do what gdal_rasterize does with a shp file mask but with a raster instead.

  • Welcome to gis.SE. Can you expand your question (just click edit below the question) to add details of your situation. In particular, you could include the format the rasters are in, what you've already looked at, what you've already tried, what worked, what didn't work, and what happened instead. Also, you might like to explain why you've tagged this with C++ and clip, which aren't obvious from the question. – BradHards Dec 19 '13 at 23:49
  • Your mask should have values of 0 for water and 1 for land. – neogeomat Dec 20 '13 at 5:18
  • sorry I am pretty new to gis work. Anyway, I tagged it with c++ because I have been able to use the gdal API to get some other things done and if a solution doesn't exist with the existing command line tools, I am willing to write some code. – Perez Dec 20 '13 at 16:57
  • You are right the mask is 0 and 1. Globalmapper shows it as 0,0,0 and 255,255,255 though. gdalinfo just shows it as a 1 band gray scale image. – Perez Dec 20 '13 at 17:12
1

You may want to check gdal_translate (see http://www.gdal.org/gdal_translate.html) in which you can define a mask band. But first, you'll have to stack your two raster in a multiband image.

0

You can use gdal_calc.py see: http://www.gdal.org/gdal_calc.html if your mask is a raster of same dimension

gdal_calc.py -A input.tif -B mask.tif --A_band=3 --B_band=3 --outfile=result.tif --calc="A*B"

That will multiply each cell of the raster with the corresponding cell of the mask. Where the mask cell is 0,0,0 the output cell will be 0,0,0 and where the mask cell value is 1,1,1 the output will be the same as the input.

P.S.: I did'nt test it, please read the doc carefuly

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.