3

I'm trying to reclassify some categorical raster data in QGIS using GDAL raster calculator. My input Geotiff has four values, [26, 27, 31, 32] which I want reclassified to [1.25, 2.5, 3.75, 5] respectively.

I want to use GDAL raster calc so I can use GDAL's lossless compression creation options(the input raster is quite large).

The logic I've tried is the following, where inputraster.tif = A

(A=26)*1.25 + (A=27)*2.5 + (A=31)*3.75 + (A=32)*5

Where am I going wrong? I'm unfamiliar with Numpy but from the examples I've found in the docs and online this logic seems right, but the process crashes immediately.

2

I tried it out following command:

gdal_calc.py -A raster_to_classify2.tif --calc "(A==26) * 1.25 + (A==27) * 2.5 + (A==31) * 3.75 + (A==32) * 5." --type Float32 --outfile raster_classified.tif

with my raster_to_classify2.tif (aleatory values 26, 27, 31, 32) and it worked.

enter image description here

2

You could also use gdal_reclassify as described here

python gdal_reclassify.py source_dataset.tif destination_dataset.tif -c "==26, ==27, ==31, ==32" -r "1.25, 2.5, 3.75, 5" -n true

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.