a-b-street / osm2lanes

A common library and set of test cases for transforming OSM tags to lane specifications
https://a-b-street.github.io/osm2lanes/
Apache License 2.0
34 stars 2 forks source link

Create an offline geocoder to determine driving side from a coordinate. #261

Closed dabreegster closed 2 years ago

dabreegster commented 2 years ago

Part of https://github.com/a-b-street/osm2streets/issues/80. Today we require the user to specify the driving side, or we attempt to query it from Overpass (but that seems to be flaky). It's much simpler to just see if some point within an imported area is within the polygon of a left-sided country or not.

See README.md for data sources and inspiration. I've got this tested end-to-end in osm2streets; a PR for that will be coming momentarily. I think we can later cleanup more things in osm2lanes based on this.

I'd like to later split out driving-side into its own repo and put it on crates.io, since it's of standalone value. But first I'd generalize it and return the ISO country code, not just left/right driving side -- aka, make a Rust port of https://github.com/westnordost/countryboundaries. I'd also add benchmarks and try out some optimizations. But for now, driving-side is fast enough and has immediate massive value to osm2streets and A/B Street.

dabreegster commented 2 years ago

Feel free anyone to review asynchronously. To avoid PRs in a few repos stacked on each other and to make progress on the original bug I was working on (yak-shaving is fun when it's this easy and beneficial!), I'm going to merge now

github-actions[bot] commented 2 years ago

Benchmark for bf65ecc

Click to view benchmark | Test | Base | PR | % | |------|--------------|------------------|---| | tests/224637155 | 5.4±0.00µs | 5.4±0.00µs | 0.00% | | tests/380103730 Japanese Expressway | 7.2±0.06µs | 7.2±0.21µs | 0.00% | | tests/389654080 | 8.8±0.01µs | **8.7±0.18µs** | **-1.14%** | | tests/49207928 cycleway:BACKWARD=lane | 6.7±0.03µs | **6.6±0.00µs** | **-1.49%** | | tests/8591383 a bidirectional cycleway, oneway:bicycle | 7.3±0.02µs | 7.3±0.01µs | 0.00% | | tests/bus:lanes=designated\| | 7.0±0.01µs | **6.7±0.01µs** | **-4.29%** | | tests/busway=lane | **6.0±0.01µs** | 6.1±0.01µs | **+1.67%** | | tests/cycleway=lane | **6.2±0.01µs** | 6.3±0.01µs | **+1.61%** | | tests/cycleway=opposite oneway=yes oneway:bicycle=no | **5.8±0.01µs** | 5.9±0.01µs | **+1.72%** | | tests/cycleway=opposite_track oneway=yes, deprecated | **6.8±0.01µs** | 6.9±0.00µs | **+1.47%** | | tests/sidewalk:right=yes | 5.5±0.00µs | 5.5±0.10µs | 0.00% | | tests/sidewalk=both | 5.7±0.01µs | 5.7±0.02µs | 0.00% |