# How do you determine how straight a LineString is? [duplicate]

I have a bunch of LINESTRINGs and need to classify them based on how strait they are. My idea is to compare the length of the LINESTRING to the distance between the first and last POINTs.

I'm thinking of something along these lines (assume the srs units are in meters):

``````ST_Length_Spheroid(geom) - ST_Distance_Spheroid(ST_PointN(geom, 1), ST_PointN(geom, St_NumPoints(geom)))
``````

Is there a better way to do this?

• Sounds like you're calculating the sinuosity, which seems pretty right-on to me. Commented May 1, 2014 at 16:07
• Why is this a duplicate? The linked question has to do with sinuosity, but the similarity ends there. Commented May 2, 2014 at 13:04

Assuming you add the appropriate ellipsoid parameter to the `ST_Distance_Spheroid` and `ST_Length_Spheroid` functions, your approach looks sound for calculating sinuosity (as dbaston said).
Another approach to consider is to calculate maximum deviation (or offset) of the intermediate points from the geodesic (ie, 'straight') line. The question then becomes "How to compute/create a geodesic in PostGIS". I'm unsure if `ST_Project` can be used for such a purpose.
``````d = sqrt( (startPoint[X] - endPoint[X]) ** 2 + (startPoint[Y] - endPoint[Y]) ** 2 )