2

I am trying to do the following in Python 2.7:

  1. Clip all files in a geodatabase with a single layer (so a batch clip)
  2. Export the resulting clip layers (identified with _clip on the end of their names) to _ready layers, only pulling out features with a Shape_Area under 100,000
  3. Delete the _clip layers to clean up the GDB.

I am doing all of this within 2 File GDBs. I originally created a model in ArcMap 10.6 ModelBuilder to get the basis, then exported to Python and rewrote it so it can be used outside of a toolbox.

I find when I run the below code, it finishes doing the clip successfully (result can be seen in the GDB), then basically skips over the rest with no error or result.

I am very new to Python, so suspect I have missed a core principle. Maybe you cannot have 2 for loops defined like this. If I separate them and run as two different scripts each process works fine, which tells me the construct of each process is correct, but combining them in this way is not.

Can someone guide me as to what I am doing wrong here?

I have done much research on Google to no avail.

I have altered path and file names to generic ones.

#IMPORT MODULES
import os
import arcpy
#SET ENVIRONMENT
arcpy.env.workspace = "E:\\Folder\\GDB_Name.gdb"
arcpy.env.overwriteOutput = True
#SET VARIABLES
inputfc = arcpy.ListFeatureClasses()
clipExtent = "Database Connections\\My Connection.sde\\My Layer"
inputfc2 = arcpy.ListFeatureClasses("*.clip")
outLocation = "E:\\Folder\\Another GDB Name.gdb"
Delete_succeeded = "true"
#PROCESSES
#CLIP
for fc in inputfc:
 arcpy.Clip_analysis(fc, clipExtent,fc + "_clip")
#FC TO FC
for fc in inputfc2:
 arcpy.FeatureClassToFeatureClass_conversion(fc, outLocation, fc + "_ready","Shape_Area > 100000")
#DELETE CLIPS
for fc in inputfc2:
 arcpy.Delete_management(fc, "")
PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Nov 11, 2020 at 12:25
0

1 Answer 1

4

At the time of you listing features: inputfc2 = arcpy.ListFeatureClasses("*.clip"). They dont exist, you create them later. And shouldnt "*.clip" be "*_clip"? So feature class to feature class and delete will have nothing as input.

(Test it with print inputfc2)

Move the list line to after the clip.

answered Nov 11, 2020 at 12:33
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.