Select to view content in your preferred language

how to replace RasterCalculator with arcpy

622
2
Jump to solution
11-24-2013 01:00 AM
Gisbert61
Frequent Contributor
Hello, newbie here.

I'm combining two rasters into an output using the Rastercalculator tool and that work fine, got the tool into modelbuilder and that works great as well.
Now I need to do additional steps like looping through more files to repeat the process and prompting the user for some choices so I'm looking into python using arcpy to do the rastermath. I cannot find the syntax to do this:

[INDENT]arcpy.gp.RasterCalculator_sa("""(Int("2010cl3" / 10) * 10) + (Int("2013cl5" / 10))""","Y:/case13/first/scrap_db.gdb/outputras")[/INDENT]

in arcpy. I understand I should not use rastercalculator in python but instead use arcpy.sa, can someone give an example please?

Thanks in advance
0 Kudos
1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor
Hi Bert,

Try something like this:

import arcpy from arcpy.sa import *   # settings (paths to input and output data) rasname1 = "Y:/Path/To/Input/Data.gdb/2010cl3" # edit this rasname2 = "Y:/Path/To/Input/Data.gdb/2013cl5" # edit this rasnameout = "Y:/case13/first/scrap_db.gdb/outputras"   # grab a SA license if arcpy.CheckExtension("Spatial") == "Available":     arcpy.CheckOutExtension("Spatial") else:     exit("No SA license available...")   # make Raster objects for easy processing ras1 = arcpy.Raster(rasname1) ras2 = arcpy.Raster(rasname2)   # apply math rasout = (Int(ras1 / 10) * 10) + Int(ras2 / 10)   # save the result to disk rasout.save(rasnameout)

Kind regards,

Xander

View solution in original post

0 Kudos
2 Replies
XanderBakker
Esri Esteemed Contributor
Hi Bert,

Try something like this:

import arcpy from arcpy.sa import *   # settings (paths to input and output data) rasname1 = "Y:/Path/To/Input/Data.gdb/2010cl3" # edit this rasname2 = "Y:/Path/To/Input/Data.gdb/2013cl5" # edit this rasnameout = "Y:/case13/first/scrap_db.gdb/outputras"   # grab a SA license if arcpy.CheckExtension("Spatial") == "Available":     arcpy.CheckOutExtension("Spatial") else:     exit("No SA license available...")   # make Raster objects for easy processing ras1 = arcpy.Raster(rasname1) ras2 = arcpy.Raster(rasname2)   # apply math rasout = (Int(ras1 / 10) * 10) + Int(ras2 / 10)   # save the result to disk rasout.save(rasnameout)

Kind regards,

Xander
0 Kudos
Gisbert61
Frequent Contributor
Xander,

Got a result! thanks!
0 Kudos