3

I have a raster with float number values for example: 2.544459104537964 and I want to round these up to integers. I have seen other posts on ArcGIS like this one but when I use Raster Calculator in QGIS, Int(myraster + 0.5) only makes the first value (which is 0) to 0,5 and the last one (which is 100) to 100,5. The other pixels stay float.

13

This is a bit of a hack but it works: The QGIS raster calculator does not support rounding as far as I know but you can use GDAL to perform float to int type conversions.

  1. Raster -> Conversion -> Translate

    • change the datatype from float to int by using the -ot option

    • gdal_translate -of GTiff -ot Int32 E:/float.tif E:/int.tif

  • OMG this worked perfectly! Values such as 3,391823765 are now 3 and values like 5,912735176253 are now 6! thank you so so so much – Stelios M May 8 '15 at 18:03
  • Wait, so it doesn't allways round down? Am I missing something in the documentation here? – Kersten May 8 '15 at 19:21
  • To me it rounds them up as it should: 0,5 and above decimal becomes 1 and 0,4 and below becomes 0! And actually, after that I wanted the image to be grayscale. At first I typed -ot Int32 as you said, but then I had issues with the image in image processing software like Gimp. It showed as a 1 band RGBA. So I searched the documentation and I tried -ot Byte. Then it worked like a charm. Thanks again for this! – Stelios M May 8 '15 at 19:36
  • Perfectly! I have already read many answers and no one did correctly operation. Thank you. – Diogo Caribé Jul 15 '15 at 0:40
  • odd that QGIS doesnt have that option in the dialog box – chrismarx Dec 14 '16 at 15:49

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.