[OSM-dev] osm2pgsql, direction of a virtual way (based on a route)

Igor Podolskiy igor.podolskiy at vwi-stuttgart.de
Wed Oct 26 19:28:16 BST 2011


Hi Markus,

> No, I'm indeed very unsure in aspects of the new schema. If the ways
> don't have roles, the direction of the route will have to be
> determined based alone on the sequence of ways in the route.
Yes, this is the only feasible way I can think of with PT routes if you 
don't have roles. This is also the way the new PT schema does this. Once 
the route uses the same OSM way more than once, you will find it very 
difficult to figure out automatically how the route goes. Bus routes use 
the same way multiple times all the time, and train routes do it as 
well, albeit rarely (Munich's S3 and S7 at Ostbahnhof being an example).

> A work-around would be to check the direction of the LineString right
> after its creation. Something like this:
>
> IF the first noderef of the LineString is identical to the first or
> last noderef of the first referenced way of the underlying relation
> THEN change the LineStrings direction
>
> Right? Or am I wrong again? Please help...
I think you mean "IF the _last_ noderef ... " :)

Yes, that might work. It's still a heuristic though, taking advantage of 
the fact that the probability that the first way member is correct in 
terms of route directionality is higher than that overall relation 
member order is correct.

Still, that assumes that you have exactly one LineString for a route in 
the first place. And as far as I understand the GEOS LineMerger 
documentation, its algorithm won't work for multiply-used ways (at least 
there are some not-so-uncommon cases I am absolutely sure it won't 
work). It won't crash but it'll return multiple geometries which you'll 
need to sew together and orientate with some other algorithm. Which gets 
us back to square one :(

I wouldn't even try to figure it out, I'd fail fast... I would just take 
the relation order and try to assemble it way by way. If it doesn't work 
(you can at least determine _that_ reliably :)), so bad luck, the 
relation is broken, can't render that route. Well, you still can render 
it (it's a bunch of LineStrings after all), but you can't draw arrows 
that show which direction it goes. And you could put a marker on it a la 
KeepRight so someone can go and fix it :)

Bye
Igor



More information about the dev mailing list