Measure Straight line distance

1168
4
01-03-2012 12:03 PM
NicholasWissler1
New Contributor
I have a polyline in ArcMap and I'd like to be able to do two different length (Or distance) measurements utilizing Python.  The first measurement needs to be length from endpoint to endpoint within the polyline.  I accomplished this part. 

The polyline is wavy and bent.  I want measure straight line distance from endpoint to endpoint.  This is easy using the measure tool within Arc, but I want to add the measurement to part of a script I'm working on. I know that the distance measurement is: X^0.5((x1-x2)^2 + (y1-y2)^2) but short of writing down the coordinates and fat fingering them into the script how can I get Python and Arc to access the endpoint information to utilize this distance measurement?

Thanks,

Nick
Tags (2)
0 Kudos
4 Replies
AngelaHansen
New Contributor
Hi,

Off of the top of my head, this is one way to do it...

Add 4 new fields to the feature class (startX, startY, endX, endY) and calculate geometry for each. Then these values can be used in your formula to measure the distance.
0 Kudos
NicholasWissler1
New Contributor
Thanks Angela.  I can definitely accomplish this, however I don't know how I can ensure that I am measuring straight line distance from end point to end point (Shortest route?) as opposed to distance along the polyline.
0 Kudos
markdenil
Occasional Contributor III
The distance between the (end) points can be calculated using the Pythagorean theorem, and will by definition be a straight line; or at least it will be a straight line in whatever coordinate space you are using.
Each coordinate system holds highly parochial (and often quite localized) views of the definition of 'straight' and 'shortest'. Make sure that the system's opinions align with yours, or at least that the errors are small enough to be negligible.
0 Kudos
HemingZhu
Occasional Contributor III
Thanks Angela.  I can definitely accomplish this, however I don't know how I can ensure that I am measuring straight line distance from end point to end point (Shortest route?) as opposed to distance along the polyline.


XYToLine_management will create a featureclass containing geodetic two-point features from start and end points (no matter what the unit the points are in).
0 Kudos