Skip to content

Commit

Permalink
bug fix for max_weight parsing and fixes for max_weight_except
Browse files Browse the repository at this point in the history
  • Loading branch information
karussell committed Nov 18, 2024
1 parent fbd89db commit e83332e
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### 11.0 [not yet released]

- max_weight_except: changed NONE to MISSING
- the list of restrictions for BIKE returned from OSMRoadAccessParser.toOSMRestrictions is again `[bicycle, vehicle, access]` and not `[bicycle, access]` like before #2981
- road_access now contains value of highest transportation mode for CAR, i.e. access=private, motorcar=yes will now return YES and not PRIVATE
- car.json by default avoids private roads
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/
public enum MaxWeightExcept {

NONE, DELIVERY, DESTINATION, FORESTRY;
MISSING, DELIVERY, DESTINATION, FORESTRY;

public static final String KEY = "max_weight_except";

Expand All @@ -23,12 +23,16 @@ public String toString() {

public static MaxWeightExcept find(String name) {
if (name == null || name.isEmpty())
return NONE;
return MISSING;

// "maxweight:conditional=none @ private" is rare and seems to be known from a few mappers only
if (name.equalsIgnoreCase("permit") || name.equalsIgnoreCase("private"))
return DELIVERY;

try {
return MaxWeightExcept.valueOf(Helper.toUpperCase(name));
} catch (IllegalArgumentException ex) {
return NONE;
return MISSING;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public OSMMaxWeightParser(DecimalEncodedValue weightEncoder) {
public void handleWayTags(int edgeId, EdgeIntAccess edgeIntAccess, ReaderWay way, IntsRef relationFlags) {
OSMValueExtractor.extractTons(edgeId, edgeIntAccess, way, weightEncoder, MAX_WEIGHT_TAGS);

// vehicle:conditional no @ (weight > 7.5)
// vehicle:conditional = no @ (weight > 7.5)
for (String restriction : HGV_RESTRICTIONS) {
String value = way.getTag(restriction, "");
if (value.startsWith("no") && value.indexOf("@") < 6) { // no,none[ ]@
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static double conditionalWeightToTons(String value) {
}
if (index > 0) {
int lastIndex = value.indexOf(')', index); // (value) or value
if (lastIndex < 0) lastIndex = value.length() - 1;
if (lastIndex < 0) lastIndex = value.length();
if (lastIndex > index)
return OSMValueExtractor.stringToTons(value.substring(index, lastIndex));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ public void testConditionalTags() {
readerWay.setTag("highway", "primary");
readerWay.setTag("hgv:conditional", "no @ (weight > 7.5)");
parser.handleWayTags(edgeId, edgeIntAccess, readerWay, relFlags);
assertEquals(MaxWeightExcept.NONE, mwEnc.getEnum(false, edgeId, edgeIntAccess));
assertEquals(MaxWeightExcept.MISSING, mwEnc.getEnum(false, edgeId, edgeIntAccess));

// weight=5 is missing
edgeIntAccess = new ArrayEdgeIntAccess(1);
readerWay.clearTags();
readerWay.setTag("highway", "primary");
readerWay.setTag("vehicle:conditional", "delivery @ (weight > 5)");
parser.handleWayTags(edgeId, edgeIntAccess, readerWay, relFlags);
assertEquals(MaxWeightExcept.NONE, mwEnc.getEnum(false, edgeId, edgeIntAccess));
assertEquals(MaxWeightExcept.MISSING, mwEnc.getEnum(false, edgeId, edgeIntAccess));

edgeIntAccess = new ArrayEdgeIntAccess(1);
readerWay.clearTags();
Expand All @@ -70,4 +70,4 @@ public void testConditionalTags() {
parser.handleWayTags(edgeId, edgeIntAccess, readerWay, relFlags);
assertEquals(MaxWeightExcept.DESTINATION, mwEnc.getEnum(false, edgeId, edgeIntAccess));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,42 +24,47 @@ public void setUp() {

@Test
public void testSimpleTags() {
EdgeIntAccess edgeIntAccess = new ArrayEdgeIntAccess(1);
ReaderWay readerWay = new ReaderWay(1);
readerWay.setTag("highway", "primary");
readerWay.setTag("maxweight", "5");
parser.handleWayTags(edgeId, edgeIntAccess, readerWay, relFlags);
assertEquals(5.0, mwEnc.getDecimal(false, edgeId, edgeIntAccess), .01);
assertEquals(5.0, getMaxWeight(readerWay), .01);

// if value is beyond the maximum then do not use infinity instead fallback to more restrictive maximum
edgeIntAccess = new ArrayEdgeIntAccess(1);
readerWay.setTag("maxweight", "54");
parser.handleWayTags(edgeId, edgeIntAccess, readerWay, relFlags);
assertEquals(51, mwEnc.getDecimal(false, edgeId, edgeIntAccess), .01);
assertEquals(51, getMaxWeight(readerWay), .01);
}

@Test
public void testConditionalTags() {
EdgeIntAccess edgeIntAccess = new ArrayEdgeIntAccess(1);
ReaderWay readerWay = new ReaderWay(1);
readerWay.setTag("highway", "primary");
readerWay.setTag("access:conditional", "no @ (weight > 7.5)");
assertEquals(7.5, getMaxWeight(readerWay), .01);

readerWay.setTag("access:conditional", "no @ weight > 7");
assertEquals(7, getMaxWeight(readerWay), .01);

readerWay = new ReaderWay(1);
readerWay.setTag("highway", "primary");
readerWay.setTag("hgv:conditional", "no @ (weight > 7.5)");
parser.handleWayTags(edgeId, edgeIntAccess, readerWay, relFlags);
assertEquals(7.5, mwEnc.getDecimal(false, edgeId, edgeIntAccess), .01);
assertEquals(7.5, getMaxWeight(readerWay), .01);

edgeIntAccess = new ArrayEdgeIntAccess(1);
readerWay = new ReaderWay(1);
readerWay.setTag("highway", "primary");
readerWay.setTag("hgv:conditional", "none @ (weight > 10t)");
parser.handleWayTags(edgeId, edgeIntAccess, readerWay, relFlags);
assertEquals(10, mwEnc.getDecimal(false, edgeId, edgeIntAccess), .01);
assertEquals(10, getMaxWeight(readerWay), .01);

edgeIntAccess = new ArrayEdgeIntAccess(1);
readerWay.setTag("hgv:conditional", "no@ (weight > 7)");
parser.handleWayTags(edgeId, edgeIntAccess, readerWay, relFlags);
assertEquals(7, mwEnc.getDecimal(false, edgeId, edgeIntAccess), .01);
assertEquals(7, getMaxWeight(readerWay), .01);

edgeIntAccess = new ArrayEdgeIntAccess(1);
readerWay.setTag("hgv:conditional", "no @ (maxweight > 6)"); // allow different tagging
assertEquals(6, getMaxWeight(readerWay), .01);
}

double getMaxWeight(ReaderWay readerWay) {
EdgeIntAccess edgeIntAccess = new ArrayEdgeIntAccess(1);
int edgeId = 0;
parser.handleWayTags(edgeId, edgeIntAccess, readerWay, relFlags);
assertEquals(6, mwEnc.getDecimal(false, edgeId, edgeIntAccess), .01);
return mwEnc.getDecimal(false, edgeId, edgeIntAccess);
}
}

0 comments on commit e83332e

Please sign in to comment.