Repository navigation
Custom area support - #2201
Custom area support#2201otbutz wants to merge 29 commits into
Conversation
|
Our unittests run without any of the Mixin interfaces which explains why my previous attempts failed. Switching to a GraphHopperConfig subclass with annotated method overrides seems to fix the issue. |
|
Thanks. This is a big change. Would you mind to split this up? E.g. move the StringEncodedValue into a separate PR before? |
|
@karussell i moved StringEncodedValue related changes into #2204 |
|
@karussell what do you think about the configuration approach? custom_area_files:
- location: core/files/spatialrules/countries.geojson
id_field: "ISO3166-1:alpha3"
encoded_value: country
encoded_value_limit: 63
max_bbox: -180,180,-90,90**I'm not sure if it's better to define the StringEncodedValues with their size elsewhere but that would add additional bloat to the GraphHopperConfig |
|
@karussell could you take a look and give me some feedback? |
|
@karussell should i rebase? |
|
Thanks again and sorry for the silence here. Will review it in the next week. Maybe unrelated, but currently I have no clear view on how to bring together the concepts of spatial rules, custom areas and custom models. See also #1280 and #1808. Especially after this change that can be combined with custom models the spatial rules look somehow redundant (?) or maybe a spatial rule is only a specific custom model at import time? |
The real benefit of spatial rules stems IMHO from the ability to manipulate the encoded values. Custom models only affect the routing itself but don't reflect in e.g the PathDetails. #2164 is a good example for what could be done with spatial rules. One could come up with a custom model which provides country specific toll rules but a client won't be able to retrieve this information later on in the form of "how many toll kilometers did the vehicle travel?". Using a spatial rule this information could easily be gathered from the PathDetails.
Custom areas can easily handle very huge and detailed border polygons without a performance impact at runtime. See #2037 |
Yes and IMO this is similar to a custom model. Sure, it does not store the calculated information into an encoded value but I could think of a custom model where this is possible: max_speed:
- if: country == DE
set to: 120Especially as we have the list of areas where I could think of one "import-model" per country or something like this.
This would be an interesting feature in general: on-the-fly statistics similar to path details but defined in the custom model: details:
- toll distance:
- if: toll != NO
add: distance
Yes. Likely we need something separate, but it could be very similar to a custom model, especially when we allow to define spatial rules in a file, but also in the Java API. |
That sounds like a workable approach. That would be enough to retire spatial rules and replace them with custom models. So how do we move forward with this? I'm going to drop the spatial rules from the GraphHopperConfig in my PR. It doesn't make sense to put them there if we want to replace them later on. |
6629736 to
3c5a386
Compare
There was a problem hiding this comment.
Is it possible to move the encoded value definition to graph.encoded_values? Then we could define it like encoded_values=country|limit=63,surface,... and we have all explicit encoded values in one place and would need to use it for the custom area.
And is max_bbox still necessary? I think I saw some PR where this requirement was removed, but maybe I mix something up.
There was a problem hiding this comment.
Is it possible to move the encoded value definition to
graph.encoded_values? Then we could define it likeencoded_values=country|limit=63,surface,...and we have all explicit encoded values in one place and would need to use it for the custom area.
I wasn't sure which option is better. From a configuration standpoint it was nice to have it in one place. But i think you're right and it's easier to configure/maintain if we manage it with the other EVs.
And is max_bbox still necessary? I think I saw some PR where this requirement was removed, but maybe I mix something up.
It's an optimization which allows to skip country boundaries which are not relevant for the imported dataset. e.g importing an europe.pbf while using the global country boundaries file in our repo.
There was a problem hiding this comment.
@karussell should we keep some kind of prefix for all custom area EVs?
e.g encoded_values=custom_area.country|limit=63,custom_area.state|limit=127,surface,...
My current approach is to create EncodedValues with a namespace using EncodingManger.getKey(String,String). This makes it easier to retrieve the correct EV for the PathDetailsBuilder later:
for (String checkPrefix : requestedPathDetails) {
if (checkPrefix.startsWith(CustomArea.key("")) && evl.hasEncodedValue(checkPrefix))
builders.add(new StringDetails(checkPrefix, evl.getStringEncodedValue(checkPrefix)));
}Adding a prefix looks a bit verbose but without it we'd have to treat any unknown key as a custom area encoded value and that would also include typos...
The same problem arises if we want to create the EV in the DefaultEncodedValueFactory.
If we want to add other types of "dynamic" EVs in the future, we have to come up with a manageable solution.
Edit: no idea why Github thought it would be a good idea to auto-submit my half typed
comment
There was a problem hiding this comment.
It's an optimization which allows to skip country boundaries which are not relevant for the imported dataset. e.g importing an europe.pbf while using the global country boundaries file in our repo.
Can you explain what you mean here? Do you mean geometries outside of max_bbox will be skipped?
should we keep some kind of prefix for all custom area EVs?
Yes, probably we need some identification like we have for RouteNetwork but a dot is not possible. I suggest a postfix like there e.g. country_area? But then it would be ugly in our script in_area_country_area :D ... so probably we should change it there too? (probably even independent of this PR to merge it fast)
There was a problem hiding this comment.
in_area_country_area
Ah, no. This would not be a problem. Still I would change it to in_xy_area for consistency I guess.
There was a problem hiding this comment.
It's an optimization which allows to skip country boundaries which are not relevant for the imported dataset. e.g importing an europe.pbf while using the global country boundaries file in our repo.
Can you explain what you mean here? Do you mean geometries outside of max_bbox will be skipped?
Exactly. Editing large geojson files is rather error prone so the user might for example use a big geojson file with lots of features while he only needs a specific subset for the small pbf dataset he wants to import. e.g using our world boundaries file while importing a DACHL pbf
I've just added a commit to also take this into account if the user doesn't provide an encoded_value_limit. The size of the resulting encoded value is therefore determined by the number of custom areas intersecting the bounding box.
Note that the bbox is also used to modify the polygons by calculating an intersection:
should we keep some kind of prefix for all custom area EVs?
Yes, probably we need some identification like we have for RouteNetwork but a dot is not possible. I suggest a postfix like there e.g.
country_area? But then it would be ugly in our scriptin_area_country_area:D ... so probably we should change it there too? (probably even independent of this PR to merge it fast)
_area looks good
There was a problem hiding this comment.
Isn't this more a CustomAreaConfig and why is this separate from CustomArea?
There was a problem hiding this comment.
Should i merge them and keep location in the CustomArea? This field is only used to point to file and is not needed anymore after the border polygons have been loaded in GraphHopperManaged.
There was a problem hiding this comment.
Removing CustomAreaFile leads to the Dropwizard issue i mentioned earlier, except that i can't ignore the customAreas field as a workaround anymore.
There was a problem hiding this comment.
As this replaces the SpatialRules should we rename the PR to make spatial rules customizable (CustomArea)?
And can we somehow avoid the name clash with the other CustomArea class?
For future reference can you also list the renamed classes here as github somehow fails to catch all some of them. E.g. SpatialRuleLookupJTS, SpatialRuleLookupHelper (?) This would also help which classes I can skip when reviewing.
And why did you choose to keep some of the classes the same name like SpatialRuleSet? Could it make sense to rename it also to CustomAreaRules or something? Also the name for CountriesSpatialRuleFactory seems not consistent.
There was a problem hiding this comment.
As this replaces the SpatialRules should we rename the PR to
make spatial rules customizable (CustomArea)?
The SpatialRules are still there - at least until we fully replace them with CustomModels later on. The only thing that changed is that they don't provide their own border polygons anymore. SpatialRules only get applied now if their ID matches the one of a CustomArea.
And can we somehow avoid the name clash with the other CustomArea class?
I think you're referring to com.graphhopper.routing.ev.CustomArea ? I can move the prefix and EV key creation into the regular CustomArea and delete this one.
For future reference can you also list the renamed classes here as github somehow fails to catch all some of them. E.g. SpatialRuleLookupJTS, SpatialRuleLookupHelper (?) This would also help which classes I can skip when reviewing.
And why did you choose to keep some of the classes the same name like SpatialRuleSet? Could it make sense to rename it also to CustomAreaRules or something? Also the name for CountriesSpatialRuleFactory seems not consistent.
CustomAreaRule sounds good. I'm going to rename the remaining classes accordingly.
|
I think we got it all covered. |

add support for StringEncodedValuessee StringEncodedValues #2204