Search code examples
algorithmmathgdal

max() implemented with basic operators


I'm wrangling some bad data in a raster image using GDAL with gdal_calc.py. I'm trying to clip value A at -100 like this:

max(A, -100)

However, only basic operators (+-/*) and logical operators (><, these return 0 or 1) are allowed. Is there a way to implement this? Got as far as returning 0 for values less than -100

A*(A>-100)

Solution

  • another one:

    (A+100)*(A>-100) - 100
    

    here the min value will be displaced to 0 to match the lower bound, then displaced back to -100.