Wednesday 28 March 2018

How to round pixel values of a raster in QGIS?


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.



Answer



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






No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...