Select to view content in your preferred language

# What is the python expression for the second, third, fourth etc etc vertex along a line feature?

693
2
08-13-2019 06:22 AM
Deactivated User

What is the python expression for the second, third, fourth etc etc vertex along a line feature? !shape.firstpoint¡ is the first vertex and !shape.lastpoint¡ is the last vertex, but what's the expression for other vertices down the line?

Tags (4)
2 Replies
by
Frequent Contributor

Theres no specific way to do this, this is likely a design decision, as features can have theoretically unlimited vertexes so loading all this info to populate a dictionary etc, could be expensive and have potential to massively slow down cursors.

Check out this article, that tells you the exact same thing I could but using many more words and much more coherently:

The code at the bottom should allow you to do as you require.

``````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 += 1p
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍``````

MVP Esteemed Contributor

I agree with Luke that cursors are best when working with more in-depth properties or methods of geometries.  If you must work with the Field Calculator, the "Code samples -- geometry" section of Calculate Field examples—Help | ArcGIS Desktop shows how you would retrieve the geometry and then process it in a code block.