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?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Jan 23, 2013 at 7:00

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.

answered Jan 24, 2013 at 0:48
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 :) Commented Jan 24, 2013 at 2:35
  • 3
    How about adding "_slope.tif" at the end? GeoTIFFs are fantastic, with no funny name length limitations. Commented 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

answered Jan 23, 2013 at 7:07
1
  • There are no unsupported characters in the workspace name. The apostrophe after 'slope' was added by ArcGIS in displaying the error. Commented 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.
answered Jan 23, 2013 at 9:13
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"
answered Jan 24, 2013 at 21:11

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.