4

I have a weird thing happening with my script. When I copy/paste it into the python cmd line within ArcMap, I get error messages. However, if I run the first part, then copy in the very last line by and run it by itself everything goes fine. Here's my code:

import os
import arcpy
from arcpy import env
from arcpy.sa import *

arcpy.env.workspace = r'H:\Arc'
#dem = r'C:\Users\Lucy\Documents\GISthings\DCEW_VegStatistics\miscrasters\bare1m_fl_int'
dem = r'H:\Arc\dem_coarseres'
# create and store aspect
outAspect = Aspect(dem)

'''set up vegetation rasters'''
pftVeg = r'H:\Arc\veg_4classes'
# raster of n and s aspects
veg_n = Con((outAspect < 45) | (outAspect > 315), pftVeg)
veg_s = Con((outAspect < 225) & (outAspect > 135), pftVeg)

''' buffer around weather stations '''
featureToBuffer = r'H:\Arc\DCEW_WS.shp' 
#outBuffer = r'C:\Users\Lucy\Documents\GISthings\DCEW_VegStatistics\bufferedWSveg.gdb\buff50m'
distanceField = "1000 meters"
# creates shapefile of buffers
# if you get an error here, try restarting computer to release schema lock
arcpy.Buffer_analysis(featureToBuffer, 'outBuffer', distanceField)

# Execute PolygonToRaster of buffers
valField = 'Field1'
assignmentType = "MAXIMUM_AREA"
priorityField = 'Field4'
cellSize = 0.00001  # 0.000001
arcpy.PolygonToRaster_conversion('outBuffer', valField, 'outRaster', assignmentType, priorityField, cellSize)
#outRaster = Lookup(Raster(outBuffer), 'Field1') #superfluous?

i = 4

# Process: Raster Calculator
arcpy.gp.RasterCalculator_sa("Con(\"outRaster\" == i,\"veg_s\")", 'temp_s')

The Raster calculator line is where everything gets fuzzy. My error message is this:

Runtime error Traceback (most recent call last): File "", line 39, in File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\geoprocessing_base.py", line 504, in return lambda *args: val(*gp_fixargs(args, True)) ExecuteError: ERROR 000539: Error running expression: rcexec() Traceback (most recent call last): File "", line 1, in File "", line 5, in rcexec File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\sa\Functions.py", line 255, in Con where_clause) File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\sa\Utils.py", line 53, in swapper result = wrapper(*args, **kwargs) File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\sa\Functions.py", line 239, in Wrapper ["IfThen", in_conditional_raster, in_true_raster_or_constant]) RuntimeError: ERROR 000732: Input Raster: Dataset veg_s does not exist or is not supported Failed to execute (RasterCalculator).

Does anyone know what could possibly be going on?

Edit in response to @FelixIP:

I'm using that syntax for my raster calculator because that's what model builder spit out for me. I'm still new to python, so I've been using it for training wheels. I tried your code with expr on one line and Rastercalculator on the other but I got the same error message. When I ran them by themselves everything worked perfectly. Does that make any sense? Ideally I'd like to put this within a for loop, so it would be good to not have to run it in two separate sections if possible.

closed as off-topic by PolyGeo Aug 29 '16 at 8:12

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions seeking help to debug/write/improve code must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Providing a clear problem statement and evidence of a code attempt will help others to help you. See: How to create a Minimal, Complete, and Verifiable example." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Why are you using Con at the start and acrpy.gp...("Con ..) at the end? – FelixIP Apr 22 '16 at 1:05
  • arcpy does not understand string in last line. Try expr=r'Con("Outraster"==%i,"veg_s")'%i first and arcpy.gp.Rastercalculator(expr) – FelixIP Apr 22 '16 at 1:13