Tuesday, June 7, 2011

The Polyline Object

A Polyline object is a shape defined by one or more paths, in which a path is a series of connected segments.



Method information can be found here.


Example: Creating a Polyline

import arcpy
coordList = [[[1,2], [2,4], [3,7]],
            [[6,8], [5,7], [7,2], [9,5]]]
# Create empty Point and Array objects
#
point = arcpy.Point()
array = arcpy.Array()

# A list that will hold each of the Polyline objects
#
featureList = []

for feature in coordList:
# For each coordinate pair, set the x,y properties and add to the
# Array object.
#
for coordPair in feature:
   point.X = coordPair[0]
   point.Y = coordPair[1]
   array.add(point)
   # Create a Polyline object based on the array of points
   #
   polyline = arcpy.Polyline(array)
   # Clear the array for future use
   #
   array.removeAll()
   # Append to the list of Polyline objects
   #
   featureList.append(polyline)

# Create a copy of the Polyline objects, by using featureList as input to
# the CopyFeatures tool.
#
arcpy.CopyFeatures_management(featureList, "c:/geometry/polylines.shp")