Polygon To Line (Data Management)

License Level:BasicStandardAdvanced

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

Syntax

PolygonToLine_management (in_features, out_feature_class, {neighbor_option})
ParameterExplanationData 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
from arcpy import env
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.
# Author: ESRI

# import system modules 
import arcpy
from arcpy import env

# Set environment settings
env.workspace = "C:/data/landcovers.gdb"
 
# Create variables for the input and output feature classes
inFeatureClass = "bldgs"
outFeatureClass = "bldgs_lines"
 
# Use error trapping in case a problem occurs when running the tool
try:
    # 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.getOutput(0) == "0"):
        print "No overlapping or shared boundary lines were found."
    else:
        print result.getOutput(0) + " overlapping or shared " +\
              "boundary lines were found."
 
except Exception, e:
    # If an error occurred, print line number and error message
    import traceback, sys
    tb = sys.exc_info()[2]
    print "Line %i" % tb.tb_lineno
    print e.message

Environments

Related Topics

Licensing Information

ArcGIS for Desktop Basic: No
ArcGIS for Desktop Standard: No
ArcGIS for Desktop Advanced: Yes
5/7/2015