I want to use arcpy raster calculation to create some script but the output raster to get from this arcpy raster calculation script is different from this to take from model builder in ArcGIS gui,any idea why ?

arcpy script :

arcpy.gp.RasterCalculator_sa(con, rstercalc)

raster calculation in model builder :


my raster is float if I try to use float(raster1) I take error :

float cannot convert in memory layer

I have some wrong in con in script or the wrong is the in_memory layer where I use ?


The Raster Calculator help page says:

The Raster Calculator tool is intended for use in the application only as a GP tool dialog box or in ModelBuilder. It is not intended for use in scripting.

You could use the Con tool if you want to calculate a conditional value (as your variable name implies).

If you just want to multiply 3 rasters, Times is more appropriate. See the code samples at the bottom of the page to fix your code. You will need to run Times twice (first raster1 * raster2, then result * raster3).

Times is the geoprocessing/scripting equivalent of the Map Algebra * operator.

  • thank you for help,but hiw can use con for this raster calculation? – Mar Jan 12 '18 at 15:35

In your example image, you do not even have a con statement. It is a straight multiplication.... if you need to turn this into a Con statement, this will give you a backbone to work with as well... try:

import arcpy, os
from arcpy.sa import *

raster1 = r'c:\temp\ras1'
raster2 = r'c:\temp\ras2'
raster3 = r'c:\temp\ras3'
arcpy.env.workspace = r'c:\temp'

raster = Raster(raster1) * Raster(raster2) * Raster(raster3)
  • I need to import this from ` arcgisscripting import Raster` because don't recognizes Raster in raster = Raster(raster1) * Raster(raster2) * Raster(raster3) – Mar Jan 26 '18 at 21:03
  • and after this calculation I take new raster with 0 values why ? – Mar Jan 27 '18 at 21:36
  • AS per your first comment, I didn't need any additoinal imports to make my example work. It sounds like you got it working though, so I will ignore. As per your second comment, this will depend on what you have as inputs. If one of the inputs is a raster of 0's then you will get zeros. If you are multiplying a float raster by an integer raster you may will likely need to put a Raster(float(raster2)) in order to make your INT raster work with a FLOAT raster – D_C Jan 29 '18 at 15:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.