Repository navigation
Allow overlapping SpatialRules with priorities - #1903
Conversation
|
@karussell any feedback so far? |
karussell
left a comment
There was a problem hiding this comment.
Thanks! Did you do some performance tests how this affects speed if spatial rules are present? Probably we should add this to our benchmark to see changes.
I'll test it with an import but the The next step after this PR will be to store the active rule IDs in the graph properties in order to drop the Country enum. That should remove the last obstacle for external rule files :) |
Thanks!
But why a special handling for the country? E.g. for road_class we also use the enum for storage. This sounds a bit strange but as we also want enums for a nicer/simpler Java API there is IMO no better solution. |
The user will be able to pass arbitrary rules with custom IDs later. I cannot use enums for this. |
|
Ok. I think we have two requirements here: one is a set of countries (Country enum) and the other are custom areas where we could use integer IDs or even the StringIndex. So even if we make custom areas possible without code we cannot remove the Country enum. |
|
Is there a reason why we should treat country rules differently? We could move them to external files later and use the same mechanism. |
|
Have not a strong opinion about this but "country" is a distinct set of values similar to what we have for road_class. |
|
I've tested the import with a small dataset(Bavaria) and didn't really notice a difference. But i'm going to run the import using the Europe pbf just to be sure. |
|
@karussell anything missing? |
|
Sorry for the delay and yes, time is missing ;) Have already asked @boldtrn to try this out in real world, so we'll have some progress here within the next 3 weeks or so :) |
I think the biggest advantage of using ids is that it's easy to extend and customize. For example one might use countries most of the time, but in the US, we might use states, because rules can differ a lot between states (for example - I have not idea if this is true). Enums are a bit unflexible and hard to change. But with IDs I don't care, I can simply add them. |
|
I had a look at the code and I missed a test case for the overlapping, so I wrote one for @Test
public void testOverlapWitPriority() {
// Let the two polygons overlap
Polygon deBorder = FAC.createPolygon(new Coordinate[] { new Coordinate(1, 1), new Coordinate(2, 1), new Coordinate(2, 2), new Coordinate(1, 2), new Coordinate(1, 1) });
List<SpatialRule> spatialRules = new ArrayList<>();
SpatialRule germany = new AbstractSpatialRule(deBorder) {
@Override
public String getId() {
return "DEU";
}
};
spatialRules.add(germany);
Polygon atBorder = FAC.createPolygon(new Coordinate[] { new Coordinate(0.5, 1), new Coordinate(1.5, 1), new Coordinate(1.5, 2), new Coordinate(0.5, 2), new Coordinate(0.5, 1) });
SpatialRule austria = new AbstractSpatialRule(atBorder) {
@Override
public String getId() {
return "AUT";
}
@Override
public int getPriority(){
return 500;
}
};
spatialRules.add(austria);
SpatialRuleLookupJTS lookup = new SpatialRuleLookupJTS(spatialRules, new Envelope(0, 3, 0, 3));
SpatialRuleSet set = lookup.lookupRules(1.5, 1.25);
assertEquals(2, set.getRules().size());
// Since Austria is priority 500, Germany should be the first, Austria the second
assertEquals(germany.getId(), set.getRules().get(0).getId());
assertEquals(austria.getId(), set.getRules().get(1).getId());
assertEquals(1, lookup.lookupRules(1.5, 0.99).getRules().size());
assertEquals(2, lookup.lookupRules(1.5, 1.00).getRules().size());
assertEquals(2, lookup.lookupRules(1.5, 1.50).getRules().size());
assertEquals(1, lookup.lookupRules(1.5, 1.51).getRules().size());
} |
|
@boldtrn Thank you! I have added your test case and listed you as commit author. |
|
Thanks! The author wouldn't have been necessary :) |
boldtrn
left a comment
There was a problem hiding this comment.
The changes look good to me. Thanks!
This seems to work perfect.
The only thing I haven't compared is the performance.
A minor thing I missed was to specify the priority for example through the geojson, but I think this could be easily added in the future, if that's a desired change in the future.
This is going to be one of the next steps:
|
I thought so :). So I think this should be good to merge. |
| SpatialRule ruleAdj = ruleLookup.lookupRules(nodeAccess.getLatitude(adjNode), nodeAccess.getLongitude(adjNode)).getRules().get(0); | ||
|
|
||
| int baseNode = allEdgesIterator.getBaseNode(); | ||
| SpatialRule ruleBase = ruleLookup.lookupRule(nodeAccess.getLatitude(baseNode), nodeAccess.getLongitude(baseNode)); |
There was a problem hiding this comment.
@otbutz if the first SpatialRule is always available should we provide a convenient method for this? Or will it be rather rare use case?
There was a problem hiding this comment.
No, it is not always available per se. The landmark use case is a bit special in that respect.
There was a problem hiding this comment.
Ok, so if no rule is available the list could be empty (unlike before where you got SpatialRule.EMPTY?)
There was a problem hiding this comment.
Correct. If no rules apply, an empty List is returned.


This PR builds on top of #1880 and restructures the
SpatialRuleLookupinterface to returnSpatialRuleSetswhich cover multiple rules.