1

I've created a symbology layer that I want to apply to my output raster. I tried the following code:

FINAL_RESULTS = os.path.join(config.RASTER_FINAL_RESULT_FOLDER,"ThresholdResults_Day_{0}.tif".format(yesterdaysJulianDate))
combineResults(intermediateResultRasters, FINAL_RESULTS)
print "Processing Finished"

# Add Symbology from template layer
Symbology_lyr = "C:\\Users\\uma.bhandaram\\Desktop\\Threshold\\thresholdcalculation\\resources\\    Symbology.lyr"
arcpy.ApplySymbologyFromLayer_management(FINAL_RESULTS, Symbology_lyr)
print "Symbology Applied"

I run into the following error:

Traceback (most recent call last):
File "C:\Python27\ArcGIS10.4\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 326, in RunScript
exec codeObject in __main__.__dict__
  File "C:\Users\uma.bhandaram\Desktop\Threshold\thresholdcalculation\thresholdCalculation\calculateYesterdaysThreshold.py", line 73, in <module>
arcpy.ApplySymbologyFromLayer_management(FINAL_RESULTS, Symbology_lyr)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.4\ArcPy\arcpy\management.py", line 6438, in ApplySymbologyFromLayer
raise e
 ExecuteError: Failed to execute. Parameters are not valid.

 ERROR 000732: Input Layer: Dataset  C:\Users\uma.bhandaram\Desktop\Threshold\thresholdcalculation\thresholdCalculation\..\resources\output\results\ThresholdResults_Day_31.tif does not exist or is not supported
 Failed to execute (ApplySymbologyFromLayer).

The output raster is created and exists so I'm not sure why the error says otherwise?

Here's the full code: import datetime import arcpy, config import os, ntpath, sys from arcpy.sa import *

if arcpy.CheckExtension("Spatial") == "Available":
    arcpy.AddMessage("Checking out Spatial")
    arcpy.CheckOutExtension("Spatial")
else:
    arcpy.AddError("Unable to get spatial analyst extension")
    sys.exit(0)


def dateToJulianDay(date):
    """Returns the Julian day number of a date."""
    return date.timetuple().tm_yday


def getFiles(day):
     DAY_MIN_RASTER = 'Obs_Min_2017_{0}.tif'.format(day)
     DAY_MAX_RASTER = 'Obs_Max_2017_{0}.tif'.format(day)
    return os.path.join(config.INPUT_DAILY_RASTER_MAX_LOC, DAY_MAX_RASTER), \
       os.path.join(config.INPUT_DAILY_RASTER_MIN_LOC, DAY_MIN_RASTER)


def createRasterBasedOnValue(raster, trueValue, falseValue, conditional,    outputLocation, ):
    conRaster = Con(raster, trueValue, falseValue, conditional)
    conRaster.save(outputLocation)


def combineResults(rasterList, output):
    outCellStats = CellStatistics(rasterList, "SUM", "DATA")
    outCellStats.save(output) 


yesterdaysJulianDate = dateToJulianDay(datetime.datetime.today()) - 1
print "Process started for day {0}".format(yesterdaysJulianDate)

maxRastFile, minRastFile = getFiles(str(yesterdaysJulianDate).zfill(3))
MinRaster = Raster(minRastFile)
MaxRaster = Raster(maxRastFile)

intermediateResultRasters = []
TO_APPEND_TO_RESULT = yesterdaysJulianDate

RESULT_X32 = os.path.join(config.RASTER_INTERMEDIATE_RESULT_OUTPUT_FOLDER,
                         "ConLess32_{0}.tif".format(ntpath.basename(minRastFile)))

createRasterBasedOnValue(MinRaster, 0, 5, "\"VALUE\" < 32", RESULT_X32)
intermediateResultRasters.append(RESULT_X32)

RESULT_X45 = os.path.join(config.RASTER_INTERMEDIATE_RESULT_OUTPUT_FOLDER,
                      "ConLess45_{0}".format(ntpath.basename(minRastFile)))
createRasterBasedOnValue(MaxRaster, 10, 15, "\"VALUE\" < 45",RESULT_X45)
intermediateResultRasters.append(RESULT_X45)

RESULT_X85 = os.path.join(config.RASTER_INTERMEDIATE_RESULT_OUTPUT_FOLDER,
                      "ConLess85_{0}".format(ntpath.basename(maxRastFile)))
createRasterBasedOnValue(MaxRaster, 20, 25, "\"VALUE\" < 85", RESULT_X85)
intermediateResultRasters.append(RESULT_X85)

RESULT_X95 = os.path.join(config.RASTER_INTERMEDIATE_RESULT_OUTPUT_FOLDER,
                      "ConLess95_{0}".format(ntpath.basename(maxRastFile)))
createRasterBasedOnValue(MaxRaster, 30, 0, "\"VALUE\" < 95", RESULT_X95)
intermediateResultRasters.append(RESULT_X95)
FINAL_RESULTS = os.path.join(config.RASTER_FINAL_RESULT_FOLDER,
                           "ThresholdResults_Day_{0}.tif".format(yesterdaysJulianDate))
combineResults(intermediateResultRasters, FINAL_RESULTS)
print "Processing Finished"

# Add Symbology from template layer
Symbology_lyr = "C:\\Users\\uma.bhandaram\\Desktop\\Threshold\\thresholdcalculation\\resources\\ Symbology.lyr"
 arcpy.ApplySymbologyFromLayer_management(FINAL_RESULTS, Symbology_lyr)
 print "Symbology Applied"
  • What happens when you run the precise code snippet that you have presented? i.e. what is the error message including line number from that rather than the one from running your whole code? – PolyGeo Feb 1 '17 at 22:01

Your Answer

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

Browse other questions tagged or ask your own question.