source: josm/trunk/src/org/openstreetmap/josm/data/validation/tests/OverlappingAreas.java@ 4682

Last change on this file since 4682 was 4682, checked in by simon04, 12 years ago

fix #2746 - add validation: Way connected to Area

File size: 1.9 KB
Line 
1package org.openstreetmap.josm.data.validation.tests;
2
3import static org.openstreetmap.josm.tools.I18n.tr;
4
5import java.util.Collection;
6import java.util.Collections;
7import org.openstreetmap.josm.data.osm.QuadBuckets;
8import org.openstreetmap.josm.data.osm.Way;
9import org.openstreetmap.josm.data.validation.Severity;
10import org.openstreetmap.josm.data.validation.Test;
11import org.openstreetmap.josm.data.validation.TestError;
12import org.openstreetmap.josm.gui.mappaint.ElemStyles;
13import org.openstreetmap.josm.tools.Geometry;
14import org.openstreetmap.josm.tools.Predicate;
15import org.openstreetmap.josm.tools.Utils;
16
17public class OverlappingAreas extends Test {
18
19 protected static int OVERLAPPING_AREAS = 2201;
20 protected QuadBuckets<Way> index = new QuadBuckets<Way>();
21
22 public OverlappingAreas() {
23 super(tr("Overlapping Areas"));
24 }
25
26 @Override
27 public void visit(Way w) {
28 if (w.isUsable() && w.isClosed() && ElemStyles.hasAreaElemStyle(w, false)) {
29 index.add(w);
30 }
31 }
32
33 @Override
34 public void endTest() {
35 for (final Way w : index) {
36 Collection<Way> overlaps = Utils.filter(
37 index.search(w.getBBox()),
38 new Predicate<Way>() {
39
40 @Override
41 public boolean evaluate(Way wi) {
42 if (w.equals(wi)) {
43 return false;
44 } else {
45 return Geometry.polygonIntersection(w.getNodes(), wi.getNodes())
46 == Geometry.PolygonIntersection.CROSSING;
47 }
48 }
49 });
50 if (!overlaps.isEmpty()) {
51 errors.add(new TestError(this, Severity.OTHER, tr("Overlapping Areas"),
52 OVERLAPPING_AREAS, Collections.singletonList(w), overlaps));
53 }
54 }
55 }
56
57}
Note: See TracBrowser for help on using the repository browser.