-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
SpatialRule interface rework #1880
Conversation
bdbc05e
to
a50b674
Compare
f5fc729
to
9c32c17
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Looks good.
Can you move the RoadClass changes into another PR? E.g. we could add also platform
or crossing
and more: https://taginfo.openstreetmap.org/keys/highway#values
merge DefaultSpatialRule into AbstractSpatialRule
What is the reason here?
allow rules to overwrite existing values instead of only being used as a fallback
Can you link to the code change here?
Sure. I thought about adding other values but hesitated as we use the RoadClass for encoding and i didn't want to blow up the size of the graph for unused values. It's something different though if you already have plans for them.
Except for
OSMMaxSpeedParser: The rule was only used if no max speed was present. OSMRoadAccessParser: The rule was only used if the road access wasn't already restricted. |
So as soon as we are over 15 distinct values it does not matter if we have 16 or 31 :)
Yes, I like this. But I do not like the car centric view for the default, as this might be misleading. Even road-centric might be wrong. But not so sure if this is a problem as it is in the abstract class...
Ah, ok. This makes sense and I like it. Still should we add it to the changelog as it is a breaking change (?) |
It's the same for
Indoor navigation or what is the use case here?
Which is still subject to change 😉
I can modify the two existing rules in order to follow the old fallback logic if that's better. |
I found the following possible candidates:
|
9c32c17
to
eeadcd5
Compare
E.g. rail routing
👍
Sorry, I think we need to revert this. The problem is that a more specific information on the road should not be overwritten from the country-specific default.
Hmmh, yeah. For multiple max_speed values like for truck we could introduce max_speed_truck? Not sure. |
SpatialRules should be able to overwrite existing values but our existing country rules are only intended as a fallback strategy. I'm going to rework the interface to take this into account.
We could follow the OSM tagging standard and add support for |
c32029b
to
6b033e5
Compare
Thanks - I like the reworked interface with the maxSpeed as a parameter and return type! Which allows the SpatialRule to adapt or overwrite the provided maxSpeed. But for which code part or use case do we need the new getDefaultAccess and getDefaultMaxSpeed methods? |
I can move them as |
Really nice work @otbutz 👍.
Are there currently default values like in the DefaultSpatialRule in the AbstractSpatialRule class, not sure if I overlooked this? The idea of the DefaultSpatialRule was to remove some of the code duplication that we would add for almost all countries and only change them, if something differs. On the other hand, having everything setup per country makes it easier to understand the code without always checking the hierarchy values. We still only support Ger and Aut where we already have quite some duplication. I think once we add 10-20 countries, we will copy paste a lot of boiler plate code for every country. So I think I would favor to have the common values set up in some parent class.
Yes, I think this would be good, I also stumbled over this when reading the interface :). |
Having to compare two classes in order to check which values are being used, is a rather tedious and error prone process. If we keep the logic down to a simple switch-case it's easier to have each rule define its all values IMHO. |
Yes, that's a valid argument as well. I am just a bit unsure, since many countries share the same values or some default values will almost always apply. For example, for motor vehicles, this will be almost always be copied, which is not that nice IMHO:
But, it's not a big issue for me, we can always refactor this when we see that it starts to become an issue, it doesn't change the interface. |
But why do we need this method? I would found it more transparent if all SpatialRules would do all the work (same argument 'Having to compare two classes in order to check which values are being used'). But to reduce some minor code duplication I would find it acceptable if it is removed from the interface and is package protected in AbstractSpatialRule. |
If we want external rule files, we have to settle for a subset of possible input variables to determine the values for maxspeed/access/etc. We could use this approach for the interface and use a more restricted one for file based rules but i'm not sure if we want to stick to code based spatial rules in the future. |
6b033e5
to
f32f4b0
Compare
@otbutz Thanks for the changes. Regarding the method return type: why do we return -1 and do not return currentMaxSpeed (or the currentAccess)? With that could avoid the separate getDefaultMaxSpeed method and make this method final: public class AustriaSpatialRule ...
@Override
public final double getMaxSpeed(RoadClass roadClass, TransportationMode transport, double currentMaxSpeed) {
if (currentMaxSpeed > 0 || transport != TransportationMode.MOTOR_VEHICLE) {
return currentMaxSpeed;
}
switch...
...
} And e.g. for |
Good catch. I will change both methods to return the current value in AbstractSpatialRule.
I already removed them but forgot to push my rebased branch. sigh...
For both AustriaSpatialRule and GermanySpatialRule: if (currentRoadAccess != RoadAccess.YES) {
return currentRoadAccess;
} So if there is any restriction it will stick to it. For AbstractSpatialRule you're right. |
f32f4b0
to
eebb99b
Compare
core/src/main/java/com/graphhopper/routing/util/spatialrules/countries/GermanySpatialRule.java
Outdated
Show resolved
Hide resolved
Ah, thanks, no worries :) ! Looks good now. |
core/src/main/java/com/graphhopper/routing/util/spatialrules/countries/GermanySpatialRule.java
Show resolved
Hide resolved
Thanks @otbutz ! |
This PR aims to improve our current spatial rule interface.
Summary of the changes:
getId()
getMaxSpeed()
andgetAccess()