Ignore:
Timestamp:
2010-07-27T03:34:06+02:00 (14 years ago)
Author:
nakor
Message:

Categorize duplicate nodes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/DuplicateNode.java

    r21177 r22445  
    22package org.openstreetmap.josm.plugins.validator.tests;
    33
     4import static org.openstreetmap.josm.tools.I18n.marktr;
    45import static org.openstreetmap.josm.tools.I18n.tr;
    56
     
    89import java.util.ArrayList;
    910import java.util.Collection;
     11import java.util.HashMap;
    1012import java.util.Iterator;
    1113import java.util.LinkedHashSet;
     
    2527import org.openstreetmap.josm.data.osm.Node;
    2628import org.openstreetmap.josm.data.osm.OsmPrimitive;
     29import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    2730import org.openstreetmap.josm.data.osm.Storage;
     31import org.openstreetmap.josm.data.osm.Way;
    2832import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil;
    2933import org.openstreetmap.josm.gui.progress.ProgressMonitor;
     
    6367
    6468    protected static int DUPLICATE_NODE = 1;
     69    protected static int DUPLICATE_NODE_MIXED = 2;
     70    protected static int DUPLICATE_NODE_HIGHWAY = 3;
     71    protected static int DUPLICATE_NODE_RAILWAY = 3;
     72    protected static int DUPLICATE_NODE_WATERWAY = 4;
     73    protected static int DUPLICATE_NODE_BOUNDARY = 5;
     74    protected static int DUPLICATE_NODE_POWER = 6;
    6575
    6676    /** The map of potential duplicates.
     
    114124            bag.add(n.getKeys(), n);
    115125        }
     126
     127        Map<String,Boolean> typeMap=new HashMap<String,Boolean>();
     128        String[] types = {"none", "highway", "railway", "waterway", "boundary", "power"};
     129
     130
    116131        // check whether we have multiple nodes at the same position with
    117132        // the same tag set
     
    120135            Map<String,String> tagSet = it.next();
    121136            if (bag.get(tagSet).size() > 1) {
    122                 errors.add(new TestError(
    123                         parentTest,
    124                         Severity.ERROR,
    125                         tr("Duplicated nodes"),
    126                         DUPLICATE_NODE,
    127                         bag.get(tagSet)
    128                 ));
     137
     138                for (String type: types) {
     139                    typeMap.put(type, false);
     140                }
     141
     142                for (OsmPrimitive p : bag.get(tagSet)) {
     143                    if (p.getType()==OsmPrimitiveType.NODE) {
     144                        Node n = (Node) p;
     145                        List<OsmPrimitive> lp=n.getReferrers();
     146                        for (OsmPrimitive sp: lp) {
     147                            if (sp.getType()==OsmPrimitiveType.WAY) {
     148                                boolean typed = false;
     149                                Way w=(Way) sp;
     150                                Map<String, String> keys = w.getKeys();
     151                                for (String type: typeMap.keySet()) {
     152                                    if (keys.containsKey(type)) {
     153                                        typeMap.put(type, true);
     154                                        typed=true;
     155                                    }
     156                                }
     157                                if (!typed) typeMap.put("none", true);
     158                            }
     159                        }
     160
     161                    }
     162                }
     163
     164                int nbType=0;
     165                for (String type: typeMap.keySet()) {
     166                    if (typeMap.get(type)) nbType++;
     167                }
     168
     169                if (nbType>1) {
     170                    String msg = marktr("Mixed type duplicated nodes");
     171                    errors.add(new TestError(
     172                            parentTest,
     173                            Severity.ERROR,
     174                            tr("Duplicated nodes"),
     175                            tr(msg),
     176                            msg,
     177                            DUPLICATE_NODE_MIXED,
     178                            bag.get(tagSet)
     179                    ));
     180                } else if (typeMap.get("highway")) {
     181                    String msg = marktr("Highway duplicated nodes");
     182                    errors.add(new TestError(
     183                            parentTest,
     184                            Severity.ERROR,
     185                            tr("Duplicated nodes"),
     186                            tr(msg),
     187                            msg,
     188                            DUPLICATE_NODE_HIGHWAY,
     189                            bag.get(tagSet)
     190                    ));
     191                } else if (typeMap.get("railway")) {
     192                    String msg = marktr("Railway duplicated nodes");
     193                    errors.add(new TestError(
     194                            parentTest,
     195                            Severity.ERROR,
     196                            tr("Duplicated nodes"),
     197                            tr(msg),
     198                            msg,
     199                            DUPLICATE_NODE_RAILWAY,
     200                            bag.get(tagSet)
     201                    ));
     202                } else if (typeMap.get("waterway")) {
     203                    String msg = marktr("Waterway duplicated nodes");
     204                    errors.add(new TestError(
     205                            parentTest,
     206                            Severity.ERROR,
     207                            tr("Duplicated nodes"),
     208                            tr(msg),
     209                            msg,
     210                            DUPLICATE_NODE_WATERWAY,
     211                            bag.get(tagSet)
     212                    ));
     213                } else if (typeMap.get("boundary")) {
     214                    String msg = marktr("Boundary duplicated nodes");
     215                    errors.add(new TestError(
     216                            parentTest,
     217                            Severity.ERROR,
     218                            tr("Duplicated nodes"),
     219                            tr(msg),
     220                            msg,
     221                            DUPLICATE_NODE_BOUNDARY,
     222                            bag.get(tagSet)
     223                    ));
     224                } else if (typeMap.get("power")) {
     225                    String msg = marktr("Power duplicated nodes");
     226                    errors.add(new TestError(
     227                            parentTest,
     228                            Severity.ERROR,
     229                            tr("Duplicated nodes"),
     230                            tr(msg),
     231                            msg,
     232                            DUPLICATE_NODE_POWER,
     233                            bag.get(tagSet)
     234                    ));
     235                } else {
     236                    errors.add(new TestError(
     237                            parentTest,
     238                            Severity.ERROR,
     239                            tr("Duplicated nodes"),
     240                            DUPLICATE_NODE,
     241                            bag.get(tagSet)
     242                    ));
     243
     244                }
    129245                it.remove();
    130246            }
Note: See TracChangeset for help on using the changeset viewer.