0

I have a GeoTiff raster with a format of Float32 and values 0.00 to 5.00. I am attempting to change all raster cells with a value below 0.10 to 0.10, and leave all other cells in the raster dataset unchanged.

Using some of the basic code examples provided on the GDAL Man pages, the initial snippet of code I used is as follows:

--calc="A*(A<0.10)"

The code executes successfully, however this sets all values below 0.10 to zero. What alteration to the formula needs to be made in order to meet the desired result?

0

If we look at the expression you have, A*(A<0.10)

(A<0.10) evaluates to a boolean, either True or False

If a boolean is used in place of a numeric value, True is equivalent to 1 while False is equivalent to 0

So when A is less than 0.1, we'd expect those values to be multiplied by 1 and remain, while values greater than that would be multiplied by 0. Not what we want.

Instead try doing (A*(A>=0.1))+(0.1*(A<0.1)). This should maintain the value (multiply by 1) if it's over 0.1, otherwise set it to zero. Then we add 0.1 to it if it's under 0.1, otherwise add 0.

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.