I am Having Issues with ERROR 000732

2569
4
Jump to solution
02-24-2016 10:10 AM
WinnMcEnery3
New Contributor

I am attempting to run a nested for loop to clip habitat types by Marine Protected Area (MPA) region offshore California.   When running the code below I receive error 000732 (red text).  Any help is greatly appreciated.

  File "C:\Python27\ArcGIS10.3\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 326, in RunScript

    exec codeObject in __main__.__dict__

  File "E:\BlueCarbon\GIS\Script\MPARegionClip.py", line 19, in <module>

    arcpy.Clip_analysis(fc, reg, op_FC)

  File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\analysis.py", line 56, in Clip

    raise e

ExecuteError: Failed to execute. Parameters are not valid.

ERROR 000732: Clip Features: Dataset CentralCoastProj.shp does not exist or is not supported

Failed to execute (Clip).

CODE:

import arcpy

from arcpy import env

#Set Variables

hab_Workspace = "E:\\BlueCarbon\\GIS\\Workspace\\habproj "

regWorkspace = "E:\\BlueCarbon\\GIS\\Workspace\\IndRegProj\\"

tWorkspace = "E:\\BlueCarbon\\GIS\\Workspace\\habproj_regions"

env.workspace = regWorkspace

region = arcpy.ListFeatureClasses("")

env.workspace = hab_Workspace

FClist = arcpy.ListFeatureClasses("")

print FClist

for fc in FClist:

    for reg in region:

        op_FC = tWorkspace + "\\" + fc + reg

        arcpy.Clip_analysis(fc, reg, op_FC)

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
DarrenWiens2
MVP Honored Contributor

You're running into issues because you can only have one workspace environment at a time. You set the workspace to the region folder. The region list is populated with the names (not full paths) of the feature classes in the region workspace folder. Then, you switch the workspace to the hab workspace folder. The FClist is populated with feature class names (not full paths) of the feature classes in the hab workspace folder. Your loops cycle through the feature class names (not full paths) in your lists. Finally, your clip tool is run against two feature class names (not full paths). Since the tool is provided with feature class names (not full paths) it looks for feature classes in the workspace environment folder - your hab folder.

The most direct route I see to a solution is to store the full path in your lists, some thing like:

>>> import os
... arcpy.env.workspace = r'C:\junk'
... region = [os.path.join(arcpy.env.workspace,fc) for fc in arcpy.ListFeatureClasses("")]

View solution in original post

4 Replies
MichaelVolz
Esteemed Contributor

I would put some print statements in to validate that the paths to your input and output data are correct.  That usually slips me up at first when creating new python scripts.

0 Kudos
DanPatterson_Retired
MVP Emeritus

I would agree with Michael, by the looks of it the shapefile at least can't be found.  You may want to verify all the files used in the clip using Exists—Help | ArcGIS for Desktop prior to

Clip—Help | ArcGIS for Desktop

0 Kudos
DarrenWiens2
MVP Honored Contributor

You're running into issues because you can only have one workspace environment at a time. You set the workspace to the region folder. The region list is populated with the names (not full paths) of the feature classes in the region workspace folder. Then, you switch the workspace to the hab workspace folder. The FClist is populated with feature class names (not full paths) of the feature classes in the hab workspace folder. Your loops cycle through the feature class names (not full paths) in your lists. Finally, your clip tool is run against two feature class names (not full paths). Since the tool is provided with feature class names (not full paths) it looks for feature classes in the workspace environment folder - your hab folder.

The most direct route I see to a solution is to store the full path in your lists, some thing like:

>>> import os
... arcpy.env.workspace = r'C:\junk'
... region = [os.path.join(arcpy.env.workspace,fc) for fc in arcpy.ListFeatureClasses("")]
WinnMcEnery3
New Contributor

Wow that makes complete sense and thanks for your help!

0 Kudos