Changeset 6482 in josm


Ignore:
Timestamp:
2013-12-17T01:52:59+01:00 (6 years ago)
Author:
Don-vip
Message:

see #9400 - implement first points of source:maxspeed validation, move validator config files into data/validator

Location:
trunk
Files:
1 added
2 edited
3 moved

Legend:

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

    r6475 r6482  
    1010import java.util.Iterator;
    1111import java.util.List;
     12import java.util.Locale;
    1213import java.util.Map;
    1314
     
    3132    protected static final int WRONG_ROUNDABOUT_HIGHWAY = 2701;
    3233    protected static final int MISSING_PEDESTRIAN_CROSSING = 2702;
     34    protected static final int SOURCE_MAXSPEED_UNKNOWN_COUNTRY_CODE = 2703;
     35    protected static final int SOURCE_MAXSPEED_UNKNOWN_CONTEXT = 2704;
     36    protected static final int SOURCE_MAXSPEED_CONTEXT_MISMATCH_VS_MAXSPEED = 2705;
     37    protected static final int SOURCE_MAXSPEED_CONTEXT_MISMATCH_VS_HIGHWAY = 2706;
    3338
    3439    /**
     
    4550            "living_street");
    4651
     52    protected static final List<String> KNOWN_SOURCE_MAXSPEED_CONTEXTS = Arrays.asList(
     53            "urban", "rural", "zone", "zone30", "zone:30", "nsl_single", "nsl_dual", "motorway", "trunk", "living_street");
     54
     55    protected static final List<String> ISO_COUNTRIES = Arrays.asList(Locale.getISOCountries());
     56
    4757    boolean leftByPedestrians = false;
    4858    boolean leftByCyclists = false;
     
    7383    @Override
    7484    public void visit(Node n) {
    75         if (n.isUsable() && !n.hasTag("highway", "crossing") && !n.hasTag("crossing", "no") && n.isReferredByWays(2)) {
    76             testMissingPedestrianCrossing(n);
     85        if (n.isUsable()) {
     86            if (!n.hasTag("highway", "crossing") && !n.hasTag("crossing", "no") && n.isReferredByWays(2)) {
     87                testMissingPedestrianCrossing(n);
     88            }
     89            if (n.hasKey("source:maxspeed")) {
     90                // Check maxspeed but not context against highway for nodes as maxspeed is not set on highways here but on signs, speed cameras, etc.
     91                testSourceMaxspeed(n, false);
     92            }
    7793        }
    7894    }
     
    8096    @Override
    8197    public void visit(Way w) {
    82         if (w.isUsable() && w.hasKey("highway") && w.hasKey("junction") && w.get("junction").equals("roundabout")) {
    83             testWrongRoundabout(w);
     98        if (w.isUsable()) {
     99            if (w.hasKey("highway") && w.hasKey("junction") && w.get("junction").equals("roundabout")) {
     100                testWrongRoundabout(w);
     101            }
     102            if (w.hasKey("source:maxspeed")) {
     103                // Check maxspeed, including context against highway
     104                testSourceMaxspeed(w, true);
     105            }
    84106        }
    85107    }
     
    173195        }
    174196    }
     197   
     198    private void testSourceMaxspeed(OsmPrimitive p, boolean testContextHighway) {
     199        String value = p.get("source:maxspeed");
     200        if (value.matches("[A-Z]{2}:.+")) {
     201            int index = value.indexOf(':');
     202            // Check country
     203            String country = value.substring(0, index);
     204            if (!ISO_COUNTRIES.contains(country)) {
     205                errors.add(new TestError(this, Severity.WARNING, tr("Unknown country code: {0}", country), SOURCE_MAXSPEED_UNKNOWN_COUNTRY_CODE, p));
     206            }
     207            // Check context
     208            String context = value.substring(index+1);
     209            if (!KNOWN_SOURCE_MAXSPEED_CONTEXTS.contains(context)) {
     210                errors.add(new TestError(this, Severity.WARNING, tr("Unknown source:maxspeed context: {0}", context), SOURCE_MAXSPEED_UNKNOWN_CONTEXT, p));
     211            }
     212            // TODO: Check coherence of context against maxspeed
     213            // TODO: Check coherence of context against highway
     214        }
     215    }
    175216
    176217    @Override
  • trunk/src/org/openstreetmap/josm/data/validation/tests/TagChecker.java

    r6385 r6482  
    7373   
    7474    /** The default data files */
    75     public static final String DATA_FILE = "resource://data/tagchecker.cfg";
    76     public static final String IGNORE_FILE = "resource://data/ignoretags.cfg";
    77     public static final String SPELL_FILE = "resource://data/words.cfg";
     75    public static final String DATA_FILE = "resource://data/validator/tagchecker.cfg";
     76    public static final String IGNORE_FILE = "resource://data/validator/ignoretags.cfg";
     77    public static final String SPELL_FILE = "resource://data/validator/words.cfg";
    7878
    7979    /** The spell check key substitutions: the key should be substituted by the value */
Note: See TracChangeset for help on using the changeset viewer.