[GIS] How to reclassify an integer raster to a float raster

arcgis-10.1arcpy

I have been using various arcGIS tools to try and do this. Unfortunately, the reclassify tool in arcmap can only output integers. A cool workaround that I found is using the raster calculator in arcmap, as suggested by Jeff Evans in this post: http://forums.arcgis.com/threads/15396-Reclass-from-Integer-to-Floating-point

*"Here is an example using a 4 value integer (21, 41, 42, 43) raster that results in a float with the values of 1.0, 2.0, 3.0, 4.0:
Float(Con("nlcd" == 21, 1.0, Con("nlcd" == 41, 2.0, Con("nlcd" == 42, 3.0, Con("nlcd" == 43, 4.0, 0.0)))))
"*

This works like a charm and gives me the desired output…

HOWEVER, I cannot use this process in arcpy… Because I need to do many loops of this process, I need it to be its own python script and “The Raster Calculator tool is intended for use in the ArcGIS for Desktop application only as a GP tool dialog box or in ModelBuilder. It is not intended for use in scripting and is not available in the
ArcPy Spatial Analyst module”.

To be honest, I am starting to give up on using arcpy for this, does anyone out there know how to do this efficiently using arcpy? I also tried some R code but it took way too long (my grids are around 1500×2400 cells). I also tried a python reclass script my colleague he built scratch, and it also takes too much time.

Any ideas/suggestions?

Thanks for your time!

Best Answer

I don't understand why you cannot use raster calculator in a python script. I use raster calculator and map algebra interchangeably all of the time. Either way, the syntax you posted in your question will work with both methods. You just have to make your raster an object first and save afterward.

import arcpy
from arcpy.sa import *

nlcd = r"PATH TO RASTER"    # input raster
nlcd_object = Raster(nlcd)  # Make a raster object
output_path = r"PATH TO OUTPUT" 

# Calculate map algebra
nlcd_reclass = Float(Con(nlcd_object == 21, 1.0, Con(nlcd_object == 41, 2.0, Con(nlcd_object == 42, 3.0, Con(nlcd_object == 43, 4.0, 0.0)))))

# Save raster
nlcd_reclass.save(output_path)

I hope this helps.