0

I'm trying to perform an operation using gdal calculator:

90*logical_and(A==111, B==3) + 92*logical_and(A==111, B==4) + 81*logical_and(A==112, B==3) + 86*logical_and(A==112, B==4)

but I get the following error:

gdal_calc.py: error: the following arguments are required: --outfile

Do you know what it means?

COMMAND IN GDAL RASTER CALCULATOR

input raster A: Uso_suolo_like_gruppi_idro_reclass_off (EPSG: 32632, float 32); input raster B: gruppi_idro_reclass_dimension (EPSG: 32632, 8 byte);

gdal_calc.bat --calc "gdal_calc.bat --calc "90*logical_and(A==111,B==3) + 92*logical_and(A==111, B==4) + 81*logical_and(A==112, B==3) + 86*logical_and(A==112, B==4)" --format GTiff --type Float32 -A C:\data\orto\3band.tif --A_band 1 -B C:\data\orto\3band.tif --B_band 2 -C C:\data\orto\3band.tif --C_band 3 --outfile C:/Temp/processing_xIueLp/c3ead72b992c4f9baac3f260b69082c2/OUTPUT.tif" --format GTiff --type Byte -A "Uso suolo_like_gruppi_idro_reclass_off" --A_band 1 --B "C:\\Users\\Anto\\OneDrive\\Desktop\\Progetto ROMA\\DATI\\Dati GIS\\Acqua\\Gruppi_idro_reclass.tif" --B_band 1 --outfile C:/Users/Anto/AppData/Local/Temp/processing_zxLIka/29c0cbd5ca6547f995f39f24fa301993/OUTPUT.tif

output raster: float 32

RESULT

gdal_calc.py: error: unrecognized arguments: suolo_like_gruppi_idro_reclass_off --A_band 1 --B C:\Users\Anto\OneDrive\Desktop\Progetto ROMA\DATI\Dati GIS\Acqua\Gruppi_idro_reclass.tif --B_band 1 --outfile C:/Users/Anto/AppData/Local/Temp/processing_zxLIka/29c0cbd5ca6547f995f39f24fa301993/OUTPUT.tif


COMMAND IN GDAL RASTER CALCULATOR

input raster A: Uso_suolo_like_gruppi_idro_reclass_off (EPSG: 32632, float 32); input raster B: gruppi_idro_reclass_dimension (EPSG: 32632, 8 byte);

gdal_calc.bat --calc "gdal_calc.bat --calc "90*logical_and(A==111,B==3) + 92*logical_and(A==111, B==4) + 81*logical_and(A==112, B==3) + 86*logical_and(A==112, B==4)" --format GTiff --type Float32 -A C:\data\orto\3band.tif --A_band 1 -B C:\data\orto\3band.tif --B_band 2 -C C:\data\orto\3band.tif --C_band 3 --outfile C:/Temp/processing_xIueLp/c3ead72b992c4f9baac3f260b69082c2/OUTPUT.tif" --format GTiff --type Byte -A "Uso suolo_like_gruppi_idro_reclass_off" --A_band 1 --B "C:\\Users\\Anto\\OneDrive\\Desktop\\Progetto ROMA\\DATI\\Dati GIS\\Acqua\\Gruppi_idro_reclass.tif" --B_band 1 --outfile C:/Users/Anto/AppData/Local/Temp/processing_zxLIka/29c0cbd5ca6547f995f39f24fa301993/OUTPUT.tif

output raster: float 32

RESULT

gdal_calc.py: error: unrecognized arguments: suolo_like_gruppi_idro_reclass_off --A_band 1 --B C:\\Users\\Anto\\OneDrive\\Desktop\\Progetto ROMA\\DATI\\Dati GIS\\Acqua\\Gruppi_idro_reclass.tif --B_band 1 --outfile C:/Users/Anto/AppData/Local/Temp/processing_zxLIka/29c0cbd5ca6547f995f39f24fa301993/OUTPUT.tif
8
  • In Qgis 3.16.11 Jan 13, 2022 at 12:05
  • Do you use command line or a tool in QGIS? Jan 13, 2022 at 12:09
  • Hi Kadir, I use the GDAL calculator tool in Qgis Jan 13, 2022 at 12:11
  • 1
    Does it work with the default settings and algorithm? Defaults seem to generate a GDAL command like gdal_calc.bat --calc "A*2" --format GTiff --type Float32 -A C:\test\test.tif --A_band 1 --outfile C:/Temp/processing_xIueLp/5f627158b03a458ebec6fffa42673d7f/OUTPUT.tif
    – user30184
    Jan 13, 2022 at 12:37
  • 1
    What is your raster source? I managed get the same error by using a WMS layer as a source. Could you add the generated GDAL command into your question? You can read the meaning of parameters from gdal.org/programs/gdal_calc.html.
    – user30184
    Jan 13, 2022 at 12:53

2 Answers 2

1

Your code works for me with a normal 8-bit RGB raster file. The generated GDAL command in this case is

gdal_calc.bat --calc "90*logical_and(A==111, B==3) + 92*logical_and(A==111, B==4) + 81*logical_and(A==112, B==3) + 86*logical_and(A==112, B==4)" --format GTiff --type Float32 -A C:\data\orto\3band.tif --A_band 1 -B C:\data\orto\3band.tif --B_band 2 -C C:\data\orto\3band.tif --C_band 3 --outfile C:/Temp/processing_xIueLp/c3ead72b992c4f9baac3f260b69082c2/OUTPUT.tif
17
  • Hi User 30184, thank you for your help. I inserted two rasters (A=land use code 111,112 etc) and B = hydrological groups = 3 or 4). The rasters are in the same projection and same cell size, they differ only because the first one is float32 while the second one is 8 bytes. In GDAL commands I put float32 as output format. Jan 13, 2022 at 14:07
  • I tried with the formula you entered, but it gives me the following error (with both float32 and byte output) : gdal_calc.py: error: unrecognized arguments: soil_like hydro groups reclass_off --A_band 1 -B C:\Users\\Anto\OneDrive\Desktop\Project ROMA\\Data GIS\Acqua\Groups Hydro_reclass. tif --B_band 1 --outfile C:/Users/Anto/AppData/Local/Temp/processing_zxLIka/29c0cbd5ca6547f995f39f24fa301993/OUTPUT.tif Jan 13, 2022 at 14:07
  • 1
    Please add your exact command to your question. And use file names which do not have spaces.
    – user30184
    Jan 13, 2022 at 14:22
  • input raster A: Uso_suolo_like_gruppi_idro_reclass_off (EPSG: 32632; float 32); input raster B: gruppi_idro_reclass_dimension (EPSG: 32632; 8 byte); Jan 13, 2022 at 14:41
  • 1
    Please add all that info into your question, it is hard for the readers to find the information from the comments. But it is obvious that spaces are clipping the command. Uso suolo_like_gruppi_idro_reclass_off gets cut into parts Uso and suolo_like_gruppi_idro_reclass_off, therefore error unrecognized arguments: suolo_like_gruppi_idro_reclass_off. And don't copy the names of my files into your command.
    – user30184
    Jan 13, 2022 at 15:28
0

I finally found the solution, much simpler, I simply entered the formula without any other commands and it came!

enter image description here

1

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.