AnsweredAssumed Answered

Lines to polygon tool? (reverse for Polygon To Line)

Question asked by lauri.kajan on Jan 15, 2015
Latest reply on Jan 15, 2015 by BRufenacht

Hi all,


I'm looking for a geoprocessing tool to convert line layer to polygons.

My line layer is a result of a Polygon To Lines tool so it has attributes LEFT_FID and RIGHT_FID. So I want to generate those lines back to polygons with those FIDs.

Actually I'm simplifying the polygon boundaries before converting those back to polygons. The reason why I'm doing this is I need to simplify my polygons as lines together with other line layer to keep lines and polygons topologically connected.

This is also the reason why Feature To Polygons wont work with labels coming from polygon centroid points since after simplifying those centroids might not to be inside simplified polygon boundaries anymore.


Is there any ready made tools to create polygons based on LEFT_FID and RIGHT_FID fields?


I have also tought to solve this with arcpy.


arcpy.AddIndex_management(inputLines, left_fid, 'LEFT_FID_IDX')
arcpy.AddIndex_management(inputLines, right_fid, 'RIGHT_FID_IDX')

fids = set()
with SearchCursor(inputLines, [left_fid, right_fid]) as cursor:
    for i, row in enumerate(cursor, 0):
        if row[0] and row[0] != -1:
        if row[1] and row[1] != -1:

fl = arcpy.MakeFeatureLayer_management(inputLines, 'fl')
with InsertCursor(outputfc, ['ORIG_FID', 'SHAPE@']) as ic:
    for i, fid in enumerate(fids):
        arcpy.SelectLayerByAttribute_management(fl, '', '"{0}" = {fid} or "{1}" = {fid}'.format(left_fid, right_fid, fid=fid))
        geom = arcpy.FeatureToPolygon_management(fl, arcpy.Geometry())
        for g in geom:
            ic.insertRow((fid, g))


My script first reads all FIDs from line layer.

Then iterates all FIDs and then selects all lines containing current FID.

Feature To Polygon is then used to create polygons from selected lines.


This seems to be really slow. Is there someway to improve the performance of my script?

And this creates polygons also from holes of the original polygons.



Thank you for your help.