StrandedKitty / streets-gl

🗺 OpenStreetMap 3D renderer powered by WebGL2
http://streets.gl
MIT License
604 stars 45 forks source link

driving side of road and (2 way, asymmetric lane count) road markings #77

Open cebderby opened 1 year ago

cebderby commented 1 year ago

With the numbers of lanes in each direction being shown, I noted that UK (driving left side) lane markings on 2-way roads with an asymmetric number of lanes (eg 2 forward, 1 backward) are currently the wrong side (ie are as if we drive on the right).

Example here with 2 lanes approaching the junction in all 4 directions and so the 2 lanes side should be on the left heading towards the crossroads: https://streets.gl/#52.58080,-1.91320,46.25,351.25,339.55 Another UK example with a 3 lane (2 way) road that locally divides to 2x separately mapped oneways and back again so can see the inconsistency: https://streets.gl/#50.86226,0.03249,22.74,310.00,168.98

I checked a case in France (driving right side) and all is well here: https://streets.gl/#50.63563,3.07818,38.50,109.75,163.79

And to check another country that drives left, there are some 3 lane roads here in Wellington NZ which are currently reversed compared to imagery: https://streets.gl/#-41.29266,174.77371,82.49,6.00,238.15

I think @dabreegster must have dealt with this in osm2streets so may know a decent way of handling it, ie. determining what country we're in and having a lookup table for driving left vs right (or a list of all the left-ies)

For now, I think these (quite few) asymmetric lane count 2-way roads are the only thing affected, but if you ever want to refine the road markings for stop/give way lines or anything more then it would immediately be a big deal.

dabreegster commented 1 year ago

https://github.com/a-b-street/country-geocoder is how osm2streets solves it. (Not on crates.io today, but I could publish quickly if it's helpful.) It's based on @westnordost's work, and actually he recently published a Rust port https://github.com/westnordost/country-boundaries-rust. You could call either one from JS with only a little build magic. (I use https://github.com/nshen/vite-plugin-wasm-pack for Vite, don't know the equivalent for webpack)

Or the approach is quite simple; load a GeoJSON (or TopoJSON for file size savings) file with all country boundaries and a list of left-handed countries (https://github.com/streetcomplete/countrymetadata/raw/master/data/isLeftHandTraffic.yml), then find the polygon containing a point. I've hit problems with looking up points near the coast (https://github.com/a-b-street/country-geocoder/issues/1) -- maybe Tobias knows how to handle that better

StrandedKitty commented 1 year ago

That's a real shame tags like lanes:forward and lanes:backward are used, lanes:left and lanes:right would be so much easier to render.

@dabreegster Is this really how many countries have reversed traffic? I thought there was like 4 of them...

So I guess that we need a different dataset that correctly handles coasts? Maybe I can just take the one from your repo (a-b-street/country-geocoder) and build a voronoi diagram of it?

westnordost commented 1 year ago

@dabreegster Is this really how many countries have reversed traffic? I thought there was like 4 of them...

Note that the United Kingdom "owns" quite a lot of ISO country codes, because every one of their overseas territories and even things like the Isle of man do have an own country code.

So I guess that we need a different dataset that correctly handles coasts? Maybe just take the one from your repo (a-b-street/country-geocoder) and build a voronoi diagram of it?

Well, it depends on the data you use. a-b-street/country-geocoder uses some really low-polygon natural earth data (by default?). https://github.com/westnordost/country-boundaries-rust by default uses the ... well, all you know need to know is in the readme. You can also use any other data, you just would need to preprocess it with the program mentioned in the readme.

westnordost commented 1 year ago

By the way, do look at https://github.com/streetcomplete/countrymetadata/tree/master/data more - you may find some information there to be useful for visualization. E.g. the color and appearance of lane markings are different in different countries.

dabreegster commented 1 year ago

Is this really how many countries have reversed traffic? I thought there was like 4 of them...

Apparently yes! https://en.wikipedia.org/wiki/List_of_countries_with_left-hand_traffic

a-b-street/country-geocoder uses some really low-polygon natural earth data (by default?).

Correct, https://github.com/a-b-street/country-geocoder/blob/6a4fd01c948f0fb9f67377343a4893cc3e43ba15/generate_data.py#L10

dabreegster commented 1 year ago

That's a real shame tags like lanes:forward and lanes:backward are used, lanes:left and lanes:right would be so much easier to render.

Wait till you get to the joy of bus lane tagging, using 3 schemas... smoothing over the tagging differences is one goal of the lane-parsing piece of osm2streets.

you may find some information there to be useful for visualization. E.g. the color and appearance of lane markings are different in different countries

FWIW, customizing lane width and marking style based on locale has been on the osm2streets TODO for ages. I may get some time soon to work on it again, since it's going to become a dependency of a current work project, but still lots of polish needed