2

I have a DEM in GeoTiff format. The processing have made areas that have really low values that I would like to remove.

Are there any GDAL tools that could set all values below -30 to NODATA or -30.

2
  • I've seen this question before... I think the easiest way is in QGIS raster calculator. Nov 6, 2014 at 0:14
  • It can be done in GDAL independent of QGIS using calc.py. Answer posted below. Nov 6, 2014 at 14:36

1 Answer 1

6

Sure you can use the No Data value in gdal_translate

-a_nodata value:

Assign a specified nodata value to output bands. Starting with GDAL 1.8.0, can be set to none to avoid setting a nodata value to the output file if one exists for the source file.

or in gdal_cac.py use the less than (<) or greater than (>) or equals (=) commands.

For example, below will convert the values below 3 to 0 and above 3 to 1. You can use equals as well.

gdal_calc.py -A C:temp\raster.tif --outfile=result.tiff --calc="0*(A<3)" --calc="1*(A>3)"

so as written by Michael yours would be along the lines of

gdal_calc.py -A input.tif --outfile=result.tif --calc="A*(A>-30)" --NoDataValue=-30

Or a combination of above.

4
  • Can you use gdal_calc to set a constant for less than and then the original value in the raster for greater than? Nov 6, 2014 at 0:15
  • 1
    The last example seems to do just that gdal.org/gdal_calc.html gdal_calc.py -A input.tif --outfile=result.tif --calc="A*(A>-30)" --NoDataValue=-30 thanks! I'll definitely be using that in the future. Nov 6, 2014 at 0:42
  • Yes it does sir, it seems underused to me as I have posted a similar answer on this board a few times. Nov 6, 2014 at 2:21
  • when i run the above code in my windows terminal, i get prompted to open it "gdal_cal.py" with a program...Where can i find some proper documentation on how to use gdal_cal.py.
    – J.A.Cado
    Apr 16, 2018 at 4:34

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.