Skip to content

Improve HGV access parsing #2744

Open
Open

Description

@otbutz

4df82f5 added a dedicated parser for hgv values but in the current state it doesn't cover all cases.

As the transportation modes follow a hierarchical approach, an access restriction such as motor_vehicle=no would also block trucks unless explicitly overridden by an accompanying hgv tag. A custommodel based on the roads vehicle would therefore need to evaluate both hgv and road_access EVs to make an appropriate decision.

Based on this, a check for fully closed road sections with the roads vehicle would look like the following:

"if": "road_access == NO || hgv == NO", "multiply_by": "0"

This would get more complex if other access types need to be blocked as well, but the main problem with this approach is that road_access is in fact encoding access for a car:

else if (name.equals(RoadAccess.KEY))
return new OSMRoadAccessParser(lookup.getEnumEncodedValue(RoadAccess.KEY, RoadAccess.class), OSMRoadAccessParser.toOSMRestrictions(TransportationMode.CAR));

A road tagged with motorcar:false+hgv=yes would falsely block a HGV vehicle.

Wouldn't it be better to reuse the code from the OSMRoadAccessParser instead? e.g.

 else if (name.equals(RoadAccess.KEY))
            return new OSMRoadAccessParser(lookup.getEnumEncodedValue(RoadAccess.KEY, RoadAccess.class), TransportationMode.CAR);
 else if (name.equals(Hgv.KEY))
            return new OSMRoadAccessParser(lookup.getEnumEncodedValue(Hgv.KEY, RoadAccess.class), TransportationMode.HGV);

The only real problem would be the mismatch between the values of RoadAccess and Hgv.

RoadAccess:

  • CUSTOMERS
  • FORESTRY
  • PRIVATE
  • OTHER

Hgv:

  • MISSING
  • DESIGNATED
  • DISCOURAGED

We would need to move the additional Hgv values into the RoadAccess enum. This would be according to how OSM is treating the values: https://wiki.openstreetmap.org/wiki/Key:access#List_of_possible_values

e.g:

RoadAccess:

  • YES
  • DESTINATION
  • CUSTOMERS
  • DELIVERY
  • FORESTRY
  • AGRICULTURAL
  • PRIVATE
  • DESIGNATED
  • DISCOURAGED
  • OTHER
  • NO

Activity

  1. otbutz commented on Feb 7, 2023

    @otbutz
    ContributorAuthor

    The solution i'm currently experimenting with:

    "if": "car_access == false || hgv == NO", "multiply_by": "0"

    Without car_access i don't get any oneway handling. But this also blocks roads which are open for trucks and blocked for regular cars...

  2. karussell commented on Feb 9, 2023

    @karussell
    Member

    A road tagged with motorcar:false+hgv=yes would falsely block a HGV vehicle.

    this also blocks roads which are open for trucks and blocked for regular cars...

    Do you have some real world examples for these cases?

  3. otbutz commented on Feb 9, 2023

    @otbutz
    ContributorAuthor

    An example from the OSM wiki: access=no + hgv:designated which describes the following restriction:

    shield

    Regular traffic including cars is prohibited but trucks should use this road.

  4. otbutz commented on Feb 9, 2023

    @otbutz
    ContributorAuthor

    But I agree that those combinations are not that common and car_access + hgv is usually enough to cover 99% of the tagged roads.

  5. karussell commented on Feb 20, 2023

    @karussell
    Member

    Probably this is the same issue like #2460.

    When we would have some BooleanEncodedValue like hgv_access it makes sense to include all the "car" and "(motor) vehicle" restrictions and it could also include hgv node tagging. But for the hgv enum it is unclear if "HGV == NO" should be 1:1 with the OSM tag or if it describes the "general hgv access". If the latter, then IMO it would then make sense when "HGV == YES" includes the other "yes" cases like HGV == DESIGNATED but this would be a bit confusing.

    IMO one "xy_access" EncodedValue per transportation mode like hgv_access would be better and this is also simpler to use in a custom model (and car and motor vehicle restrictions would be included), but the hgv enum is still necessary to utilize the information of when HGV should be avoided or preferred and we have to accept that we partially duplicate the hgv=yes/no information (?)

    Now, regarding the oneway information. For #196 I thought a separate bike_oneway was necessary. Also for car_access it make sense to separate the oneway information from car_access. E.g. to model a "police car" and differentiate between reverse directions of oneways and roads that are normally inaccessible by cars. But for car_access the backward compatibility would break and we would have to fix the #1835 before the split. A good solution that would still make this possible and avoid the problems could be to create a function backward(xy_access) and we can have the rather simple usage of just hgv_access. (And this would also avoid the question if roundabout should be included in xy_oneway or not.)

  6. otbutz commented on Feb 20, 2023

    @otbutz
    ContributorAuthor

    I still think that we should translate the raw access values into a simplified version for our routing:

    PREFER -> ALLOW -> AVOID -> BLOCK

    and let the user configure the translation using properties like we handle it with block_private

  7. karussell commented on Feb 20, 2023

    @karussell
    Member

    Not sure what you mean as prefer/avoid has nothing to do with the access and we would still keep the hgv enum (designated/delivery/discouraged..) to implement avoid/prefer in a custom model.

    and let the user configure the translation using properties like we handle it with block_private

    block_private will go away sooner or later as this can be done with a custom model and road_access == PRIVATE

  8. otbutz commented on Feb 20, 2023

    @otbutz
    ContributorAuthor

    Why do we split hgv_access and hgv at all? Access is not a binary decision. We would encode the OSM tag hgv=destination as hgv_access == true and force the author of the custom model to consider hgv == DESTINATION later, because access to that section of the road is obviously different from hgv == YES. This way a custom model has to evaluate the access values at runtime and ultimately use them to determine the priority of the road segment.

    So instead of encoding all access values into the graph and do this classification in the custom model, we could encode the result of this classification instead e.g:

    access priority
    designated PREFER
    yes ALLOW
    destination AVOID
    no BLOCK
  9. karussell commented on Feb 20, 2023

    @karussell
    Member

    Why do we split hgv_access and hgv at all?

    See my reasoning above: either we keep the meaning 1:1 to OSM or we have to ensure that YES also includes the other YES cases and this seems counter intuitive for an enum, so a boolean gives more clarity and we can keep the "hgv OSM tag" meaning.

    force the author of the custom model to consider hgv == DESTINATION later

    Why is that a bad thing? At the end we'll have a custom model that makes such factors explicit and easily configurable.

    This way a custom model has to evaluate the access values at runtime and ultimately use them to determine the priority of the road segment.

    That is exactly the plan :)

    I don't think it will be slow or why do you think this is bad?

    So instead of encoding all access values into the graph and do this classification in the custom model, we could encode the result of this classification instead

    In the future we'll go exactly the opposite way: move things out into a custom model to make things easily customizable instead of mixing things into a single "compound" encoded value where we use static factors. This not only improves flexibility but also the reasoning about a route as every used encoded value can be easily viewed when debugging which is not possible with a "compound" encoded value.

    But of course you can still create your own compound encoded values and use them in a custom model.

  10. otbutz commented on Feb 20, 2023

    @otbutz
    ContributorAuthor

    Sounds reasonable 👍 So we would keep the current hgv EV and add a HgvAccessParser based on AbstractAccessParser/CarAccessParser ?

  11. karussell commented on Feb 20, 2023

    @karussell
    Member

    Probably a clean start might be better and maybe only rely on the "car_access" as EncodedValue? IMO this way the dependencies and differences are easier to identify and at some point we might resolve this inheritance structure for the existing parsers too.

  12. karussell commented on Oct 28, 2024

    @karussell
    Member

    @otbutz can you have a look if the ModeAccessParser and the OSMRoadAccessParser from PR #3056 can satisfy this requirement?

  13. otbutz commented on Oct 29, 2024

    @otbutz
    ContributorAuthor

    Cases like access=no + hgv:designated are still not covered if I'm not mistaken? Would be nice if we could keep it closer to the other transportation modes and introduce hgv_road_access.

  14. karussell commented on Oct 29, 2024

    @karussell
    Member

    You can use hgv identical to a theoretical hgv_road_access and the new OSMRoadAccessParser should work with hgv and also for cases like access=no + hgv:designated.

    Maybe you can try it out if it works or if there are changes to OSMRoadAccessParser necessary?

  15. otbutz commented on Oct 29, 2024

    @otbutz
    ContributorAuthor

    the new OSMRoadAccessParser should work with hgv and also for cases like access=no + hgv:designated.

    #2744 (comment) is still not resolved IMHO.

  16. karussell commented on Oct 29, 2024

    @karussell
    Member

    I thought you could do something like:

    "if": "car_access == false && hgv != YES || hgv == NO", "multiply_by": "0"

    but the oneway restriction is important even for hgv==YES. So this does not work properly.

    We could separate the oneway at some point, but why not use another boolean, let's call it hgv_access, populated from ModeAccessParser?

  17. otbutz commented on Oct 29, 2024

    @otbutz
    ContributorAuthor

    It's a separate transportation mode. Is there a reason to stick with the current HGV enum apart from breaking backwards compatibility? A HGVRoadAccess similar to FootRoadAccess would be a lot cleaner.

  18. karussell commented on Nov 1, 2024

    @karussell
    Member

    Please note, there are two encoded values. One is a boolean xy_access (in the future populated from ModeAccessParser) and the other is an enum xy_road_access populated from OSMRoadAccessParser. Both encoded values are required. The xy_access is still a "compound" encoded value from multiple attributes, but not something the PR changes.

    Now, the hgv encoded value is already the hgv_road_access (except its name) and my question was if this in combination with the boolean hgv_access populated from ModeAccessParser would still serve your needs. (If, how and when we change hgv -> hgv_road_access is also not something the PR changes)

    To better see the similarity you can try to populate hgv via OSMRoadAccessParser (instead of OSMHgvParser) via:

    new OSMRoadAccessParser<>(lookup.getEnumEncodedValue(Hgv.KEY, Hgv.class), OSMRoadAccessParser.toOSMRestrictions(TransportationMode.HGV), (readerWay, access) -> access, Hgv::find)

    Yes, this will ignore the ~900 conditional ways world-wide tagged with hgv:conditional, but I doubt this is/was important.

  19. otbutz commented on Nov 4, 2024

    @otbutz
    ContributorAuthor

    That sounds good. So we get rid of most of the car/hgv ambiguity, while still retaining the ability to handle oneways etc via hgv_access.

  20. karussell commented on Sep 16, 2026

    @karussell
    Member

    I have now created hgv_road_access which is similar to road_access except that it replaces motorcar with hgv when evaluating the restrictions:

    9710656

    ddd5c9b

    This is a first step to make merging xy_access with xy_road_access enums easier.

    Now, the hgv encoded value is already the hgv_road_access (except its name)

    This was not true.

  21. otbutz commented on Sep 17, 2026

    @otbutz
    ContributorAuthor

    Awesome 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions