Changeset 4051 in josm for trunk/src/org


Ignore:
Timestamp:
2011-04-20T19:09:23+02:00 (13 years ago)
Author:
stoecker
Message:

fix #5642 - patch by bilbo - improve validator checks

Location:
trunk/src/org/openstreetmap/josm/data/validation
Files:
1 added
2 edited

Legend:

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

    r3946 r4051  
    3131import org.openstreetmap.josm.data.validation.tests.DuplicateNode;
    3232import org.openstreetmap.josm.data.validation.tests.DuplicateWay;
     33import org.openstreetmap.josm.data.validation.tests.DuplicateRelation;
    3334import org.openstreetmap.josm.data.validation.tests.DuplicatedWayNodes;
    3435import org.openstreetmap.josm.data.validation.tests.MultipolygonTest;
     
    9596            RelationChecker.class, // ID  1701 ..  1799
    9697            TurnrestrictionTest.class, // ID  1801 ..  1899
     98            DuplicateRelation.class, // ID 1901 .. 1999
    9799    };
    98100
  • trunk/src/org/openstreetmap/josm/data/validation/tests/DuplicateWay.java

    r4043 r4051  
    3434{
    3535
    36     private static class WayPair {
     36    private class WayPair {
    3737        public List<LatLon> coor;
    3838        public Map<String, String> keys;
     
    5656    }
    5757
     58    private class WayPairNoTags {
     59        public List<LatLon> coor;
     60        public WayPairNoTags(List<LatLon> _coor) {
     61            coor=_coor;
     62        }
     63        @Override
     64        public int hashCode() {
     65            return coor.hashCode();
     66        }
     67        @Override
     68        public boolean equals(Object obj) {
     69            if (!(obj instanceof WayPairNoTags)) return false;
     70            WayPairNoTags wp = (WayPairNoTags) obj;
     71            return wp.coor.equals(coor);
     72        }
     73    }
     74
    5875    protected static int DUPLICATE_WAY = 1401;
     76    protected static int SAME_WAY = 1402;
    5977
    6078    /** Bag of all ways */
    6179    MultiMap<WayPair, OsmPrimitive> ways;
     80
     81    /** Bag of all ways, regardless of tags */
     82    MultiMap<WayPairNoTags, OsmPrimitive> waysNoTags;
    6283
    6384    /**
     
    6687    public DuplicateWay() {
    6788        super(tr("Duplicated ways."),
    68                 tr("This test checks that there are no ways with same tags and same node coordinates."));
     89              tr("This test checks that there are no ways with same node coordinates and optionally also same tags."));
    6990    }
    7091
     
    7495        super.startTest(monitor);
    7596        ways = new MultiMap<WayPair, OsmPrimitive>(1000);
     97        waysNoTags = new MultiMap<WayPairNoTags, OsmPrimitive>(1000);
    7698    }
    7799
     
    85107            }
    86108        }
     109
     110        for(Set<OsmPrimitive> sameway : waysNoTags.values()) {
     111            if( sameway.size() > 1) {
     112                //Report error only if at least some tags are different, as otherwise the error was already reported as duplicated ways
     113                Map<String, String> tags0=null;
     114                boolean skip=true;
     115
     116                for(OsmPrimitive o : sameway) {
     117                    if (tags0==null) {
     118                        tags0=o.getKeys();
     119                        removeUninterestingKeys(tags0);
     120                    } else {
     121                        Map<String, String> tagsCmp=o.getKeys();
     122                        removeUninterestingKeys(tagsCmp);
     123                        if (!tagsCmp.equals(tags0)) {
     124                            skip=false;
     125                            break;
     126                        }
     127                    }
     128                }
     129                if (skip) continue;
     130                TestError testError = new TestError(this, Severity.WARNING, tr("Ways with same position"), SAME_WAY, sameway);
     131                errors.add(testError);
     132            }
     133        }
    87134        ways = null;
     135        waysNoTags = null;
     136    }
     137
     138    /**
     139     * Remove uninteresting keys, like created_by to normalize the tags
     140     */
     141    public void removeUninterestingKeys(Map<String, String> wkeys) {
     142        wkeys.remove("created_by");
    88143    }
    89144
     
    98153        }
    99154        Map<String, String> wkeys = w.getKeys();
    100         wkeys.remove("created_by");
     155        removeUninterestingKeys(wkeys);
    101156        WayPair wKey = new WayPair(wLat, wkeys);
    102157        ways.put(wKey, w);
     158        WayPairNoTags wKeyN = new WayPairNoTags(wLat);
     159        waysNoTags.put(wKeyN, w);
    103160    }
    104161
     
    174231            return false;
    175232
     233        //Do not automatically fix same ways with different tags
     234        if (testError.getCode()!=DUPLICATE_WAY) return false;
     235
    176236        // We fix it only if there is no more than one way that is relation member.
    177237        Collection<? extends OsmPrimitive> sel = testError.getPrimitives();
Note: See TracChangeset for help on using the changeset viewer.