2

I have written a script which is supposed to loop through all the rasters in a folder and perform a slope analysis on each raster and save the results in another folder.

I keep getting the following error:

< type 'exceptions.RuntimeError'>: ERROR 000875: Output raster: C:\Slope_Outputs\burd_25m_dem_slope's workspace is an invalid output workspace.

Here's my code:

class LicenseError(Exception):
    pass

# Set desktop license used to ArcView
#
import arcview
import arcpy
from arcpy import env

try:
    if arcpy.CheckExtension("Spatial") == "Available":
        arcpy.CheckOutExtension("Spatial")
    else:
        # Raise a custom exception
        raise LicenseError

except LicenseError:
    arcpy.AddMessage("Spatial Analyst license is unavailable")
except:
    print arcpy.GetMessages(2)

from arcpy.sa import *

originLocation = arcpy.GetParameterAsText(0)
slopeMeasurement = arcpy.GetParameterAsText(1)
destinationLocation = arcpy.GetParameterAsText(2)

arcpy.env.workspace = originLocation

rasterList = arcpy.ListRasters("*")

for raster in rasterList:
    finalDestination = destinationLocation+"\\"+raster+"_slope"
    arcpy.AddMessage(finalDestination)
    outSlope=arcpy.sa.Slope(raster, slopeMeasurement)
    arcpy.AddMessage(outSlope)
    outSlope.save(finalDestination)

I'm not really sure why I'm getting this error.

Any ideas?

4 Answers 4

4

I have found on this page that the maximum raster name length is 13 characters. I have modified my code to take the first 7 characters of the input raster name and add "_slope" at the end of it.

This works for now, but I think I will modify my code to write to a different file format instead of ESRI GRID or possibly a geodatabase instead.

2
  • someone told me before that, the file name length should be 8, 11 or 13. He was not sure. 11 length worked for me. So, I told you to keep the name length less or equal 11. thanks for sharing the link :)
    – Emi
    Jan 24, 2013 at 2:35
  • 3
    How about adding "_slope.tif" at the end? GeoTIFFs are fantastic, with no funny name length limitations.
    – Mike T
    Jan 24, 2013 at 3:37
3

try changing the workspace name to this C:\Slope_Outputs\burd_25m_dem_slopes. I think the problem might be that you are using unsupported characters in your workspace name. Maybe this post for ESRI will be helpful

1
  • There are no unsupported characters in the workspace name. The apostrophe after 'slope' was added by ArcGIS in displaying the error.
    – Fezter
    Jan 24, 2013 at 0:32
3

I am not sure about it. But Try those:

  1. Try change the drive.
  2. Try keep the raster name length less than or equal 11.
2

Perhaps the "\" is causing problems. Try the following:

import os # add this in with your other imports at top of code
finalDestination = destinationLocation + os.sep + raster + "_slope"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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