TransWikia.com

gdal_calc.py SyntaxError

Geographic Information Systems Asked on December 6, 2021

I tried to use gdal_calc.py to avoid using the manual GUI raster calculator in QGIS. However, I’m not yet familiar with it and having errors with my code:

gdal_calc.py -A perennials.tif -B annuals.tif --outfile=annuals_only.tif --calc="(A<=85 or B=2001)*(A)" --format=GTiff 0 .. evaluation of calculation (A<=85 or B=2001)*(A) 

evaluation of calculation (A<=85 or B=2001)*(A) failed Traceback (most recent call last):
  File "/usr/bin/gdal_calc.py", line 401, in <module>
    main()
  File "/usr/bin/gdal_calc.py", line 394, in main
    doit(opts, args)
  File "/usr/bin/gdal_calc.py", line 288, in doit
    myResult = eval(opts.calc, global_namespace, local_namespace)
  File "<string>", line 1
    (A<=85 or B=2001)*(A)
               ^
SyntaxError: invalid syntax

Is there some thing I can improve in my –calc formula?

One Answer

Your syntax is wrong for logical operator (or). Try this:

gdal_calc.py -A perennials.tif -B annuals.tif --outfile=annuals_only.tif --calc="A*logical_or(A<=85, B=2001)"

I would also add --NoDataValue=0 to avoid large black areas in the output.

Answered by Zoltan on December 6, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP