Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optional distance tolerance paramter for rtree plugin #28

Merged
merged 5 commits into from
Nov 10, 2023

Conversation

robfitzgerald
Copy link
Collaborator

@robfitzgerald robfitzgerald commented Nov 10, 2023

this PR adds optional "distance_tolerance" and "distance_unit" parameters for the rtree plugin. there is no associated issue so i'll describe the problem here.

problem

currently, if the user loads a road network and then submits a query that is well outside of the road network region, the rtree plugin will still find the nearest vertex. this leads to unexpected behavior where matched origins and destinations may be miles from the user-requested locations.

solution

when the nearest vertex is found, if the optional tolerance is provided, the plugin checks that the vertex found does not exceed the distance tolerance from the query coordinate. if the tolerance is exceeded, the query fails. if no tolerance is provided, then we get the original behavior (tolerance is infinite).

i have updated the osm_default_*.toml files to use a tolerance of 200 meters (0.2km). along the way i also fixed the display implementation for Unit types so that they are not enquoted by double-quotes in their string representation.

example

i have run a national query on a denver road network, where the destination coordinate is in Massachusetts which is 2000+ km outside of the nearest vertex:

$ RUST_BACKTRACE=1 RUST_LOG=debug target/release/routee-compass -c ~/dev/nrel/routee/routee-compass-tomtom/compass_tomtom_denver_energy_smartcore.toml /Users/rfitzger/dev/nrel/routee/routee-compass-tomtom/queries/test_national.json 
...
[2023-11-10T19:30:03Z INFO  routee_compass] Query: Object {"destination_name": String("Jack's Abby Craft Lagers"), "destination_x": Number(-71.4133386), "destination_y": Number(42.2803461), "grid_search": Object {"energy_cost_coefficient": Array [Number(0.0), Number(0.25), Number(0.5), Number(0.75), Number(1.0)]}, "model_name": String("2016_TOYOTA_Camry_4cyl_2WD"), "origin_name": String("NREL"), "origin_x": Number(-105.1710052), "origin_y": Number(39.7402804)}
...
[2023-11-10T19:35:06Z ERROR routee_compass] Error: "coord Coord { x: -71.4133386, y: 42.2803461 } nearest vertex coord is Coord { x: -104.541352, y: 40.044087 } which is 2766.833749832952 kilometers away, exceeding the distance tolerance of 0.2 kilometers"

Copy link
Collaborator

@nreinicke nreinicke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, this is a great improvement, thanks for adding in

@robfitzgerald robfitzgerald merged commit ab15523 into main Nov 10, 2023
5 checks passed
@robfitzgerald robfitzgerald deleted the rjf/rtree-distance-tolerance branch November 10, 2023 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants