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
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.
-
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– Emi2013年01月24日 02:35:23 +00:00Commented Jan 24, 2013 at 2:35
-
3How about adding
"_slope.tif"
at the end? GeoTIFFs are fantastic, with no funny name length limitations.Mike T– Mike T2013年01月24日 03:37:01 +00:00Commented Jan 24, 2013 at 3:37
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
-
There are no unsupported characters in the workspace name. The apostrophe after 'slope' was added by ArcGIS in displaying the error.Fezter– Fezter2013年01月24日 00:32:51 +00:00Commented Jan 24, 2013 at 0:32
I am not sure about it. But Try those:
- Try change the drive.
- Try keep the raster name length less than or equal 11.
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"
Explore related questions
See similar questions with these tags.