Midpoint of a line?

3589
2
07-06-2011 02:31 PM
GerryGabrisch
Occasional Contributor III
I would like to use Python to get the midpoint of a line.

There are a number of geometry properties that will return the centroid, the label point�?�

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Polyline/000v000000n2000000/

�?�but what I am looking for is the coordinate values of the position which is exactly halfway along the line�??s length.

It is possible to calculate the midpoint using the calculate geometry functions by right clicking a new field in the attribute table and selecting calculate geometry, but I can find no way to get that calculation into a Python code block.
Any ideas?
Tags (2)
0 Kudos
2 Replies
DarrenWiens2
MVP Honored Contributor
Doesn't the centroid give you the point object that you're looking for, which I assume you can access the coordinates by centroid.x, centroid.y?
0 Kudos
GerryGabrisch
Occasional Contributor III
No, you would think!  The centroid returns the midpoint of the line if and only if that point falls on the line, otherwise it returns the coordinates of the label point (which seems to be defined by magic:)).
I have a script that I tested on a line shaped like three sides of a square, and the centroid is not close to the midpoint of that line.
Using the midpoint function from calculate geometry does return the true midpoint coordinates of that line, but there is no Arcpy/Python property that returns that same coordinate value.
0 Kudos