Multiple clip using a feature class in a geodatabase

09-24-2015 03:10 PM
New Contributor

Hello everybody,I´m a student and new in python. As an excercise I have to create an script, which, using a feature class existing in a geodatabase, should clip other featureclasses existing in the same geodatabase (but not clipping itself) and add the prefix "NewFile" to the feature classes that were clipped, however, I arrive to some point where I´m lost and don´t know exactly how to finish the script, can somebody help me with that?

Thank you in advance!

import arcpy, os

from arcpy import env

arcpy.env.workspace = arcpy.GetParameterAsText(0)

clipFeatures = 'D:\\datosvalle\\Valle.mdb\\Santiago_de_cali'

outWorkspace = 'D:\\datosvalle\\Valle.mdb'

clusterTolerance = ""


    fcs = arcpy.ListFeatureClasses()

    for fc in fcs:

        featureClassName = arcpy.ValidateTableName("Newfile_"+fc, outWorkspace)

        outFeatureClass = os.path.join(outWorkspace, featureClassName)

        if fc <> os.path.basename (clipFeatures):

            arcpy.Clip_analysis(fc, clipFeatures, outFeatureClass, clusterTolerance)

except: arcpy.AddMessage(arcpy.GetMessages(2))

print "The files were correctly clipped"

Tags (2)
0 Kudos
3 Replies
Regular Contributor II

What are you having a problem with?

0 Kudos
MVP Esteemed Contributor

Welcome to the site.  It is preferable practice to indicate

  • what you have done,
  • the results of any script
    • did it fail? and if so what is the exact error message and a listing of thinputs to it
    • it worked, but you don't like it... changes you want

Your response suggests that you got lost somewhere...but the script looks not bad.  Did you get lost early on? if so how did you write the rest of the script?  So basically, as Freddie says...what's up? what happened or didn't?

Regular Contributor III

I think what you need to do is remove the clip fc from the list


0 Kudos