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

Last change on this file since 6241 was 6241, checked in by Don-vip, 12 years ago

fix more warnings/javadoc in data.validation.tests

File size: 3.6 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
20/**
21 * Checks if areas overlap.
22 * @since 4448
23 */
24public class OverlappingAreas extends Test {
25
26 protected static final int OVERLAPPING_AREAS = 2201;
27 protected QuadBuckets<Way> index = new QuadBuckets<Way>();
28
29 /**
30 * Constructs a new {@code OverlappingAreas} test.
31 */
32 public OverlappingAreas() {
33 super(tr("Overlapping Areas"), tr("This test checks if areas overlap."));
34 }
35
36 @Override
37 public void visit(Way w) {
38 if (w.isUsable() && w.isArea() && ElemStyles.hasAreaElemStyle(w, false)) {
39 index.add(w);
40 }
41 }
42
43 @Override
44 public void endTest() {
45 for (final Way w : index) {
46 Collection<Way> overlaps = Utils.filter(
47 index.search(w.getBBox()),
48 new Predicate<Way>() {
49
50 @Override
51 public boolean evaluate(Way wi) {
52 if (w.equals(wi))
53 return false;
54 else
55 return Geometry.polygonIntersection(w.getNodes(), wi.getNodes())
56 == Geometry.PolygonIntersection.CROSSING;
57 }
58 });
59 if (!overlaps.isEmpty()) {
60 Collection<Way> overlapsWater = new ArrayList<Way>();
61 Collection<Way> overlapsOther = new ArrayList<Way>();
62
63 String natural1 = w.get("natural");
64 String landuse1 = w.get("landuse");
65 boolean isWaterArea = "water".equals(natural1) || "wetland".equals(natural1) || "coastline".equals(natural1) || "reservoir".equals(landuse1);
66 boolean isWaterArea2 = false;
67
68 for (Way wayOther : overlaps) {
69 String natural2 = wayOther.get("natural");
70 String landuse2 = wayOther.get("landuse");
71 boolean isWaterAreaTest = "water".equals(natural2) || "wetland".equals(natural2) || "coastline".equals(natural2) || "reservoir".equals(landuse2);
72
73 if (!isWaterArea2) {
74 isWaterArea2 = isWaterAreaTest;
75 }
76
77 if (isWaterArea && isWaterAreaTest) {
78 overlapsWater.add(wayOther);
79 } else {
80 overlapsOther.add(wayOther);
81 }
82 }
83
84 if (!overlapsWater.isEmpty()) {
85 errors.add(new TestError(this, Severity.WARNING, tr("Overlapping Water Areas"),
86 OVERLAPPING_AREAS, Collections.singletonList(w), overlapsWater));
87 }
88
89 if (!overlapsOther.isEmpty()) {
90 errors.add(new TestError(this, Severity.OTHER, tr("Overlapping Areas"),
91 OVERLAPPING_AREAS, Collections.singletonList(w), overlapsOther));
92 }
93 }
94 }
95
96 super.endTest();
97 }
98
99}
Note: See TracBrowser for help on using the repository browser.