I've been reading several posts to do so and one option would be to use gdalwarp -cutline, but I would need to keep what it is NOT inside the polygon area. GDAL or any command-line tool does that?

  • Do you currently use Arcgis or Qgis?
    – TsvGis
    Aug 5, 2015 at 2:06
  • QGis yes, I know I can do it in ArcGis, but I want to add this processing step to my bash script, that's the reason why I'd like to use command-line tools such as GDAL.
    – Gery
    Aug 5, 2015 at 2:20

1 Answer 1


Draw the area(s) you want to hide from the image and save as vectors into shapefile or other format if you prefer. Then use the gdal_rasterize utility http://www.gdal.org/gdal_rasterize.html which burns fixed, non-transparent pixels into your image and removes permanently image data below the polygons.

Here is an example. The map is a RGB tiff image with RGB 0,0,0 defined as nodata value. Create two shapefiles red.shp and nodata.shp and save them on disk.

enter image description here

Run two gdal_rasterize commands. The first one is painting with red (RGB 255,0,0), the second one with totally black (RGB 0,0,0)

gdal_rasterize -b 1 -b 2 -b 3 -burn 255 -burn 0 -burn 0 red.shp burntest.tif
gdal_rasterize -b 1 -b 2 -b 3 -burn 0 -burn 0 -burn 0 nodata.shp burntest.tif

Open the image "burntest.tif" with a viewer that knows what to do with nodata

enter image description here

However, if the viewer does not know what to do with nodata the image will look different.

enter image description here

  • 1
    It is important to say few things: you need to run gdal_rasterize in update mode (updating existing geotiff, not creating new) and if you want your polygon area as no data you need to either know what is the no data value and use it as polygon attribute or burn value (depending what is more handy for you) or set attribute (burn value) to whatever you like and use -a_nodata value (which will overide existing no data value)
    – Miro
    Aug 5, 2015 at 5:40
  • Is there such an update mode? From the documentation: dst_filename: The GDAL supported output file. Must support update mode access. Before GDAL 1.8.0, gdal_rasterize could not create new output files.which sounds like update is the default and a new raster will be created only if the one with given filename does not exist.
    – user30184
    Aug 5, 2015 at 5:58
  • From my point of view the answer should include information on both that it is needed to overwrite the file and if "erase" is the goal then to find out and set null (no data) value. And provide simple example like if nodata is -9999: gdal_rasterize -burn -9999 -l erase_plg erase_plg.shp geotiff.tif . From my tests you can't use -a_nodata to set null value when in overwrite mode...
    – Miro
    Aug 5, 2015 at 7:31
  • I can make some tests and improve my answer but please tell me what parameter from gdal.org/gdal_rasterize.html I must use for reaching the overwrite mode? Or do you mean rather "paint" mode (or burn) for overwriting pixels (not file) with a visible, opaque color?
    – user30184
    Aug 5, 2015 at 7:39
  • Sorry for misunderstanding, first the part about nodata value is the important one which I wanted to draw attention to. You need to know the GeoTiFF nodata value to be able to "erase" some area by polygon by setting that area to nodata value. Plaese don't care about overwrite "mode". That is switched based on if file exist or not and of-course in this case we use gdal_rasterize with goal to overwrite existing file and not create new one - unless the geotiff nodata value needs to be set which makes everything more complicated because that can't be done in overwrite mode.
    – Miro
    Aug 5, 2015 at 7:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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