9

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?

1
  • 1
    Could you please supply more details on the raster? For example, how many bands? What information does the raster contain (e.g. elevation DEM)?
    – Aaron
    Commented Oct 7, 2014 at 2:35

5 Answers 5

13

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.

4
  • That's true, I should have mentioned that.
    – Menno
    Commented Oct 7, 2014 at 13:25
  • 1
    It is still a solid answer. I often use INT as sometimes it just does not matter. Commented Oct 7, 2014 at 13:46
  • 1
    Thank you user two seven two three nine for this detailed information.
    – Gloria
    Commented Oct 8, 2014 at 3:51
  • @Gloria Remember to accept an answer if it answered your question. Commented May 17, 2017 at 15:09
4

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.

0
2

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
1

Using 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.

For example -6.47 + 0.5 = -5.97 and will then truncate to -5.

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!

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.

1
  • I believe that Focal Statistics only works on an int() type raster. Is there a similar tool for con() types?
    – MaryBeth
    Commented Nov 5, 2015 at 18:15

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.