0

Would like to achieve this in gdal_calc.Py if possible.

I have a raster with a value of 0-7 in GTiff

I would like one output raster where

NoData = 0,1,2,3

1 = 4,5,6,7

So basically an ArcGIS reclass but using gdal_calc.py. I know how to do it in QGIS, ArcGIS, etc.

I know this question has been asked before for SAGA, QGIS, GRASS (r.reclass), but I do not see it for gdal_calc.py

1
  • gdal_calc.py -A Aq.tiff --outfile=Aq_Reclass.tiff --calc="A*(A>3)" --NoDataValue=0 This seems to work for the NoData part , setting 0,1,2,3 to NoData but how to set 4,5,6,7 to 1? Commented Jun 8, 2014 at 18:12

1 Answer 1

1

Thanks for the help

this seems to work.

gdal_calc.py -A filename.tiff --outfile=filename.tiff --calc="A*(A>3)" --NoDataValue=0 --calc="1*(A<3)

4
  • 1
    not exactly, but this is the right track. You could use --calc="1*(A>3)" (note that 1* is not necessary here, just for the example).
    – radouxju
    Commented Jun 8, 2014 at 18:43
  • --calc shouldn't be passed twice - I believe the first will be ignored.
    – jbaums
    Commented Aug 20, 2015 at 3:14
  • you have to make a single --calc 1*(A<=4) +2*((A>4)*(A<=9))+3*((A>9)*(A<=16))+4*((A>16)*(A<=31))+5*((A>31)*(A<=41))+6*((A>41)*(A<=1000))
    – PEL
    Commented Feb 27, 2017 at 18:22
  • The answer has 2 --calc expressions, which is accepted by gdal_calc.py (if the GDAL version >= 3.2). However in this case it seems to be a mistake. Multiple --calc expressions should be used only to produce a multiband file: gdal.org/programs/gdal_calc.html#cmdoption-calc Commented Nov 3, 2022 at 14:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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