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

Turn-by-turn parameter "exclude_polygons" doesn't seem to work, 3.4.0 #4659

Open
a3rtgm-ds opened this issue Mar 26, 2024 · 4 comments
Open
Labels
troubleshooting a request to help debug an issue with the software

Comments

@a3rtgm-ds
Copy link

a3rtgm-ds commented Mar 26, 2024

Cheers,

I'm facing an issue with the exlude_polygons parameter. No matter what I do, the polygons are just ignored when calculating the route.
I tried:

  • several routes as well as polygons.
  • avoid_polygons as well as exclude_polygons
  • GET and and POST method.
  • I even checked what happens if I change the max_exclude_polygons_length in valhalla.json: It recognizes that the polygon perimeter is too long, but if set correctly still ignores it.

This is my request body as send via POST to http://localhost:8000/route:

{
    "locations": [
        {
            "lat": 53.58057720517453,
            "lon": 9.963296614329304
        },
        {
            "lat": 53.559049291307375,
            "lon": 9.94031099409257
        }
    ],
    "costing": "auto",
    "units": "kilometer",
    "exclude_polygons": [
        [
            [
                10.00117041454449,
                53.5863817221415
            ],
            [
                10.008862952800815,
                53.58892866828994
            ],
            [
                10.012118863375917,
                53.584903008050084
            ],
            [
                10.00202911515473,
                53.582596393422726
            ],
            [
                10.000156668420933,
                53.58468367276585
            ],
            [
                10.00117041454449,
                53.5863817221415
            ]
        ],
        [
            [
                9.95400692524349,
                53.57376955479453
            ],
            [
                9.963818328458117,
                53.57041413262857
            ],
            [
                9.9556777094013,
                53.5652222028617
            ],
            [
                9.94444436558794,
                53.56794487947813
            ],
            [
                9.95400692524349,
                53.57376955479453
            ]
        ],
        [
            [
                9.961423015970604,
                53.579558276534776
            ],
            [
                9.967208236519298,
                53.57759824820427
            ],
            [
                9.957685660953539,
                53.577142414948675
            ],
            [
                9.961423015970604,
                53.579558276534776
            ]
        ],
        [
            [
                9.945119787225885,
                53.56241491954112
            ],
            [
                9.9504520688648,
                53.56055736461627
            ],
            [
                9.947537086439002,
                53.55844640942041
            ],
            [
                9.941031701902205,
                53.56144393615054
            ],
            [
                9.945119787225885,
                53.56241491954112
            ]
        ],
        [
            [
                9.958201653622325,
                53.57661828782614
            ],
            [
                9.962076448930198,
                53.5753733086931
            ],
            [
                9.960370117087333,
                53.5733052983731
            ],
            [
                9.957917264330936,
                53.57486686715341
            ],
            [
                9.958201653622325,
                53.57661828782614
            ]
        ]
    ],
    "language": "en-US"
}

And this is the result, decoded to geojson:
image

I'm using https://download.geofabrik.de/europe/germany/hamburg-latest.osm.pbf to build the graph.

I thought it might be a version issue. I am using the docker image provided by gis-ops, version 3.4.0, but I couldn't find any related issues with that version. Maybe that fix caused the issue 3907?

Thanks in advance. Probably just stupidity at my part 😅

@nilsnolde
Copy link
Member

it still works on https://valhalla.openstreetmap.de/ (you can create a polygon with right toolbar). so just do that, look at the network console and compare to your request. the parameters seem fine (list of rings), but you're sure that's how you actually sent it to valhalla?

you're on latest image and pulled recently right?

@a3rtgm-ds
Copy link
Author

@nilsnolde Thanks! I did what you suggested and got a working result with my docker environment.

There were 2 main differences I found:

  1. The demo server nests the exclude_polygon like so:
{
    "costing_options": {
          "auto": {
              "exclude_polygons": my_coord_list // that does the trick
    },
    "exclude_polygons": my_coord_list // seems to be redundant
}

So the param appears double in the request. The API docs kinda suggest that it should live on the top level of the object, but that seems to be redundant. If I remove the one nested under costing_options it doesn't work anymore. Not sure what the intended behavior is. Maybe it should be clarified in the docs.

  1. your polygon is only an open linear ring, i.e. you don't repeat the last vertex, as a geojson would. But I found that both seem to work fine, if the param is at the right spot.

Thanks again, sorry to bother and I hope my comments are any helpful.

Cheers

@a3rtgm-ds
Copy link
Author

Little correction. That doesn't seem to be it. So far, I'm still not sure which combination actually works 😅
I'll post it here when I'm wiser.

@nilsnolde
Copy link
Member

So the param appears double in the request

🙄 man that web app needs a make-over..

The API docs kinda suggest that it should live on the top level of the object, but that seems to be redundant. If I remove the one nested under costing_options it doesn't work anymore.

it should appear top-level, that's what the code suggests:

valhalla/src/worker.cc

Lines 1060 to 1083 in 6f9f637

auto rings_req =
rapidjson::get_child_optional(doc, doc.HasMember("avoid_polygons") ? "/avoid_polygons"
: "/exclude_polygons");
if (rings_req) {
if (!rings_req->IsArray()) {
add_warning(api, 204);
} else {
auto* rings_pbf = options.mutable_exclude_polygons();
try {
for (const auto& req_poly : rings_req->GetArray()) {
if (!req_poly.IsArray() || (req_poly.IsArray() && req_poly.GetArray().Empty())) {
continue;
}
auto* ring = rings_pbf->Add();
parse_ring(ring, req_poly);
}
} catch (...) { throw valhalla_exception_t{137}; }
}
} // if it was there in the pbf already
else if (options.exclude_polygons_size()) {
for (auto& ring : *options.mutable_exclude_polygons()) {
parse_ring(&ring, rapidjson::Value{});
}
}

your polygon is only an open linear ring, i.e. you don't repeat the last vertex, as a geojson would. But I found that both seem to work fine, if the param is at the right spot.

we check the open-ness in valhalla and correct it, so both is fine technically.

@nilsnolde nilsnolde added the troubleshooting a request to help debug an issue with the software label Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
troubleshooting a request to help debug an issue with the software
Projects
None yet
Development

No branches or pull requests

2 participants