source: josm/trunk/src/org/openstreetmap/josm/data/validation/tests/OverlappingWays.java@ 3673

Last change on this file since 3673 was 3671, checked in by bastiK, 13 years ago

adapt coding style (to some degree); there shouldn't be any semantic changes in this commit

  • Property svn:eol-style set to native
File size: 5.8 KB
Line 
1// License: GPL. See LICENSE file for details.
2package org.openstreetmap.josm.data.validation.tests;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.util.ArrayList;
7import java.util.HashMap;
8import java.util.List;
9import java.util.Map;
10
11import org.openstreetmap.josm.data.osm.Node;
12import org.openstreetmap.josm.data.osm.OsmPrimitive;
13import org.openstreetmap.josm.data.osm.OsmUtils;
14import org.openstreetmap.josm.data.osm.Way;
15import org.openstreetmap.josm.data.osm.WaySegment;
16import org.openstreetmap.josm.data.validation.Severity;
17import org.openstreetmap.josm.data.validation.Test;
18import org.openstreetmap.josm.data.validation.TestError;
19import org.openstreetmap.josm.data.validation.util.Bag;
20import org.openstreetmap.josm.gui.progress.ProgressMonitor;
21import org.openstreetmap.josm.tools.Pair;
22
23/**
24 * Tests if there are overlapping ways
25 *
26 * @author frsantos
27 */
28public class OverlappingWays extends Test {
29
30 /** Bag of all way segments */
31 Bag<Pair<Node,Node>, WaySegment> nodePairs;
32
33 protected static int OVERLAPPING_HIGHWAY = 101;
34 protected static int OVERLAPPING_RAILWAY = 102;
35 protected static int OVERLAPPING_WAY = 103;
36 protected static int OVERLAPPING_HIGHWAY_AREA = 111;
37 protected static int OVERLAPPING_RAILWAY_AREA = 112;
38 protected static int OVERLAPPING_WAY_AREA = 113;
39 protected static int OVERLAPPING_AREA = 120;
40
41 /** Constructor */
42 public OverlappingWays() {
43 super(tr("Overlapping ways."),
44 tr("This test checks that a connection between two nodes "
45 + "is not used by more than one way."));
46 }
47
48 @Override
49 public void startTest(ProgressMonitor monitor) {
50 super.startTest(monitor);
51 nodePairs = new Bag<Pair<Node,Node>, WaySegment>(1000);
52 }
53
54 @Override
55 public void endTest() {
56 Map<List<Way>, List<WaySegment>> ways_seen = new HashMap<List<Way>, List<WaySegment>>(500);
57
58 for (List<WaySegment> duplicated : nodePairs.values()) {
59 int ways = duplicated.size();
60
61 if (ways > 1) {
62 List<OsmPrimitive> prims = new ArrayList<OsmPrimitive>();
63 List<Way> current_ways = new ArrayList<Way>();
64 List<WaySegment> highlight;
65 int highway = 0;
66 int railway = 0;
67 int area = 0;
68
69 for (WaySegment ws : duplicated) {
70 if (ws.way.get("highway") != null) {
71 highway++;
72 } else if (ws.way.get("railway") != null) {
73 railway++;
74 }
75 Boolean ar = OsmUtils.getOsmBoolean(ws.way.get("area"));
76 if (ar != null && ar) {
77 area++;
78 }
79 if (ws.way.get("landuse") != null
80 || ws.way.get("natural") != null
81 || ws.way.get("amenity") != null
82 || ws.way.get("leisure") != null
83 || ws.way.get("building") != null) {
84 area++;
85 ways--;
86 }
87
88 prims.add(ws.way);
89 current_ways.add(ws.way);
90 }
91 /* These ways not seen before
92 * If two or more of the overlapping ways are
93 * highways or railways mark a separate error
94 */
95 if ((highlight = ways_seen.get(current_ways)) == null) {
96 String errortype;
97 int type;
98
99 if (area > 0) {
100 if (ways == 0 || duplicated.size() == area) {
101 errortype = tr("Overlapping areas");
102 type = OVERLAPPING_AREA;
103 } else if (highway == ways) {
104 errortype = tr("Overlapping highways (with area)");
105 type = OVERLAPPING_HIGHWAY_AREA;
106 } else if (railway == ways) {
107 errortype = tr("Overlapping railways (with area)");
108 type = OVERLAPPING_RAILWAY_AREA;
109 } else {
110 errortype = tr("Overlapping ways (with area)");
111 type = OVERLAPPING_WAY_AREA;
112 }
113 }
114 else if (highway == ways) {
115 errortype = tr("Overlapping highways");
116 type = OVERLAPPING_HIGHWAY;
117 } else if (railway == ways) {
118 errortype = tr("Overlapping railways");
119 type = OVERLAPPING_RAILWAY;
120 } else {
121 errortype = tr("Overlapping ways");
122 type = OVERLAPPING_WAY;
123 }
124
125 errors.add(new TestError(this,
126 type < OVERLAPPING_HIGHWAY_AREA ? Severity.WARNING : Severity.OTHER,
127 tr(errortype), type, prims, duplicated));
128 ways_seen.put(current_ways, duplicated);
129 } else { /* way seen, mark highlight layer only */
130 for (WaySegment ws : duplicated) {
131 highlight.add(ws);
132 }
133 }
134 }
135 }
136 super.endTest();
137 nodePairs = null;
138 }
139
140 @Override
141 public void visit(Way w) {
142 Node lastN = null;
143 int i = -2;
144 for (Node n : w.getNodes()) {
145 i++;
146 if (lastN == null) {
147 lastN = n;
148 continue;
149 }
150 nodePairs.add(Pair.sort(new Pair<Node,Node>(lastN, n)),
151 new WaySegment(w, i));
152 lastN = n;
153 }
154 }
155}
Note: See TracBrowser for help on using the repository browser.