Ticket #20832: 20832.3.patch

File 20832.3.patch, 10.6 KB (added by GerdP, 2 years ago)
  • src/org/openstreetmap/josm/data/validation/tests/TurnrestrictionTest.java

     
    4747
    4848    private static final List<String> SUPPORTED_RESTRICTIONS = Arrays.asList(
    4949            "no_right_turn", "no_left_turn", "no_u_turn", "no_straight_on",
    50             "only_right_turn", "only_left_turn", "only_straight_on",
     50            "only_right_turn", "only_left_turn", "only_straight_on", "only_u_turn",
    5151            "no_entry", "no_exit"
    5252        );
    5353
     54    // This should really be replaced with a transport mode hierarchy, i.e. #18383
     55    private static final List<String> SUPPORTED_VEHICLE_TYPES = Arrays.asList(
     56            "agricultural", "bicycle", "bus", "caravan", "foot", "hazmat",
     57            "hgv", "horse", "motor_vehicle", "motorcar", "motorcycle",
     58            "psv", "vehicle"
     59    );
     60
     61    /** A string for "restriction" */
     62    private static final String RESTRICTION_STRING = "restriction";
     63    /** A string for "conditional" */
     64    private static final String CONDITIONAL_STRING = "conditional";
     65
    5466    /**
    5567     * Constructs a new {@code TurnrestrictionTest}.
    5668     */
     
    5870        super(tr("Turn restrictions"), tr("This test checks if turn restrictions are valid."));
    5971    }
    6072
    61     private static boolean hasSupportedRestrictionTag(Relation r) {
    62         if (r.hasTag("restriction", SUPPORTED_RESTRICTIONS))
    63             return true;
    64         String conditionalValue = r.get("restriction:conditional");
    65         if (conditionalValue != null) {
     73    /**
     74     * Check for any restriction tag (e.g., "restriction:mode:conditional" or "restriction:conditional)
     75     * @param key The key to check
     76     * @param value The value to check
     77     * @return {@code true} if the tag is supported
     78     */
     79    private static boolean restrictionTagIsSupported(final String key, final String value) {
     80        if (!key.startsWith("restriction:"))
     81            return false;
     82        String[] parts = key.split(":");
     83        if (parts.length > 3)
     84            return false;
     85        if (parts.length == 3 && !SUPPORTED_VEHICLE_TYPES.contains(parts[1]))
     86            return false;
     87        if (key.endsWith(CONDITIONAL_STRING)) {
     88            // restriction:conditional=* or restriction:mode:condition=*
    6689            try {
    67                 List<ConditionalValue> values = ConditionalValue.parse(conditionalValue);
    68                 return !values.isEmpty() && SUPPORTED_RESTRICTIONS.contains(values.get(0).restrictionValue);
     90                final List<ConditionalValue> conditionalValues = ConditionalValue.parse(value);
     91                return !conditionalValues.isEmpty() && conditionalValues.stream()
     92                        .anyMatch(conditional -> SUPPORTED_RESTRICTIONS.contains(conditional.restrictionValue));
    6993            } catch (ConditionalParsingException e) {
    7094                Logging.trace(e);
    7195            }
     96        } else if (SUPPORTED_VEHICLE_TYPES.contains(parts[1])) {
     97            // restriction:mode=*
     98            return SUPPORTED_RESTRICTIONS.contains(value);
    7299        }
    73100        return false;
    74101    }
    75102
     103    private static boolean hasSupportedRestrictionTag(Relation r) {
     104        if (r.hasTag(RESTRICTION_STRING, SUPPORTED_RESTRICTIONS))
     105            return true;
     106        if (r.hasTag("restriction:bicycle", "give_way", "stop"))
     107            return true;
     108        return r.getKeys().entrySet().stream()
     109                .anyMatch(entry -> restrictionTagIsSupported(entry.getKey(), entry.getValue()));
     110    }
     111
    76112    @Override
    77113    public void visit(Relation r) {
    78         if (!r.hasTag("type", "restriction"))
     114        if (!r.hasTag("type", RESTRICTION_STRING))
    79115            return;
    80116
    81117        if (!hasSupportedRestrictionTag(r)) {
     
    224260            return;
    225261        }
    226262        if (fromWay.equals(toWay)) {
    227             Severity severity = r.hasTag("restriction", "no_u_turn") ? Severity.OTHER : Severity.WARNING;
     263            Severity severity = r.hasTag(RESTRICTION_STRING, "no_u_turn") ? Severity.OTHER : Severity.WARNING;
    228264            errors.add(TestError.builder(this, severity, FROM_EQUALS_TO)
    229265                    .message(tr("\"from\" way equals \"to\" way"))
    230266                    .primitives(r)
  • nodist/data/restriction.osm

     
    303303  </node>
    304304  <node id='-139153' action='modify' lat='51.12589701544' lon='14.16097636327' />
    305305  <node id='-139155' action='modify' lat='51.12605520638' lon='14.16056440756' />
     306  <node id='-139208' action='modify' lat='51.12625114973' lon='14.15235587932' />
     307  <node id='-139209' action='modify' lat='51.12618309097' lon='14.151858722' />
     308  <node id='-139210' action='modify' lat='51.12642930304' lon='14.1518794535' />
     309  <node id='-139211' action='modify' lat='51.12659369391' lon='14.15201819507'>
     310    <tag k='name' v='14 - hgv only straight on' />
     311  </node>
     312  <node id='-139212' action='modify' lat='51.12600068301' lon='14.15168569371' />
     313  <node id='-139213' action='modify' lat='51.12586506509' lon='14.15166097538' />
     314  <node id='-139214' action='modify' lat='51.12569691835' lon='14.15169924892' />
     315  <node id='-139215' action='modify' lat='51.12638976908' lon='14.15142056972' />
     316  <node id='-139224' action='modify' lat='51.12615056402' lon='14.1527188163' />
     317  <node id='-139225' action='modify' lat='51.12639677626' lon='14.1527395478' />
     318  <node id='-139226' action='modify' lat='51.12656116725' lon='14.15287828937'>
     319    <tag k='name' v='15 - only straight on conditional' />
     320  </node>
     321  <node id='-139227' action='modify' lat='51.12596815593' lon='14.15254578801' />
     322  <node id='-139228' action='modify' lat='51.12583253792' lon='14.15252106968' />
     323  <node id='-139229' action='modify' lat='51.12566439106' lon='14.15255934322' />
     324  <node id='-139230' action='modify' lat='51.12621862282' lon='14.15321597362' />
     325  <node id='-139231' action='modify' lat='51.12635724228' lon='14.15228066402' />
     326  <node id='-139292' action='modify' lat='51.12616277589' lon='14.15339796366' />
     327  <node id='-139293' action='modify' lat='51.12598036785' lon='14.15322493537' />
     328  <node id='-139294' action='modify' lat='51.12584474987' lon='14.15320021704' />
     329  <node id='-139295' action='modify' lat='51.12567660306' lon='14.15323849058' />
     330  <node id='-139296' action='modify' lat='51.12623083467' lon='14.15389512098' />
     331  <node id='-139297' action='modify' lat='51.12640898807' lon='14.15341869516' />
     332  <node id='-139298' action='modify' lat='51.12657337901' lon='14.15355743673'>
     333    <tag k='name' v='16 - hgv only straight on conditional' />
     334  </node>
     335  <node id='-139299' action='modify' lat='51.12636945409' lon='14.15295981138' />
    306336  <way id='-138981' timestamp='2009-09-09T15:30:17Z'>
    307337    <nd ref='-112783' />
    308338    <nd ref='-112877' />
     
    9831013    <tag k='highway' v='unclassified' />
    9841014    <tag k='oneway' v='yes' />
    9851015  </way>
     1016  <way id='-139194' action='modify'>
     1017    <nd ref='-139208' />
     1018    <nd ref='-139209' />
     1019    <tag k='highway' v='unclassified' />
     1020  </way>
     1021  <way id='-139195' action='modify'>
     1022    <nd ref='-139209' />
     1023    <nd ref='-139210' />
     1024    <nd ref='-139211' />
     1025    <tag k='highway' v='unclassified' />
     1026  </way>
     1027  <way id='-139196' action='modify'>
     1028    <nd ref='-139209' />
     1029    <nd ref='-139212' />
     1030    <nd ref='-139213' />
     1031    <nd ref='-139214' />
     1032    <tag k='highway' v='unclassified' />
     1033  </way>
     1034  <way id='-139197' action='modify'>
     1035    <nd ref='-139215' />
     1036    <nd ref='-139209' />
     1037    <tag k='highway' v='unclassified' />
     1038  </way>
     1039  <way id='-139202' action='modify'>
     1040    <nd ref='-139224' />
     1041    <nd ref='-139225' />
     1042    <nd ref='-139226' />
     1043    <tag k='highway' v='unclassified' />
     1044  </way>
     1045  <way id='-139203' action='modify'>
     1046    <nd ref='-139224' />
     1047    <nd ref='-139227' />
     1048    <nd ref='-139228' />
     1049    <nd ref='-139229' />
     1050    <tag k='highway' v='unclassified' />
     1051  </way>
     1052  <way id='-139204' action='modify'>
     1053    <nd ref='-139230' />
     1054    <nd ref='-139224' />
     1055    <tag k='highway' v='unclassified' />
     1056  </way>
     1057  <way id='-139205' action='modify'>
     1058    <nd ref='-139231' />
     1059    <nd ref='-139224' />
     1060    <tag k='highway' v='unclassified' />
     1061  </way>
     1062  <way id='-139258' action='modify'>
     1063    <nd ref='-139292' />
     1064    <nd ref='-139293' />
     1065    <nd ref='-139294' />
     1066    <nd ref='-139295' />
     1067    <tag k='highway' v='unclassified' />
     1068  </way>
     1069  <way id='-139259' action='modify'>
     1070    <nd ref='-139296' />
     1071    <nd ref='-139292' />
     1072    <tag k='highway' v='unclassified' />
     1073  </way>
     1074  <way id='-139260' action='modify'>
     1075    <nd ref='-139292' />
     1076    <nd ref='-139297' />
     1077    <nd ref='-139298' />
     1078    <tag k='highway' v='unclassified' />
     1079  </way>
     1080  <way id='-139261' action='modify'>
     1081    <nd ref='-139299' />
     1082    <nd ref='-139292' />
     1083    <tag k='highway' v='unclassified' />
     1084  </way>
    9861085  <relation id='-139094' action='modify' timestamp='2009-09-09T15:30:17Z'>
    9871086    <member type='way' ref='-139044' role='to' />
    9881087    <member type='node' ref='-112839' role='via' />
     
    13191418    <tag k='restriction:conditional' v='no_u_turn @ (Mo-Fr 16:00-18:00)' />
    13201419    <tag k='type' v='restriction' />
    13211420  </relation>
     1421  <relation id='-139211' action='modify'>
     1422    <member type='way' ref='-139196' role='from' />
     1423    <member type='way' ref='-139195' role='to' />
     1424    <member type='node' ref='-139209' role='via' />
     1425    <tag k='name' v='OK 14 - hgv only straight on' />
     1426    <tag k='restriction:hgv' v='only_straight_on' />
     1427    <tag k='type' v='restriction' />
     1428  </relation>
     1429  <relation id='-139213' action='modify'>
     1430    <member type='way' ref='-139203' role='from' />
     1431    <member type='way' ref='-139202' role='to' />
     1432    <member type='node' ref='-139224' role='via' />
     1433    <tag k='name' v='OK 15- only straight on conditional' />
     1434    <tag k='restriction:conditional' v='only_straight_on @ (07:00-09:00)' />
     1435    <tag k='type' v='restriction' />
     1436  </relation>
     1437  <relation id='-139216' action='modify'>
     1438    <member type='way' ref='-139258' role='from' />
     1439    <member type='way' ref='-139260' role='to' />
     1440    <member type='node' ref='-139292' role='via' />
     1441    <tag k='name' v='OK 16- hgv only straight on conditional' />
     1442    <tag k='restriction:caravan:conditional' v='only_straight_on @ (07:00-09:00)' />
     1443    <tag k='type' v='restriction' />
     1444  </relation>
    13221445</osm>