Changeset 6573 in josm


Ignore:
Timestamp:
2013-12-31T10:56:23+01:00 (6 years ago)
Author:
simon04
Message:

fix #9043 - Validator: Verify links on highways

Location:
trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/validation/tests/Highways.java

    r6482 r6573  
    2222import org.openstreetmap.josm.data.validation.Test;
    2323import org.openstreetmap.josm.data.validation.TestError;
     24import org.openstreetmap.josm.tools.Predicate;
    2425import org.openstreetmap.josm.tools.Utils;
    2526
     
    3637    protected static final int SOURCE_MAXSPEED_CONTEXT_MISMATCH_VS_MAXSPEED = 2705;
    3738    protected static final int SOURCE_MAXSPEED_CONTEXT_MISMATCH_VS_HIGHWAY = 2706;
     39    protected static final int SOURCE_WRONG_LINK = 2707;
    3840
    3941    /**
     
    104106                testSourceMaxspeed(w, true);
    105107            }
     108            testHighwayLink(w);
    106109        }
    107110    }
     
    140143    }
    141144
     145    public static boolean isHighwayLinkOkay(final Way way) {
     146        final String highway = way.get("highway");
     147        if (highway == null || !highway.endsWith("_link")) {
     148            return true;
     149        }
     150
     151        final HashSet<OsmPrimitive> referrers = new HashSet<OsmPrimitive>();
     152        referrers.addAll(way.firstNode().getReferrers());
     153        referrers.addAll(way.lastNode().getReferrers());
     154
     155        return Utils.exists(Utils.filteredCollection(referrers, Way.class), new Predicate<Way>() {
     156            @Override
     157            public boolean evaluate(final Way otherWay) {
     158                return !way.equals(otherWay) && otherWay.hasTag("highway", highway, highway.replaceAll("_link$", ""));
     159            }
     160        });
     161    }
     162
     163    private void testHighwayLink(final Way way) {
     164        if (!isHighwayLinkOkay(way)) {
     165            errors.add(new TestError(this, Severity.WARNING,
     166                    tr("Highway link is not linked to adequate highway/link"), SOURCE_WRONG_LINK, way));
     167        }
     168    }
     169
    142170    private void testMissingPedestrianCrossing(Node n) {
    143171        leftByPedestrians = false;
  • trunk/src/org/openstreetmap/josm/tools/Predicates.java

    r6547 r6573  
    11package org.openstreetmap.josm.tools;
     2
     3import org.openstreetmap.josm.data.osm.OsmPrimitive;
    24
    35import java.util.regex.Pattern;
     
    4648        };
    4749    }
     50
     51    /**
     52     * Returns a {@link Predicate} executing {@link OsmPrimitive#hasTag(String, String...)}.
     53     */
     54    public static Predicate<OsmPrimitive> hasTag(final String key, final String... values) {
     55        return new Predicate<OsmPrimitive>() {
     56            @Override
     57            public boolean evaluate(OsmPrimitive p) {
     58                return p.hasTag(key, values);
     59            }
     60        };
     61    }
    4862}
Note: See TracChangeset for help on using the changeset viewer.