How to Clip line features from multiple polygon feature class

5844
5
05-27-2016 12:05 AM
SadanandacharB1
New Contributor III

Hi All,

         I am new to arcgis python,  i am in learning stage, i have one taluk boundary feature  class which has 200 polygon features. And i have line feature class with 2500 features.

    My question is how do i clip these line feature class one by one using python script?

For example i have to take one taluk boundary and clip it and display the message "This is the taluk for this line feature" like this. Please help me

Thank You

0 Kudos
5 Replies
NeilAyres
MVP Frequent Contributor

You could use existing tools...

Union or intersect your polygons to the lines then use the Split tool (Analysis toolbox).

Or you could use python the read each poly geometry and clip the lines each time.

something like this :

with arcpy.da.SearchCursor(polyFc, ["SHAPE@"]) as Cur:
    for row in Cur:
        pGeom = row[0]
        arcpy.Clip_analysis(lineFc, pGeom, output)
        etc.....

You will need to setvariables polyFc & lineFc to points to some data. And set output.

SadanandacharB1
New Contributor III

Hi,

I tried as per your suggestion, but i am not getting,

Bellow is my polygon features and line featuresRoads.jpg

Taluk.jpg

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

How did you flesh out Neil's ..etc... part?  You didn't include your code sample to show how you cycled through the polygon shapes to do the intersect and then the split?

0 Kudos
FC_Basson
MVP Regular Contributor

You probably need to look at the Intersect—Help | ArcGIS for Desktop  tool, but do you really need to clip each feature on it's own?  Once you have intersected the line features with the polygon features, you can assign the polygon attributes to the line features.  Unless the line feature class is dynamic and you need to repeat the process frequently.  What is the rule for when the line feature intersects with more than one polygon?

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

If intersect produces a unique ID field, you could use split Layer by Attributes to produce shapefiles of the output using that key