Clipping multiple feature classes from one input feature.

11-02-2020 03:34 PM
New Contributor III

I am trying to get this code to work.

What is does is the user assigns a shape or feature class to clip sever pre-defined layers, and rename those layers according to the listed layers.  Such as clip the layers from area of Interest (AOI) and rename them in the new geodatabase as per the original name in the list. 

I keep getting an error such as: 

ERROR 000210: Cannot create output \\Workspace\\scripts\P_2020\Data\P_Data\P_Data\bctsdata
Failed to execute (Clip).

Traceback Info:
File "\\Workspace\P_2020\scripts\", line 143, in <module>

Error Info:
<class 'arcgisscripting.ExecuteError'>: ERROR 000210: Cannot create output \\Workspace\scripts\P_2020\Data\P_Data\MTAP_Data\data
Failed to execute (Clip).

Here is my code. Thank you in advance:

#---------------------------MTAP Script Main Body ------------------------------
#======================= GDB and Folder Set Up (STEP 1)========================#
# Seting up folder path peramters from ArcGIs Tool Box
FolderPath = arcpy.GetParameterAsText(4)

# Naming the Geodatabase for the user.
WorkGDB = "MTAP_Data"

# Ensureing if re-run that the output can be over written
arcpy.env.overwriteOutput = True

# Create the new file geodatabase and or over write if there is one in place already
arcpy.CreateFileGDB_management(FolderPath, WorkGDB)

# Set the working enviroment for MTAP Project
tempdata = os.path.join(FolderPath, WorkGDB)

# make sure gdb does not already exist
if arcpy.Exists(tempdata):
arcpy.env.workspace = tempdata
# Create the new file geodatabase and or over write if there is one in place already
arcpy.CreateFileGDB_management(FolderPath, WorkGDB, 'CURRENT')
arcpy.env.workspace = tempdata

# set up outputwork space outWS
outWS = tempdata

# Send Arcpy message to verify workspace has been set.
arcpy.AddMessage("Workspace has been set to: " + str(arcpy.env.workspace) + '\n')

# Message for tool box outputs - shows location of folder to user
arcpy.AddMessage("Geodatabase has been created here:" + FolderPath + '\n')

# ============ End of Geodatabase and folder creation (STEP 1) =============== #

# ========= Gather Global base data and Clip to user areas (STEP 2) ========== #

# set constant vaiblaes for layers for data prep:
clip_lyr = 'Clip_area_lyr'

# Global varibles for MTAP operations ---------

FC1 = r'\\Data\Data.gdb\AREA_R'
FC2 = r'\\Data\Data.gdb\Net_Downs_G'
FC3 = r'\\\Data\Data.gdb\TAM_G'
FC4 = r'\\Data\Data.gdb\Woodshed_LU'
FC5 = r'\\Data\Data.gdb\TRIM750M'

FCList = [FC1, FC2, FC3, FC4, FC5]

# ------USER DEFINED VAIBLES --------------------------------------------------#
# AOI (Area of interest for clipping data from
clipInput = arcpy.GetParameterAsText(5)

# Query if needed for selecting from AOI
query = arcpy.GetParameterAsText(6)
# -----------------------------------------------------------------------------#

# ensure Clip layer does not already exist in the geodatabase.
if arcpy.Exists(clip_lyr):

# make new layer the selected feature to clip from ( user input clipInput to make Clip_Lyr)
arcpy.MakeFeatureLayer_management(clipInput, clip_lyr, query)
result = int(arcpy.GetCount_management(clip_lyr).getOutput(0))

# loop through multiple feature classes and clip
for fc in FCList:
clipfc = os.path.join(outWS,WorkGDB, os.path.basename(fc.split('.')[0]))
arcpy.AddMessage('Clipped: ' + os.path.basename(fc))

arcpy.AddMessage("! Script Completed !" + '\n')
print( "! Script completed !" + '\n')


tb = sys.exc_info()[2]
tbinfo = traceback.format_tb(tb)[0]
pymsg = "PYTHON ERRORS:\nTraceback Info:\n" + tbinfo + "\nError Info:\n " +\
str(sys.exc_type) + ": " + str(sys.exc_value) + "\n"
msgs = "ARCPY ERRORS:\n" + arcpy.GetMessages(2) + "\n"


print msgs
print pymsg

print arcpy.GetMessages(1)

Tags (2)
0 Kudos
1 Reply
by Anonymous User
Not applicable

Hi Andrew,

I'd suggest adding the '.gdb' extension to your variable denoting the file geodatabase you create a few lines later.


WorkGDB = "MTAP_Data.gdb"


I'm only saying this because the doc relating to CreateFileGDB mentions this file extension in the examples.

Also, you point to a new variable 


outWS = tempdata


outWS, which is a path concatenation of the folder and file gdb.

There seems to be a double up/clash here where the paths to the fileGDB are joined (outWS is already a path to the workGDB so maybe remove the second param 'workGDB' below?


clipfc = os.path.join(outWS,WorkGDB, os.path.basename(fc.split('.')[0]))



It's really helpful to run each tool you use to build your script in arcPro on some data and copy the python snippet from the result, pasting it into your IDE. That way you see what syntax arcpy 'likes' and then structure your params similarly.


Good luck.

Tags (1)