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

Last change on this file since 5927 was 5927, checked in by bastiK, 11 years ago

add missing license information

File size: 3.5 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.validation.tests;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.util.ArrayList;
7import java.util.Collection;
8import java.util.Collections;
9
10import org.openstreetmap.josm.data.osm.QuadBuckets;
11import org.openstreetmap.josm.data.osm.Way;
12import org.openstreetmap.josm.data.validation.Severity;
13import org.openstreetmap.josm.data.validation.Test;
14import org.openstreetmap.josm.data.validation.TestError;
15import org.openstreetmap.josm.gui.mappaint.ElemStyles;
16import org.openstreetmap.josm.tools.Geometry;
17import org.openstreetmap.josm.tools.Predicate;
18import org.openstreetmap.josm.tools.Utils;
19
20public class OverlappingAreas extends Test {
21
22 protected static final int OVERLAPPING_AREAS = 2201;
23 protected QuadBuckets<Way> index = new QuadBuckets<Way>();
24
25 public OverlappingAreas() {
26 super(tr("Overlapping Areas"), tr("This test checks if areas overlap."));
27 }
28
29 @Override
30 public void visit(Way w) {
31 if (w.isUsable() && w.isArea() && ElemStyles.hasAreaElemStyle(w, false)) {
32 index.add(w);
33 }
34 }
35
36 @Override
37 public void endTest() {
38 for (final Way w : index) {
39 Collection<Way> overlaps = Utils.filter(
40 index.search(w.getBBox()),
41 new Predicate<Way>() {
42
43 @Override
44 public boolean evaluate(Way wi) {
45 if (w.equals(wi))
46 return false;
47 else
48 return Geometry.polygonIntersection(w.getNodes(), wi.getNodes())
49 == Geometry.PolygonIntersection.CROSSING;
50 }
51 });
52 if (!overlaps.isEmpty()) {
53 Collection<Way> overlapsWater = new ArrayList<Way>();
54 Collection<Way> overlapsOther = new ArrayList<Way>();
55
56 String natural1 = w.get("natural");
57 String landuse1 = w.get("landuse");
58 boolean isWaterArea = "water".equals(natural1) || "wetland".equals(natural1) || "coastline".equals(natural1) || "reservoir".equals(landuse1);
59 boolean isWaterArea2 = false;
60
61 for (Way wayOther : overlaps) {
62 String natural2 = wayOther.get("natural");
63 String landuse2 = wayOther.get("landuse");
64 boolean isWaterAreaTest = "water".equals(natural2) || "wetland".equals(natural2) || "coastline".equals(natural2) || "reservoir".equals(landuse2);
65
66 if (!isWaterArea2) {
67 isWaterArea2 = isWaterAreaTest;
68 }
69
70 if (isWaterArea && isWaterAreaTest) {
71 overlapsWater.add(wayOther);
72 } else {
73 overlapsOther.add(wayOther);
74 }
75 }
76
77 if (!overlapsWater.isEmpty()) {
78 errors.add(new TestError(this, Severity.WARNING, tr("Overlapping Water Areas"),
79 OVERLAPPING_AREAS, Collections.singletonList(w), overlapsWater));
80 }
81
82 if (!overlapsOther.isEmpty()) {
83 errors.add(new TestError(this, Severity.OTHER, tr("Overlapping Areas"),
84 OVERLAPPING_AREAS, Collections.singletonList(w), overlapsOther));
85 }
86 }
87 }
88
89 super.endTest();
90 }
91
92}
Note: See TracBrowser for help on using the repository browser.