I am using OSM data for a programming task I'm working on, and one thing I've noticed is that often, major streets that have a barrier or divider in the middle are represented as two separate, parallel ways - one way for each direction. This behavior is not desirable for the particular program I'm writing, so I want parallel ways to be merged into a single way running down the center of the street. It seems like a fairly simple problem, but I'm having a trouble getting the program to identify ways that need to be merged and then merge them properly. Right now, the program looks for ways that need to be merged by looking at pairs of ways, using the first and last node of each way to figure out the angle at which it is oriented. If the ways are oriented at a similar angle and are close enough that small rectangles drawn around them would overlap, then the program will try to merge the two ways. Unfortunately this technique doesn't work as well as I'd like it to in practice - it's pretty inefficient (as it would need to compare lots of pairs in a large map) and there are many edge cases in which it fails, like when one side consists of a single long way and the other side consists of multiple short ways. Is there an easier way to accomplish this? Perhaps with an existing tool, or something obvious I haven't thought of? asked 19 Jun '15, 21:19 tongning |
Yep this is intentional. The idea being that if you could physically (as opposed to legally) do a U-turn in a road, then you should map it as one OSM way, if you cannot (due to walls/barriers) then it should be 2 separate ways in OSM, with appropriate one way tags. This also makes much more sense for motorways, which will have complicated junctions which only merge into one "lane". To solve your problem, I can give some hints: Many of these "split roads" will have For example, this road and this road are one "split road". You'll notice they both are mapped
Perhaps, rather than trying to merge the 2 OSM ways, you could just use the approach I gave to detect "probably split roads", and then only add the sidewalk in one direction? i.e. the direction of the road itself? answered 22 Jun '15, 09:04 rorym |
I suspect that first merging ways that have been split along the length of the road would help a bit, naturally there is no guaranteee that the geometry of say a footway actually is parallel to the real road surface. ASCII art of such a situation:
F=footway 1 f=footway 2 R=Road F and f woudn't be mergeable without splitting at X. PS: in an answer becase markdown doesn't work in comments. answered 20 Jun '15, 07:45 SimonPoole ♦ |
Your question/issue is just a trivial case of the problem what we inevitably meet in vector map-making. Namely, in a road class, road sections are often presented by two "parallel" poly-line segments, one per direction. More precisely, the distance between the two "parallel" poly-line segments is never larger than a critical (parameter) distance "d". For illustration assume the primary road class and d=10m. In the data preparation, when creating the vector scale-levels, when the scale factor is less than 1:20000 the distance will vary between 0 and 2 pixels on a 120dpi rendering display. This has a bad aesthetic consequence end data redundancy in transmission and client rendering. Therefore, in the data preparation we try to detect and eliminate the parallel cases (the phase/step just before the vector smoothing). answered 30 Jun '15, 11:53 sanser |
I'd be interested in hearing about what you are doing where merging those ways would be advantageous.
In OSM those parallel ways will generally be marked with a oneway tag, perhaps that can help identify the ways of interest.
Interesting suggestion, thanks! As for the program, it tries to predict where sidewalks and crosswalks should be located, as part of a project to improve accessibility. It's written in Python and generates geojson output showing predicted crosswalk and sidewalk locations when fed an OSM file as input. It should be putting sidewalks on each side of a street, of course, but when there are two parallel ways it tries to put four sidewalks rather than two.
Tags should be a good option, no? I've just checked such a double-way next to my place and realized that it was also tagged < lane=2 >. A combination of tags could help reduce the number of ways to compare... But you certainly have looked at tags carefully yet.