Finding mid-point of line using ArcPy?
The Polyline class has a new method called "positionAlongLine" in ArcGIS 10.1. This will return a PointGeometry object with exactly one point at a specified distance from the starting end of the line, or a fraction of the distance between the start and end. To find the midpoint, you would just need to do positionAlongLine(0.5,True)
. To find the midpoints for lines and add their coordinates to the attribute table, you could do Field Calculator on the following statement:
!Shape!.positionAlongLine(0.5,True).firstPoint.X
!Shape!.positionAlongLine(0.5,True).firstPoint.Y
Note that you need to be using the Python parser in field calculator for this to work.
If you wanted to access this point object in Python, you would just do the following:
Input_shp = "C:\Temp\Line.shp"
Cursor = arcpy.SearchCursor(Input_shp)
for Feature in Cursor:
Midpoint = Feature.shape.positionAlongLine(0.50,True).firstPoint
print Midpoint.X
print Midpoint.Y