This is my first attempt at a complex stand alone python code. I am self teaching the arcpy module, well at least attempting to.

I am having a great deal of difficulty getting my site suitability analysis code to run. It consistently crashes at the raster calculator step. I understand that the raster calculator tool is difficult to manage in arcpy, however I am equally unfamiliar with the method using map algebra.

The outputs/inputs are rasters. Everything is converted to rasters in prior steps. I get an error code: 000989 Python Syntax error: parsing error invalid syntax, referencing the line of code for raster calculator.

My code is included below. Can someone help me with a workaround for this issue?

# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# Megan E Brown
# ModelCode.py
# Created on: 2014-04-21 23:51:03.00000
#   (generated by ArcGIS/ModelBuilder)
# Usage: ModelCode <Scratch_Workspace> <Trails> <Trail_Proximity> <DEM> <Min_Elevation__m_> <Max_Slope____> <Final_raster> 
# ---------------------------------------------------------------------------

# Import arcpy module
import arcpy, arcview
#from arcpy.sa import *
#env.workspace = "C:\\temp"

# Check out any necessary licenses

# Script arguments
Scratch_Workspace = arcpy.GetParameterAsText(0)
if Scratch_Workspace == '#' or not Scratch_Workspace:
    Scratch_Workspace = "C:\\temp" # provide a default value if unspecified

Trails = arcpy.GetParameterAsText(1)
if Trails == '#' or not Trails:
    Trails = "Z:\\GIS500\\FinalProject\\FPData\\WELP_trails.shp" # provide a default value if unspecified

Trail_Proximity = arcpy.GetParameterAsText(2)
if Trail_Proximity == '#' or not Trail_Proximity:
    Trail_Proximity = "200 Feet" # provide a default value if unspecified

DEM = arcpy.GetParameterAsText(3)
if DEM == '#' or not DEM:
    DEM = "Z:\\GIS500\\ned\\ned" # provide a default value if unspecified

Min_Elevation__m_ = arcpy.GetParameterAsText(4)
if Min_Elevation__m_ == '#' or not Min_Elevation__m_:
    Min_Elevation__m_ = "170" # provide a default value if unspecified

Max_Slope____ = arcpy.GetParameterAsText(5)
if Max_Slope____ == '#' or not Max_Slope____:
    Max_Slope____ = "10" # provide a default value if unspecified

Final_raster = arcpy.GetParameterAsText(6)
if Final_raster == '#' or not Final_raster:
    Final_raster = "Z:\\GIS500\\FinalProject\\FPData\\tempdata\\yay" # provide a default value if unspecified

# Local variables:
Percent_Slope = "C:\\temp\\Percent_Slope"            #slope output
Slope_LE = "C:\\temp\\Slope_LE"                      #"output of less than equal"
Calc = "C:\\temp\\Calc"                              #output from raster calculator, input to final step Equal to
Elevation_GE = "C:\\temp\\Elevation_GE"              #"greater than equal output"
Buff = "C:\\temp\\Buff"                              #"output of buffer"
buffer_raster = "C:\\temp\\buffer_raster"            #"output of feature to raster making buffer into polys"
Near_trails = "C:\\temp\\Near_trails"                #"output from not equal reclassing the buffer raster for raster calculation"
Cell_size_30m = 30
Value_0 = "0"
Value3 = "3"

# Process: Slope
arcpy.Slope_3d(DEM, Percent_Slope, "PERCENT_RISE", "9.0021749575298E-06")

# Process: Less Than Equal
arcpy.gp.LessThanEqual_sa(Percent_Slope, Max_Slope____, Slope_LE)

# Process: Greater Than Equal
arcpy.gp.GreaterThanEqual_sa(DEM, Min_Elevation__m_, Elevation_GE)

# Process: Buffer
arcpy.Buffer_analysis(Trails, Buff, Trail_Proximity, "FULL", "ROUND", "NONE", "")

# Process: Feature to Raster
arcpy.FeatureToRaster_conversion(Buff + ".shp", "FID", buffer_raster, Cell_size_30m)

# Process: Not Equal
arcpy.gp.NotEqual_sa(buffer_raster, Value_0, Near_trails)

# Process: Raster Calculator
arcpy.gp.RasterCalculator_sa(((Slope_LE) + (Elevation_GE) + (Near_trails)), Calc)

# Process: Equal To
arcpy.gp.EqualTo_sa(Calc, Value3, Final_raster)
  • 2
    Are you really trying to apply the Raster Calculator to shapefile data that have nothing at all to do with any of the previous calculations? Perhaps you could describe your model so that people will know what it is intended to do.
    – whuber
    Apr 28, 2014 at 22:01
  • Its a site suitability analysis. The proccessed outputs of the previous tools go into this as the inputs, aka the slope, minimum elevation, and buffer rasters, to produce a binary output based on input criteria showing cells that meet the criterion. They are all raster files by the time they get to that stage in the process.
    – Megan
    Apr 28, 2014 at 22:21
  • I don't understand your accusation that it makes use of none of the previous calculations.
    – Megan
    Apr 28, 2014 at 22:30
  • 2
    I apologize, Megan, because any rudeness was completely unintentional: the abbreviated form of communication forced upon us by the limited comment space makes it essential to be terse. I only wanted to direct your attention to the fact that your original call to the raster calculation (before your edit) explicitly attempted to process shapefiles, not rasters, and those shapefiles (by their very nature) could not have been produced by any of your previous calculations. I was hoping this would help you quickly identify and fix your problem without having to wait for a more extended answer.
    – whuber
    Apr 28, 2014 at 22:33
  • 1
    I see someone has voted to close this question. That is probably because it seems to be missing essential information, such as specific error codes. I also see you have been attempting to fill us in, at this very moment, with such information in a comment. Would you kindly instead edit the question itself to include that information? I think that would head off any more close votes and enable your readers to provide specific, useful suggestions. As far as syntax errors go, might I suggest you print out the first argument to RasterCalculator_sa? It will be very revealing.
    – whuber
    Apr 28, 2014 at 22:39

2 Answers 2


Just looking around for an answer to this and I've found the following: On this answer to a previous post, Luke indicates that from the ArcGIS Help:

The Raster Calculator tool is intended for use in the ArcGIS 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.

As an alternative to the Raster Calculator, you might need to investigate using the Math Toolset. Specifically, the Plus tool to do what you want.

I haven't tried this, but it looks like it might do what you want. Note, the Math Tools take two inputs, so you might need to create a temporary file. Something similar to this:

from arcpy.sa import *

PlusTemp = Plus(Slope_LE, Elevation_GE)
Calc = Plus(PlusTemp, Near_trails)
  • Thanks so much, with that to start with I was able to save out calc and get the program to finish.
    – Megan
    Apr 29, 2014 at 2:48

I am using ArcGIS 10.3.1 and ran into same problem. When I export the Result of Raster calculator, I have found out that it uses arcpy.gp's RasterCalculator_sa package.

For example, this,

arcpy.gp.RasterCalculator_sa("""Con(IsNull("{0}"),Int(Filter("{0}","LOW","DATA")),"{0}")""".format(nullified), output),

uses a Con operator to apply Filter tool to NODATA values. It bases on a SLC OFF Landsat 7 imagery in the map document assigned to nullified variable (its purpose is to iteratively destripe imagery).

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.