I am having an issue using the route web API. What I want is to get the shortest path between two points, so I use weighting = shortest. Another requirement is that my customers need to be able to close roads, meaning that they submit a coordinate, and I ensure that that coordinate is avoided. The way I have implemented this is by drawing a square around that point, and then mapping it to a custom model, where I set the priority to zero.
However, it seems that one of these two are not working (shortest weighting or closing a road). When I post the following json:
{
"points": [
[
9.974817036680832,
56.15063242652721
],
[
9.606132685260434,
56.165955689633904
]
],
"profile": "truck",
"ch.disable": true,
"debug": false,
"calc_points": false,
"instructions": false,
"custom_model": {
"areas": {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
9.754235338325909,
56.15088662234999
],
[
9.747784661674093,
56.15088662234999
],
[
9.747784661674093,
56.147293377650016
],
[
9.754235338325909,
56.147293377650016
],
[
9.754235338325909,
56.15088662234999
]
]
]
},
"id": "spaerring0"
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
9.619902611394895,
55.93195337765002
],
[
9.626317388605106,
55.93195337765002
],
[
9.626317388605106,
55.93554662234999
],
[
9.619902611394895,
55.93554662234999
],
[
9.619902611394895,
55.93195337765002
]
]
]
},
"id": "spaerring1"
}
]
},
"priority": [
{
"if": "in_spaerring0",
"multiply_by": "0"
},
{
"if": "in_spaerring1",
"multiply_by": "0"
}
]
},
"weighting": "shortest"
}
I get this result back:
{
"hints": {
"visited_nodes.sum": 1080,
"visited_nodes.average": 1080.0
},
"info": {
"copyrights": [
"GraphHopper",
"OpenStreetMap contributors"
],
"took": 3,
"road_data_timestamp": "2024-09-21T17:00:00Z"
},
"paths": [
{
"distance": 24998.667,
"weight": 1727.025036,
"time": 1249956,
"transfers": 0,
"points_encoded": true,
"points_encoded_multiplier": 100000.0,
"snapped_waypoints": "w|uuIqe{{@q~A|~fA"
}
]
}
But without the custom model I get this:
{
"hints": {
"visited_nodes.sum": 1080,
"visited_nodes.average": 1080.0
},
"info": {
"copyrights": [
"GraphHopper",
"OpenStreetMap contributors"
],
"took": 4,
"road_data_timestamp": "2024-09-21T17:00:00Z"
},
"paths": [
{
"distance": 24998.667,
"weight": 1727.025036,
"time": 1249956,
"transfers": 0,
"points_encoded": true,
"points_encoded_multiplier": 100000.0,
"snapped_waypoints": "w|uuIqe{{@q~A|~fA"
}
]
}
Which has a higher distance. How can this be true when I use shortest as the weighting? Am I supposed to do something else to get the shortest weighting?
Below you will find my custom model and my points drawn in geojson.io.