How to cut polygon feature using line feature

11802
5
08-08-2016 07:36 PM
SheikhHafiz1
New Contributor III

Hi,

I have a line feature and a polygon feature for roads. The polygons do not have always the same width. The line features of the roads are not the center line of the roads but those line features are within the polygon features. I want to cut the polygon features according to the length of the line features. How can I do that?

In the attachment I have shown the polygon features and the line features for roads and selected two line features to show the length. I want to cut all the polygon features in the polygon feature class according to the length of the all the line features in the line feature class.

Any help is appreciated.

Thanks.

Hafiz

0 Kudos
5 Replies
JohannesBierer
Occasional Contributor III

Maybe you can use buffer tool with the option endtype flat and then process further to cut the polygon to the lenght of the line?

0 Kudos
SheikhHafiz1
New Contributor III

Thanks Johannes. I tried that way before publishing this post. It did not give me the desired output. I appreciate your help.

0 Kudos
JoeBorgione
MVP Emeritus

Check out ArcGIS tools add-ons and extensions from ET SpatialTechniques (ian-ko.com) he has a split polygons with polylines tool.

That should just about do it....
RichardFairhurst
MVP Honored Contributor

If you have an Advanced license you can use the Feature To Polygon tool.  It will take both the polygon and the line inputs and divide the polygons wherever the lines fully intersect one of the polygons.  You can use the Identity tool with the output to transfer the attributes of the original polygons back into the cut polygons.  Your polygons need to be topologically clean (no overlaps) for this to work well.

FC_Basson
MVP Regular Contributor

I found a Python script on StackExchange [Automated/geoprocesing tool to slice, clip, or cut polygons using polylines using ArcGIS Desktop? - ... ] that does the job.

Credit to John Tran, Tristan Forward

  1. Copy and save the code below to a .py file
  2. Create a new script tool in your ArcToolbox for the new py file
  3. Set the parameters for the script as:
    1. Input Polygon (type Feature Class, direction Input)
    2. Input Polyline (type Feature Class, direction Input)
    3. Output Polygon (type Feature Class, direction Output)
  4. Run the script tool

__author__ = "John K. Tran, Tristan Forward"

__contact__ = "jtran20@masonlive.gmu.edu, http://gis.stackexchange.com/users/6996/tristan-forward"

__version__ = "2.0"

__created__ = "7/3/15"

__credits__ = "http://gis.stackexchange.com/questions/124198/optimizing-arcpy-code-to-cut-polygon"

"""

Cut polygons by polylines, splitting each polygon into slices.

:param to_cut: The polygon to cut.

:param cutter: The polylines that will each polygon.

:param out_fc: The output with the split geometry added to it.

"""

import os

import sys

import arcpy

arcpy.SetProgressor("default", "Firing up script...")

to_cut = arcpy.GetParameterAsText(0)

cutter = arcpy.GetParameterAsText(1)

out_fc = arcpy.GetParameterAsText(2)

spatialref = arcpy.Describe(to_cut).spatialReference

polygons = []

lines = []

slices = []

gcount = 0

pcount = 0

with arcpy.da.SearchCursor(to_cut, ["SHAPE@", "OID@"]) as pcursor:

    for prow in pcursor:

        arcpy.SetProgressorLabel("Generating slices: {0} rows complete".format(str(pcount)))

        polygon = prow[0]

        polyid = prow[1]

        polygons.append((polygon, polyid))

        pcount += 1

del pcursor

lcount= 0

with arcpy.da.SearchCursor(cutter, ["SHAPE@", "OID@"]) as lcursor:

    for lrow in lcursor:

        line = lrow[0]

        lineid = lrow[1]

        lines.append((line, lineid))

        lcount += 1

del lcursor

def cut_geometry():

    global polygons

    global lines

    global slices

    global gcount

    for eachpoly, eachpolyid in polygons:

        iscut = False

        for eachline, eachlineid in lines:

            if eachline.crosses(eachpoly):

                try:

                    slice1, slice2 = eachpoly.cut(eachline)

                    polygons.insert(0, (slice1, eachpolyid))

                    polygons.insert(0, (slice2, eachpolyid))

                    iscut = True

                except RuntimeError:

                    continue

        if iscut == False:

            slices.append((eachpoly, eachpolyid))

            gcount += 1

            if gcount % 10 == 0:

                arcpy.SetProgressorLabel("Cutting polygons: {0} rows complete".format(str(gcount)))

        polygons.remove((eachpoly, eachpolyid))

while polygons:

    cut_geometry()

arcpy.SetProgressorLabel("Creating output feature class")

arcpy.CreateFeatureclass_management(os.path.dirname(out_fc), os.path.basename(out_fc), "POLYGON",

                                    spatial_reference = spatialref)

arcpy.AddField_management(out_fc, "SOURCE_OID", "LONG")

scount = 0

with arcpy.da.InsertCursor(out_fc, ["SHAPE@", "SOURCE_OID"]) as icursor:

    for eachslice in slices:

        if scount % 10 == 0:

            arcpy.SetProgressorLabel("Inserting slices: {0} rows complete".format(str(scount)))

        icursor.insertRow(eachslice)

        scount += 1

del icursor

arcpy.SetProgressorLabel("Deleting duplicate slices")

shapefieldname = arcpy.Describe(out_fc).shapeFieldName

arcpy.DeleteIdentical_management(out_fc, [shapefieldname, "SOURCE_OID"])

arcpy.ResetProgressor()