Polygon To Line (Data Management)

Summary

Creates a feature class containing lines that are converted from polygon boundaries with or without considering neighboring polygons.

Illustration

Polygon To Line illustration

Usage

  • If the Identify and store polygon neighboring information check box is checked (neighbor_option is set to IDENTIFY_NEIGHBORS in Python), the polygon neighboring relationship will be analyzed. As illustrated above, the boundaries are converted to lines, taking into account crossing or shared segments; two new fields, LEFT_FID and RIGHT_FID, will be added to the output feature class and set to the feature IDs of the input polygons to the left and right of each output line. The attributes of the input features will not be maintained in the output feature class. The following scenarios help you understand the process and output in more detail:

    • In a polygon geometry, the outer boundary is always stored in a clockwise direction. If the polygon has a hole, the hole (or inner) boundary is always stored in a counterclockwise direction. Therefore, for a polygon with no neighbors to the left side (outside) of its outer boundary and the left side (inside) of the hole boundary, the resulting lines will have a value of -1 for LEFT_FID and the polygon feature ID as the RIGHT_FID.
    • If a polygon contains another polygon, one output line in the clockwise direction will be generated representing the shared boundary, with its LEFT_FID set to the outer polygon feature ID and the RIGHT_FID set to the inner polygon feature ID.
    • If two polygons share a portion of their boundaries, one output line will be generated representing the shared segment. The line direction will be arbitrary; the LEFT_FID and the RIGHT_FID will be set to the left or right polygon feature IDs accordingly.
    • If a polygon overlaps another polygon, two output lines will be generated representing each crossing boundary twice: the first line will represent the outer boundary of one of the overlapping polygons, therefore, its LEFT_FID is the feature ID of the polygon it crosses, and its RIGHT_FID will be its own polygon feature ID; the second line will be in the opposite direction, splitting the other polygon, therefore, its LEFT_FID and RIGHT_FID will be the same as the other polygon feature ID.
    • Multiparts in input polygons are not maintained; the output lines are all single part.

    For parametric (true) curve input features, output lines will remain true curves, even if they are split. This does not apply to shapefile data.

    This option uses a tiling process to handle very large datasets for better performance and scalability. For more details, see Tiled processing of large datasets.

  • If the Identify and store polygon neighboring information check box is unchecked (neighbor_option is set to IGNORE_NEIGHBORS in Python), the polygon neighboring relationship will be ignored. Each input polygon boundary will be written out as an enclosed line feature. A multipart polygon will become a multipart line in the output. The attributes of the input features will be maintained in the output feature class. A new field, ORIG_FID, will be added to the output and set to the input feature IDs of each line.

Parameters

LabelExplanationData Type
Input Features

The input features that must be polygon.

Feature Layer
Output Feature Class

The output line feature class.

Feature Class
Identify and store polygon neighboring information
(Optional)

Specifies whether or not to identify and store polygon neighboring information.

  • Checked— Polygon neighboring relationship will be identified and stored in the output. If different segments of a polygon share boundary with different polygons, the boundary will be split such that each uniquely shared segment will become a line with its two neighboring polygon FIDs stored in the output, as shown in the illustration. This is the default.
  • Unchecked— Polygon neighboring relationship will be ignored; every polygon boundary will become a line feature with its original polygon feature ID stored in the output.

Boolean

arcpy.management.PolygonToLine(in_features, out_feature_class, {neighbor_option})
NameExplanationData Type
in_features

The input features that must be polygon.

Feature Layer
out_feature_class

The output line feature class.

Feature Class
neighbor_option
(Optional)

Specifies whether or not to identify and store polygon neighboring information.

  • IDENTIFY_NEIGHBORSPolygon neighboring relationship will be identified and stored in the output. If different segments of a polygon share boundary with different polygons, the boundary will be split such that each uniquely shared segment will become a line with its two neighboring polygon FIDs stored in the output. This is the default.
  • IGNORE_NEIGHBORSPolygon neighboring relationship will be ignored; every polygon boundary will become a line feature with its original polygon feature ID stored in the output.
Boolean

Code sample

PolygonToLine example 1 (Python window)

The following Python window script demonstrates how to use the PolygonToLine function in immediate mode.

import arcpy
arcpy.env.workspace = "C:/data"
arcpy.PolygonToLine_management("Habitat_Analysis.gdb/vegtype", 
                               "C:/output/Output.gdb/vegtype_lines",
                               "IGNORE_NEIGHBORS")
PolygonToLine example 2 (stand-alone script)

The following stand-alone script is a simple example of how to apply the PolygonToLine function in a scripting environment.

# Name: PolygonToLine_Example2.py
# Description: Use PolygonToLine function to convert polygons to lines,
#              and report how many shared or overlapping boundary lines
#              were found.

# import system modules 
import arcpy

# Set environment settings
arcpy.env.workspace = "C:/data/landcovers.gdb"
 
# Create variables for the input and output feature classes
inFeatureClass = "bldgs"
outFeatureClass = "bldgs_lines"
 
# Run PolygonToLine to convert polygons to lines using default neighbor_option
arcpy.PolygonToLine_management(inFeatureClass, outFeatureClass)

# Select lines that have LEFT_FID values greater than -1
arcpy.MakeFeatureLayer_management(outFeatureClass, "selection_lyr", 
                                  "\"LEFT_FID\" > -1")
result = arcpy.GetCount_management("selection_lyr")

if result[0] == "0":
    print("No overlapping or shared boundary lines were found.")
else:
    print("{} overlapping or shared boundary lines were found.".format(result[0]))

Related topics