0

I am trying to Clip several in_features with several clip_features and name the output using the name of the clip features.

Till now i made it with a loop for many in_features but only one clip_feature. I used a for loop. But now i have no idea, how to that with several clip_features...

That's my code:

import arcpy
import os
arcpy.env.workspace = "path of in_features"
out_clipped_Objects = "path of output"
clip_fc = "path of clip_features"

fcs = arcpy.ListFeatureClasses()

for fc in fcs:
     arcpy.Clip_analysis(fc, clip_fc, os.path.join(out_clipped_Objects, fc)+ "name of clip_feature")

Does somebody know how to alter the code, to do the clip_analysis with more then one clip_feature?

  • 2
    Welcome to GIS SE. As a new user, please take the Tour. The Clip documentation doesn't show any option for an array of parameters in either in_features or clip_features so I don't think this is possible, If you think about the topological processing involved, it doesn't make sense to have multiple sources with only one output, and with multiple outputs, you might as well just run multiple single-input, single-output processes. – Vince Oct 17 '18 at 12:42
1

If all your clip feature classes are the same geometry type (point, polyline, polygon) you can merge all of them into a single feature class before your clip:

import arcpy
import os
arcpy.env.workspace = "path of in_features"
out_clipped_Objects = "path of output"
clip_fcs = ["list", "of", "clip", "featuresclasses"]

#merge all clip feature classes into one feature class
mergeFc = os.path.join (out_clipped_Objects, "merge")
arcpy.Merge_management (clip_fcs, mergeFc)

fcs = arcpy.ListFeatureClasses()

for fc in fcs:
     arcpy.Clip_analysis(fc, mergeFc, os.path.join(out_clipped_Objects, fc)+ "name of clip_feature")

If all your clip feature classes are not the same geometry type you'll need to iterate through each clip feature class and clip, using the previous iteration's clip result as your input.

import arcpy
import os
arcpy.env.workspace = "path of in_features"
out_clipped_Objects = "path of output"
clip_fcs = ["list", "of", "clip", "featuresclasses"]

fcs = arcpy.ListFeatureClasses()

for fc in fcs:
    q = 0
    for clip_fc in clip_fcs:
        q += 1
        try: last_clip_fc
        except NameError: last_clip_fc = fc
        out_clip_fc = os.path.join(out_clipped_Objects, fc)+ "name of clip_feature_{}".format (q)
        arcpy.Clip_analysis(last_clip_fc, clip_fc, out_clip_fc)
        last_clip_fc = out_clip_fc
    print "clipped feature class for {}:".format (fc)
    print last_clip_fc
    del last_clip_fc

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.