I am getting a not executed error for a raster calculator. Here is part of the output:

File "C:\projectTemp\FloodAnalysis\floodxsectionanalysis.py", line 107, in makeSeemless arcpy.gp.RasterCalculator_sa(Con(IsNull(rasterIn), FocalStatistics(rasterIn,NbrRectangle(3, 3), "MEAN"), rasterIn), "{0}yrSeemless.img".format(increment)) File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\geoprocessing_base.py", line 498, in return lambda *args: val(*gp_fixargs(args, True)) arcgisscripting.ExecuteError: ERROR 000539: Parsing error SyntaxError: invalid syntax (line 5) Failed to execute (RasterCalculator).

This code I have setup to put into this calculator is:

def makeSeemless(outputPath, increment, rasterIn):
    arcpy.gp.RasterCalculator_sa(Con(IsNull(rasterIn), FocalStatistics(rasterIn,NbrRectangle(3, 3), "MEAN"), rasterIn), "{0}yrSeemless.img".format(increment))

1 Answer 1


From the ArcGIS Help:

Note: 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.

That said, you can use it with arcpy.gp.RasterCalculator_sa, but you need to pass it a string expression, i.e. arcpy.gp.RasterCalculator_sa('Con(IsNull("somerasterlayer"), etc...)')

As suggested by @radouxju, you're better off using the map algebra syntax instead:

import arcview,arcpy
from arcpy.sa import *
rasterIn=Raster('path to raster')
rasterOut=Con(IsNull(rasterIn), FocalStatistics(rasterIn,NbrRectangle(3, 3), "MEAN"), rasterIn)

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.