I have two hillshading geotifs that I created using gdaldem hillshade. One covers a huge area with an OK resolution and the other has a much higher resolution for a smaller part within the huge area. It looks something like that:

+------------------+ big
|                  |
|                  |
|     +----+ small |
|     |    |       |
|     |    |       |
|     +----+       |
|                  |
|                  |

So now I'd like to know how to set the part inside the big tif to nodata (or any other value...). It's only shades of gray, so no RGB (only one byte per pixel).

Is there a way to first get the exact extent of the small tiff? And with that extent I'd like to set all pixel within this extend in the other tif to a given value... Is this possible? Would be great if someone could tell me the command I have to use in probably gdal?!?


A simple method that does not need programming is to digitize the area of "small" into vector file as a polygon and then burn it into the image with gdal_rasterize http://www.gdal.org/gdal_rasterize.html

If the small image is rectangular without nodata regions you can get the mask shapefile with gdaltindex http://www.gdal.org/gdaltindex.html

gdaltindex mask.shp small.tif

I copy the first example from the gdal_rasterize manual page here:

The following would burn all polygons from mask.shp into the RGB TIFF file work.tif with the color red (RGB = 255,0,0).

gdal_rasterize -b 1 -b 2 -b 3 -burn 255 -burn 0 -burn 0 -l mask mask.shp work.tif

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.