I want to clip multiple rasters to my study area, so I'm writing a script that's using the arcpy.Clip_management tool. However, the tool throws an 999999 error with no explanation when executing.
I suspect that I'm mucking up the syntax somehow since the tool runs fine when executed from the toolbox with the same inputs, but I can't figure out what I might be doing wrong.
Tool help for reference: http://desktop.arcgis.com/en/arcmap/latest/tools/data-management-toolbox/clip.htm
This is the script as is:
import arcpy, numpy arcpy.env.overwriteOutput = True try: # set workspace arcpy.env.workspace = r"C:\Users\Johnnie\Desktop\exarb\gis\pilotstudie" # set inputs inLocation = "in.gdb/" outLocation = "ut2.gdb/" studyArea = inLocation + "studieomrade" vectorInputs = ["by_get", "my_get", "vl_get"] rasterInputs = ["hojd2m3006_6589746_685960"] # process: clip all vector inputs to study area #for i in vectorInputs: #outName = i + "_clip" #arcpy.Clip_analysis(inLocation + i, inLocation + studyArea, outLocation + outName) # process: clip all raster inputs to study area for i in rasterInputs: outName = outLocation + i + "_clip" inName = inLocation + i arcpy.Clip_management(inName, "", outName, studyArea, "", "ClippingGeometry", "NO_MAINTAIN_EXTENT") except Exception as err: print err.args
This works with no problems for the commented out arcpy.Clip_analysis part.
This is what it looks like when I try to run the tool directly from the python console:
>>> arcpy.Clip_management("in.gdb/hojd2m3006_6589746_685960", "", "ut2.gdb/test2", "in.gdb/studieomrade", "", "ClippingGeometry", "NO_MAINTAIN_EXTENT") Runtime error Traceback (most recent call last): File "<string>", line 1, in <module> File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\management.py", line 13594, in Clip raise e ExecuteError: ERROR 999999: Error executing function. Failed to execute (Clip).
I've tried with both empty quotes and "#" for default values as in the help sections code examples, but seems to make no difference.
Running the tool from the toolbox with the same inputs works just fine.