[postgis-users] Sorting/ordering linestrings

Charles Galpin cgalpin at lhsw.com
Wed Mar 30 18:01:33 PDT 2011

Thanks for responding Steve (and fork)

On Mar 30, 2011, at 7:47 PM, Stephen Woodbridge wrote:

> Charles Galpin<cgalpin<at>  lhsw.com>  writes:
>> Does anyone have any bright ideas on how to sort linestrings (with postgis
>> or  anything else for that matter).
> ok, need some more criteria here. Sorting linestrings is a proposed solution to an undisclosed problem. What is your problem?

I guess my biggest problem is I don't carry enough clout around here, because I wouldn't be doing this if it was my choice :)

It's a stupid requirement. I can't remember some of the reasons (other than they want it), but I know of one specific use case where it's just plain idiotic and they should use a map and let the user select links of interest from it (reporting tool). Instead they want to present the user with a list of links and let them wade through them (i assume filter) and select the ones they care about, but they want them ordered as if you were traversing the road. A map would be such a cleaner way to do it.  It's due to the fact that they currently have a set of data that is much smaller and instead of lots of little short linestrings they have larger road segments essentially from intersection to intersection. And perhaps a perception it's quicker to develop without the map.

So I guess in an ideal world I'd build up linestrings from intersection to intersection and mimic the kind of thing they have today, although they have the same ordering requirement between these larger linestrings too.  I also need to enhance our data with the nearest cross roads for the linestrings, and better road name and direction, but again most of this is oriented to how they did things before with a different data set.

Unless you have better ideas I'll revisit using the lat/lon but recall quickly running into problems with curved roads. Also taking a fixed point and comparing the distance to it has it flaws with horseshoe shaped roads and curves etc.


More information about the postgis-users mailing list