I have a float type raster file (an NDVI made from ERDAS IMAGINE) and would like to convert it to an interger type raster file in order to use Focal Statistics function (Majority). Is there any way to do this?
1Could you please supply more details on the raster? For example, how many bands? What information does the raster contain (e.g. elevation DEM)?– Aaron ♦Oct 7, 2014 at 2:35
Menno's answer will work but it will work but it will always round down. For example, 99.99999 becomes 99.
This function in the raster calculator or map algebra tool will do logical rounding.
Int(yourraster + 0.5)
This way 99.99999 becomes 100 and and 99.49999 becomes 99.
That's true, I should have mentioned that.– MennoOct 7, 2014 at 13:25
1It is still a solid answer. I often use INT as sometimes it just does not matter. Oct 7, 2014 at 13:46
1Thank you user two seven two three nine for this detailed information.– GloriaOct 8, 2014 at 3:51
@Gloria Remember to accept an answer if it answered your question. May 17, 2017 at 15:09
From the fact that you plan to use focal statistics I infer that you must be able to use the spatial analyst extension.
In the spatial analyst toolbox there is a tool Int in the Math toolset which converts a floating point raster to an integer raster.
You need to stretch the NDVI floating point values (-1 to 1) to 8-bit unsigned (0 - 255). If you convert the float to integer directly, the resulting raster will have only one integer value. You can stretch the values in the Raster Calculator using the following equation:
(NDVI - -1) * 255 / (1 - -1) + 0
I use raster calculator all the time for mapping riverine floodplains.
I found that when I turned a raster set into an integer raster set by using Int () in the raster calculator that I lost information.
In order to avoid the likelihood of this happening, I would advise to use Con () instead to convert all values to a single integer value of your choosing and then converting that product to a polygon using raster to polygon conversion.
I believe that Focal Statistics only works on an int() type raster. Is there a similar tool for con() types?– MaryBethNov 5, 2015 at 18:15
Int(yourraster + 0.5) in the Raster Calculator tool was what I needed.
As I just discovered, if the raster values are negative (for example a DEM below sea level), this method won't round the floats to the nearest integer.
-6.47 + 0.5 = -5.97 and will then truncate to
So for rasters with negative values, use
Int(yourraster - 0.5)
Might seem obvious, but took me more head scratching than I'd care to admit!