Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

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?

share|improve this question

marked as duplicate by Fezter, PolyGeo, BradHards, Simbamangu, Devdatta Tengshe May 2 '14 at 6:19

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Sounds like you're calculating the sinuosity, which seems pretty right-on to me. – dbaston May 1 '14 at 16:07
@dbaston thanks! Now I have something to Google. – ilia choly May 1 '14 at 16:36
Why is this a duplicate? The linked question has to do with sinuosity, but the similarity ends there. – dbaston May 2 '14 at 13:04
up vote 1 down vote accepted

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.

share|improve this answer

I do not know the exact syntax implementation in postgis but you can calculate sinuosity with the following pseudo-code:

d = sqrt( (startPoint[X] - endPoint[X]) ** 2 + (startPoint[Y] - endPoint[Y]) ** 2 )
  sinuosity = (d / lineLength)
share|improve this answer
The problem with that is it uses planar (Euclidean) geometry. The question proposes using the accurate spheroidal forms of the distance and length functions. – Martin F May 1 '14 at 19:22

Not the answer you're looking for? Browse other questions tagged or ask your own question.