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, "")
0
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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.