Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

Thanks.

share|improve this question

4 Answers 4

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

share|improve this answer
    
There are no unsupported characters in the workspace name. The apostrophe after 'slope' was added by ArcGIS in displaying the error. –  Fezter Jan 24 '13 at 0:32

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.
share|improve this answer
up vote 3 down vote accepted

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.

share|improve this answer
    
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 '13 at 2:35
2  
How about adding "_slope.tif" at the end? GeoTIFFs are fantastic, with no funny name length limitations. –  Mike T Jan 24 '13 at 3:37

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"
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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