Ticket #18544: 18544.patch

File 18544.patch, 1.9 KB (added by GerdP, 5 years ago)
  • src/org/openstreetmap/josm/data/validation/tests/CrossingWays.java

     
    77import java.util.ArrayList;
    88import java.util.Arrays;
    99import java.util.HashMap;
     10import java.util.HashSet;
    1011import java.util.List;
    1112import java.util.Map;
    1213import java.util.Objects;
     14import java.util.Set;
    1315
    1416import org.openstreetmap.josm.data.coor.EastNorth;
    1517import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    219221
    220222        @Override
    221223        boolean ignoreWaySegmentCombination(Way w1, Way w2) {
    222             return !Objects.equals(w1.get("boundary"), w2.get("boundary"));
     224            // ignore ways which have no common boundary tag value
     225            Set<String> s1 = getBoundaryTags(w1);
     226            Set<String> s2 = getBoundaryTags(w2);
     227            for (String type : s1) {
     228                if (s2.contains(type))
     229                    return false;
     230            }
     231            return true;
    223232        }
    224233
     234        /**
     235         * Collect all boundary tag values of the way and its parent relations
     236         * @param w the way to check
     237         * @return set with the found boundary tag values
     238         */
     239        private static Set<String> getBoundaryTags(Way w) {
     240            final Set<String> types = new HashSet<>();
     241            String type = w.get("boundary");
     242            if (type != null)
     243                types.add(type);
     244            w.referrers(Relation.class).filter(Relation::isMultipolygon).map(r -> r.get("boundary"))
     245                    .filter(Objects::nonNull).forEach(types::add);
     246            return types;
     247        }
     248
    225249        @Override
    226250        public void visit(Relation r) {
    227251            for (Way w : r.getMemberPrimitives(Way.class)) {