Weird File Path Returning from Print Statement Causing ERROR 000732

849
3
Jump to solution
04-08-2013 02:04 PM
MikeMacRae
Occasional Contributor III
0 down vote favorite


I have created a python script in ArcGIS 10.1. My first parameter type is a 'Feature Layer' set to as a multivalue input. I was running my script quite well off of data from one of my drives (my Y:drive), but then I tried use some data from another drive (my Z:drive) and am receiving an error:

ERROR 000732: Input Features: Dataset 'Z:\DATA FOR 2009\Base.gdb\CREEKS_UTM' does not exist or is not supported


I set a print message to print out the parameters for me and this is what i got:

Y:\2012_data\INFRASTRUCTURE.gdb\Buildings;'Z:\DATA FOR 2009\Base.gdb\CREEKS_UTM';'Z:\DATA FOR 2009\Base.gdb\LAKES_UTM'


The only anomaly I see is that the 2 feature classes from the Z:drive is being wrapped in single quotes when it returns the value, but the Y:drive doesn't. I have no idea why this is, but I'm thinking that is the issue I am having.

My script basically just reads in the parameters and clips to the extent of a raster file I have. The reason for the conditional statement in the loop is because the user may use a layer file from ArcMap or they may navigate to a feature class/shapefile and use that as an input. If they are using the layer in the map, then it reads it in as just the layer name. If they navigate, then the parameter reads the whole file path and name, so I need to parse it to use the base file name for the output parameter in the clip tool.

Any suggestions are welcome.

My script is as follows:
import arcpy, os  inLines = arcpy.GetParameterAsText(0) inRaster = arcpy.GetParameterAsText(1) outRaster = arcpy.GetParameterAsText(2)  pnt_array = arcpy.Array() extent = arcpy.Raster(inRaster).extent pnt_array.add(extent.lowerLeft) pnt_array.add(extent.lowerRight) pnt_array.add(extent.upperRight) pnt_array.add(extent.upperLeft)  poly = arcpy.Polygon(pnt_array)  for shp in inLines.split(';'):     arcpy.AddMessage(shp)     arcpy.AddMessage(os.path.isabs(shp))     if os.path.isabs(shp) == True:         arcpy.AddMessage('if')         (filename, ext) = os.path.splitext(os.path.basename(shp))          arcpy.Clip_analysis(shp, poly, outRaster + "\\" + str(filename) + "_Clip")              else:         arcpy.AddMessage('else')         arcpy.Clip_analysis(shp, poly, outRaster + "\\" + str(shp) + "_Clip")
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
ChrisFox3
Occasional Contributor III
That occurs when the path has a space in it for a multivalue parameter. You can safely remove the single quote using the strip function on the string. If the string doesn't begin or end with a single-quote then the code below will have no impact on the original string.

shpPath = shp.strip("'")

View solution in original post

0 Kudos
3 Replies
MathewCoyle
Frequent Contributor
They have quotes because you have spaces in your paths. You should generally try to avoid spaces or starting a directory with a numeral as both of those cases can cause issues when dealing with rasters.
0 Kudos
ChrisFox3
Occasional Contributor III
That occurs when the path has a space in it for a multivalue parameter. You can safely remove the single quote using the strip function on the string. If the string doesn't begin or end with a single-quote then the code below will have no impact on the original string.

shpPath = shp.strip("'")
0 Kudos
MikeMacRae
Occasional Contributor III
Thanks guys,

I managed to do something similar as to what Chris suggested by testing:

if os.path.isabs(shp[1:-1]) == True:


Which basically does the same thing as stripping the quotes. I definitely would have tried the stripping method had I not figured the other way out.
0 Kudos