ArcGIS Pro

Reading geometries

In this topic

Each feature in a feature class contains a set of points defining the vertices of a polygon or line, or a single coordinate defining a point feature. These points can be accessed with geometry objects (Polygon, Polyline, PointGeometry, or MultiPoint), which returns them in an array of Point objects.

Features can have multiple parts. The geometry object's partCount property returns the number of parts for a feature. The getPart method 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.

PointGeometry features return a single Point object instead of an array of point objects. All other feature types—polygon, polyline, and multipoint—return an array of point objects or if the feature has multiple parts, an array containing multiple arrays of point objects.

If a polygon contains holes, it consists of a number of rings. The array of point objects returned for a polygon contains the points for the exterior ring and all inner rings. The exterior ring is always returned first, followed by inner rings, with null point objects as the separator between rings. Whenever a script is reading coordinates for polygons in a geodatabase or shapefile, it should contain logic for handling inner rings if this information is required by the script; otherwise, only the exterior ring is read.

A multipart feature is composed of more than one physical part but only references one set of attributes in the database. For example, in a layer of states, the state of Hawaii could be considered a multipart feature. Although composed of many islands, it would be recorded in the database as one feature.

A ring is a closed path that defines a two-dimensional area. A valid ring consists of a valid path, such that the from and to points of the ring have the same x,y coordinates. A clockwise ring is an exterior ring, and a counterclockwise ring defines an interior ring.

Using geometry tokens

Geometry tokens can also be used as shortcuts in place of accessing full geometry objects. Additional geometry tokens can be used to access specific geometry information. Accessing the full geometry is more costly timewise. If you only need specific properties of the geometry, use tokens to provide shortcuts to access geometry properties. For instance, SHAPE@XY returns a tuple of x,y coordinates that represent the feature's centroid.

Reading polyline or polygon geometries

Search cursor on a polygon or line feature class

import arcpy
infc = arcpy.GetParameterAsText(0)
# Enter for loop for each feature
#
for row in arcpy.da.SearchCursor(infc, ["OID@", "SHAPE@"]):
# Print the current multipoint's ID
#
print("Feature {}:".format(row[0]))
partnum = 0
# Step through each part of the feature
#
for part in row[1]:
# Print the part number
#
print("Part {}:".format(partnum))
# Step through each vertex in the feature
#
for pnt in part:
if pnt:
# Print x,y coordinates of current point
#
print("{}, {}".format(pnt.X, pnt.Y))
else:
# If pnt is None, this represents an interior ring
#
print("Interior Ring:")
partnum += 1

With the feature class above, the script returns the information below. Feature 0 is a single-part polygon, feature 1 is a two-part polygon, and feature 2 is a single-part polygon with an interior ring.