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.

1

1 Answer 1

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.

0

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