0

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 1500x2400 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!

6
  • What prevents you from using these formulas in ArcPy? And how long is "way too long": on my machine, R has no problem processing grids this size and the conversion to float is instantaneous.
    – whuber
    Commented Nov 21, 2013 at 19:32
  • 1
    I forgot to add this line form the 10.1 manual: “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”. Maybe it does work well in R and I am unaware of the proper types of code to use (I've only done genetics in R, no GIS)... Just writing the file to .asc at the end took 4 minutes.
    – xoof
    Commented Nov 21, 2013 at 19:46
  • 3
    You can use the raster calculator, however, when working with rasters in python it is much easier to use raster objects and map algebra. Either way, your example code above is useful with raster calculator or map algebra. If your are looping, you will need to introduce a raster name variable.
    – Barbarossa
    Commented Nov 21, 2013 at 19:53
  • Four minutes for writing out that file is unusually long: there was some I/O problem with your system. But you don't want to use ASCII format, anyway: binary formats can reduce the I/O time by an order of magnitude. Using functions provided by the raster package I just wrote a 1500 by 2400 floating-point grid to disk in 2.4 seconds (which is still slow by most standards, but it's not 4 minutes!). This package provides in-RAM and multi-core functionality that could further speed the process.
    – whuber
    Commented Nov 21, 2013 at 21:04
  • @whuber Unfortunately, ascii is not optional for me, it is a prerequisite for the downstream applications of this data in Circuitscape as part of the full loop.
    – xoof
    Commented Nov 21, 2013 at 22:32

2 Answers 2

4

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.

1

I sounds like you really need to see how to run the equivalent of a Raster Calculator function in Python. Here are some examples:

euc_dist = arcpy.sa.EucDistance(extracted_ones)
max_elev = euc_dist.maximum
conv_to_hundred_con = arcpy.sa.Con(euc_dist, (euc_dist * (100/-max_elev)), 
                                   euc_dist, "VALUE > 0")
# Need to save the raster out?
conv_to_hundred_con.save(<raster on disk>)

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.