Polyline (arcpy)

Summary

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

Discussion

In many geoprocessing workflows, you may need to run a specific operation using coordinate and geometry information but don't necessarily want to go through the process of creating a new (temporary) feature class, populating the feature class with cursors, using the feature class, then deleting the temporary feature class. Geometry objects can be used instead for both input and output to make geoprocessing simpler. Geometry objects can be created from scratch using Geometry, Multipoint, PointGeometry, Polygon, or Polyline classes.

Syntax

Polyline (inputs, {spatial_reference}, {has_z}, {has_m})
ParameterExplanationData Type
inputs

The coordinates used to create the object. The datatype can be either Point or Array objects.

Object
spatial_reference

The spatial reference of the new geometry.

(The default value is None)

SpatialReference
has_z

The Z state: True for geometry if Z is enabled and False if it is not.

(The default value is False)

Boolean
has_m

The M state: True for geometry if M is enabled and False if it is not.

(The default value is False)

Boolean

Properties

PropertyExplanationData Type
JSON
(Read Only)

Returns a JSON representation of the geometry as a string.

TipTip:

The returned string can be converted to a dictionary using Python's json.loads function.

String
WKB
(Read Only)

Returns the well-known binary (WKB) representation for OGC geometry. It provides a portable representation of a geometry value as a contiguous stream of bytes.

Bytearray
WKT
(Read Only)

Returns the well-known text (WKT) representation for OGC geometry. It provides a portable representation of a geometry value as a text string.

String
area
(Read Only)

The area of a polygon feature. Empty for all other feature types.

Double
centroid
(Read Only)

The true centroid if it is within or on the feature; otherwise, the label point is returned. Returns a point object.

Point
extent
(Read and Write)

The extent of the geometry.

Extent
firstPoint
(Read Only)

The first coordinate point of the geometry.

Point
hullRectangle
(Read Only)

A space-delimited string of the coordinate pairs of the convex hull rectangle.

String
isMultipart
(Read Only)

True, if the number of parts for this geometry is more than one.

Boolean
labelPoint
(Read Only)

The point at which the label is located. The labelPoint is always located within or on a feature.

Point
lastPoint
(Read Only)

The last coordinate of the feature.

Point
length
(Read Only)

The length of the linear feature. Zero for point and multipoint feature types.

Double
length3D
(Read and Write)

The 3D length of the linear feature. Zero for point and multipoint feature types.

Double
partCount
(Read Only)

The number of geometry parts for the feature.

Integer
pointCount
(Read Only)

The total number of points for the feature.

Integer
spatialReference
(Read Only)

The spatial reference of the geometry.

SpatialReference
trueCentroid
(Read Only)

The center of gravity for a feature.

Point
type
(Read Only)

The geometry type: polygon, polyline, point, multipoint, multipatch, dimension, or annotation.

String

Method Overview

MethodExplanation
boundary ()

Constructs the boundary of the geometry.

Boundary operator
buffer (distance)

Constructs a polygon at a specified distance from the geometry.

Buffer operator
clip (envelope)

Constructs the intersection of the geometry and the specified extent.

Clip operator
contains (second_geometry)

Indicates if the base geometry contains the comparison geometry.

contains is the opposite of within.

Only True relationships are shown in this illustration.

Possible contains relationships
convexHull ()

Constructs the geometry that is the minimal bounding polygon such that all outer angles are convex.

ConvexHull operator
crosses (second_geometry)

Indicates if the two geometries intersect in a geometry of a lesser shape type.

Two polylines cross if they share only points in common, at least one of which is not an endpoint. A polyline and an polygon cross if they share a polyline or a point (for vertical line) in common on the interior of the polygon which is not equivalent to the entire polyline.

Only True relationships are shown in this illustration.

Possible crosses relationships
cut (cutter)

Splits this geometry into a part left of the cutting polyline, and a part right of it.

When a polyline or polygon is cut, it is split where it intersects the cutter polyline. Each piece is classified as left of or right of the cutter. This classification is based on the orientation of the cutter line. Parts of the target polyline that do not intersect the cutting polyline are returned as part of the right of result for that input polyline. If a geometry is not cut, the left geometry will be empty (None).

Cut operator
difference (other)

Constructs the geometry that is composed only of the region unique to the base geometry but not part of the other geometry. The following illustration shows the results when the red polygon is the source geometry.

Difference operator
disjoint (second_geometry)

Indicates if the base and comparison geometries share no points in common.

Two geometries intersect if disjoint returns False.

Only True relationships are shown in this illustration.

Possible disjoint relationships
distanceTo (other)

Returns the minimum distance between two geometries. If the geometries intersect, the minimum distance is 0.

Both geometries must have the same projection.

equals (second_geometry)

Indicates if the base and comparison geometries are of the same shape type and define the same set of points in the plane. This is a 2D comparison only; M and Z values are ignored.

Only True relationships are shown in this illustration.

Possible equals relationships
getArea ({type}, {units})

Returns the area of the feature using a measurement type.

getLength ({measurement_type}, {units})

Returns the length of the feature using a measurement type.

getPart ({index})

Returns an array of point objects for a particular part of geometry or an array containing a number of arrays, one for each part.

intersect (other, dimension)

Constructs a geometry that is the geometric intersection of the two input geometries. Different dimension values can be used to create different shape types.

The intersection of two geometries of the same shape type is a geometry containing only the regions of overlap between the original geometries.

Intersect operator

For faster results, test if the two geometries are disjoint before calling intersect.

measureOnLine (in_point, {as_percentage})

Returns a measure from the start point of this line to the in_point.

overlaps (second_geometry)

Indicates if the intersection of the two geometries has the same shape type as one of the input geometries and is not equivalent to either of the input geometries.

Only True relationships are shown in this illustration.

Possible overlaps relationships
positionAlongLine (value, {use_percentage})

Returns a point on a line at a specified distance from the beginning of the line.

projectAs (spatial_reference, {transformation_name})

Projects a geometry and optionally applies a geotransformation.

To project, the geometry needs to have a spatial reference, and not have an UnknownCoordinateSystem. The new spatial reference system passed to the method defines the output coordinate system. If either spatial reference is unknown the coordinates will not be changed. The Z- and measure values are not changed by the ProjectAs method.

queryPointAndDistance (in_point, {as_percentage})

Finds the point on the polyline nearest to the in_point and the distance between those points. Also returns information about the side of the line the in_point is on as well as the distance along the line where the nearest point occurs.

snapToLine (in_point)

Returns a new point based on in_point snapped to this geometry.

symmetricDifference (other)

Constructs the geometry that is the union of two geometries minus the instersection of those geometries.

The two input geometries must be the same shape type.

symmetricDifference operator
touches (second_geometry)

Indicates if the boundaries of the geometries intersect.

Two geometries touch when the intersection of the geometries is not empty, but the intersection of their interiors is empty. For example, a point touches a polyline only if the point is coincident with one of the polyline end points.

Only True relationships are shown in this illustration.

Possible touches relationships
union (other)

Constructs the geometry that is the set-theoretic union of the input geometries.

The two geometries being unioned must be the same shape type.

Union operator
within (second_geometry)

Indicates if the base geometry is within the comparison geometry.

within is the opposite operator of contains.

Only True relationships are shown in this illustration.

Possible within relationships

Methods

boundary ()
Return Value
Data TypeExplanation
Object

A polygon's boundary is a polyline. A polyline's boundary is a multipoint, corresponding to the endpoints of the line. A point or multipoint's boundary is an empty point or multipoint.

buffer (distance)
ParameterExplanationData Type
distance

The buffer distance.

The buffer distance is in the same units as the geometry that is being buffered.

A negative distance can only be specified against a polygon geometry.

Double
Return Value
Data TypeExplanation
Polygon

The buffered polygon geometry.

clip (envelope)
ParameterExplanationData Type
envelope

An extent object used to define the clip extent.

Extent
Return Value
Data TypeExplanation
Object

An output geometry clipped to the specified extent.

contains (second_geometry)
ParameterExplanationData Type
second_geometry

A second geometry.

Object
Return Value
Data TypeExplanation
Boolean

A return Boolean value of True indicates this geometry contains the second geometry.

convexHull ()
Return Value
Data TypeExplanation
Object

The resulting geometry. The convex hull of a single point is the point itself.

crosses (second_geometry)
ParameterExplanationData Type
second_geometry

A second geometry.

Object
Return Value
Data TypeExplanation
Boolean

A return Boolean value of True indicates the two geometries intersect in a geometry of a lesser shape type.

cut (cutter)
ParameterExplanationData Type
cutter

The cutting polyline geometry.

PolyLine
Return Value
Data TypeExplanation
Geometry

A list of two geometries.

difference (other)
ParameterExplanationData Type
other

A second geometry.

Object
Return Value
Data TypeExplanation
Object

The resulting geometry.

disjoint (second_geometry)
ParameterExplanationData Type
second_geometry

A second geometry.

Object
Return Value
Data TypeExplanation
Boolean

A return Boolean value of True indicates that the two geometries share no points in common.

distanceTo (other)
ParameterExplanationData Type
other

A second geometry.

Object
Return Value
Data TypeExplanation
Double

The distance between the two geometries.

equals (second_geometry)
ParameterExplanationData Type
second_geometry

A second geometry.

Object
Return Value
Data TypeExplanation
Boolean

A return Boolean value of True indicates that the two geometries are of the same shape type and define the same set of points in the plane.

getArea ({type}, {units})
ParameterExplanationData Type
type

PLANAR measurements reflect the projection of geographic data onto the 2D surface (in other words, they will not take into account the curvature of the earth). GEODESIC, GREAT_ELLIPTIC, LOXODROME, and PRESERVE_SHAPE measurement types may be chosen as an alternative, if desired.

  • GEODESICThe shortest line between any two points on the earth's surface on a spheroid (ellipsoid). One use for a geodesic line is when you want to determine the shortest distance between two cities for an airplane's flight path. This is also known as a great circle line if based on a sphere rather than an ellipsoid.
  • GREAT_ELLIPTICThe line on a spheroid (ellipsoid) defined by the intersection at the surface by a plane that passes through the center of the spheroid and the start and endpoints of a segment. This is also known as a great circle when a sphere is used.
  • LOXODROMEA loxodrome is not the shortest distance between two points but instead defines the line of constant bearing, or azimuth. Great circle routes are often broken into a series of loxodromes, which simplifies navigation. This is also known as a rhumb line.
  • PLANARPlanar measurements use 2D Cartesian mathematics to calculate lengths and areas. This option is only available when measuring in a projected coordinate system and the 2D plane of that coordinate system will be used as the basis for the measurements.
  • PRESERVE_SHAPEThis type calculates the area or length of the geometry on the surface of the earth ellipsoid, for geometry defined in a projected or geographic coordinate system. This option preserves the shape of the geometry in its coordinate system.

(The default value is GEODESIC)

String
units

The units in which the area will be calculated.

Areal unit of measure keywords: ACRES | ARES | HECTARES | SQUARECENTIMETERS | SQUAREDECIMETERS | SQUAREINCHES | SQUAREFEET | SQUAREKILOMETERS | SQUAREMETERS | SQUAREMILES | SQUAREMILLIMETERS | SQUAREYARDS

String
Return Value
Data TypeExplanation
Double

The area of the feature.

By default, for Projected coordinate systems, area will be returned in the units of the coordinate system, and for Geographic coordinate systems, area will be returned in square meters.

getLength ({measurement_type}, {units})
ParameterExplanationData Type
measurement_type

PLANAR measurements reflect the projection of geographic data onto the 2D surface (in other words, they will not take into account the curvature of the earth). GEODESIC, GREAT_ELLIPTIC, LOXODROME, and PRESERVE_SHAPE measurement types may be chosen as an alternative, if desired.

  • GEODESICThe shortest line between any two points on the earth's surface on a spheroid (ellipsoid). One use for a geodesic line is when you want to determine the shortest distance between two cities for an airplane's flight path. This is also known as a great circle line if based on a sphere rather than an ellipsoid.
  • GREAT_ELLIPTICThe line on a spheroid (ellipsoid) defined by the intersection at the surface by a plane that passes through the center of the spheroid and the start and endpoints of a segment. This is also known as a great circle when a sphere is used.
  • LOXODROMEA loxodrome is not the shortest distance between two points but instead defines the line of constant bearing, or azimuth. Great circle routes are often broken into a series of loxodromes, which simplifies navigation. This is also known as a rhumb line.
  • PLANARPlanar measurements use 2D Cartesian mathematics to calculate lengths and areas. This option is only available when measuring in a projected coordinate system and the 2D plane of that coordinate system will be used as the basis for the measurements.
  • PRESERVE_SHAPEThis type calculates the area or length of the geometry on the surface of the earth ellipsoid, for geometry defined in a projected or geographic coordinate system. This option preserves the shape of the geometry in its coordinate system.

(The default value is GEODESIC)

String
units

The units in which the length will be calculated.

Linear unit of measure keywords: CENTIMETERS | DECIMETERS | FEET | INCHES | KILOMETERS | METERS | MILES | MILLIMETERS | NAUTICALMILES | YARDS

String
Return Value
Data TypeExplanation
Double

The length of the feature.

By default, for Projected coordinate systems, length will be returned in the units of the coordinate system, and for Geographic coordinate systems, length will be returned in square meters.

getPart ({index})
ParameterExplanationData Type
index

The index position of the geometry.

Integer
Return Value
Data TypeExplanation
Array

getPart returns an array of point objects for a particular part of the geometry if an index is specified. If an index is not specified, an array containing an array of point objects for each geometry part is returned.

intersect (other, dimension)
ParameterExplanationData Type
other

The second geometry.

Object
dimension

The topological dimension (shape type) of the resulting geometry.

  • 1A zero-dimensional geometry (point or multipoint).
  • 2A one-dimensional geometry (polyline).
  • 4A two-dimensional geometry (polygon).
Integer
Return Value
Data TypeExplanation
Object

A new geometry (point, multipoint, polyline, or polygon) that is the geometric intersection of the two input geometries.

measureOnLine (in_point, {as_percentage})
ParameterExplanationData Type
in_point

A point (PointGeometry or Point) that is used to measure from the start point of the polyline.

PointGeometry
as_percentage

If False, the measure will be returned as a distance; if True, the measure will be returned as a percentage.

(The default value is False)

Boolean
Return Value
Data TypeExplanation
Double

A distance or percentage.

overlaps (second_geometry)
ParameterExplanationData Type
second_geometry

A second geometry.

Object
Return Value
Data TypeExplanation
Boolean

A return Boolean value of True indicates the intersection of the two geometries has the same dimension as one of the input geometries.

positionAlongLine (value, {use_percentage})
ParameterExplanationData Type
value

The distance along the line.

If the distance is less than zero, then the starting point of the line will be returned; if the distance is greater than the length of the line, then the end point of the line will be returned.

Double
use_percentage

The distance may be specified as a fixed unit of measure or a ratio of the length of the line.

If True, value is used as a percentage; if False, value is used as a distance. For percentages, the value should be expressed as a double from 0.0 (0%) to 1.0 (100%).

(The default value is False)

Boolean
Return Value
Data TypeExplanation
PointGeometry

The point on the line at a specified distance from the beginning of the line.

projectAs (spatial_reference, {transformation_name})
ParameterExplanationData Type
spatial_reference

The new spatial reference. This can be a SpatialReference object or the coordinate system name.

SpatialReference
transformation_name

The geotransformation name.

String
Return Value
Data TypeExplanation
Object

The projected geometry.

queryPointAndDistance (in_point, {as_percentage})
ParameterExplanationData Type
in_point

The input point (PointGeometry or Point).

PointGeometry
as_percentage

If False, the measure will be returned as a distance; if True, the measure will be returned as a percentage.

(The default value is False)

Boolean
Return Value
Data TypeExplanation
tuple

Returns a tuple that includes the following:

  • A PointGeometry that is the nearest point on the polyline to the in_point.
  • The distance between the start point of the line and the returned point on the line.
  • The minimum distance between the line and the in_point.
  • A Boolean that indicates if the in_point is on the right side of the line. The direction of the line determines the right and left sides.
snapToLine (in_point)
ParameterExplanationData Type
in_point

A point (PointGeometry or Point) to be snapped to the line.

PointGeometry
Return Value
Data TypeExplanation
PointGeometry

The snapped point.

symmetricDifference (other)
ParameterExplanationData Type
other

A second geometry.

Object
Return Value
Data TypeExplanation
Object

The resulting geometry.

touches (second_geometry)
ParameterExplanationData Type
second_geometry

A second geometry.

Object
Return Value
Data TypeExplanation
Boolean

A return Boolean value of True indicates the boundaries of the geometries intersect.

union (other)
ParameterExplanationData Type
other

A second geometry.

Object
Return Value
Data TypeExplanation
Object

The resulting geometry.

within (second_geometry)
ParameterExplanationData Type
second_geometry

A second geometry.

Object
Return Value
Data TypeExplanation
Boolean

A return Boolean value of True indicates this geometry is contained within the second geometry.

Code Sample

Polyline example

Create a polyline feature class from scratch.

import arcpy

# A list of features and coordinate pairs
feature_info = [[[1, 2], [2, 4], [3, 7]],
                [[6, 8], [5, 7], [7, 2], [9, 5]]]

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

for feature in feature_info:
    # Create a Polyline object based on the array of points
    # Append to the list of Polyline objects
    features.append(
        arcpy.Polyline(
            arcpy.Array([arcpy.Point(*coords) for coords in feature])))

# Persist a copy of the Polyline objects using CopyFeatures
arcpy.CopyFeatures_management(features, "c:/geometry/polylines.shp")

Related Topics

3/3/2014