0

I am looking to utilise gdal_calc to batch binarise a few hundred rasters. I am having dificulty though in relation to the correct formula to achieve this. I am trying to make all the values between -20 and -15 in a raster = 1 and everything else = 0, making 0 NoData.

PolyGeo
  • 65,136
  • 29
  • 109
  • 338

1 Answers1

5

You can use gdal_calc.py with conditional statements.
This should do the trick:

gdal_calc.py -A input.tif --outfile=result.tif --calc="(A>=-20)*(A<=-15)" --NoDataValue=0

or

gdal_calc.py -A input.tif --outfile=result.tif --calc="logical_and(A>=-20,A<=-15)" --NoDataValue=0

This returns values 0 and 1. Add "255*" if you want values 0 and 255.

pLumo
  • 6,489
  • 20
  • 41