source: josm/trunk/src/org/openstreetmap/josm/data/validation/tests/UnclosedWays.java@ 4448

Last change on this file since 4448 was 4447, checked in by simon04, 13 years ago

fix #6799 - MultipolygonTest: wrong objects in unclosed relation

  • Property svn:eol-style set to native
File size: 3.7 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.marktr;
5import static org.openstreetmap.josm.tools.I18n.tr;
6
7import java.text.MessageFormat;
8import java.util.Arrays;
9
10import org.openstreetmap.josm.data.osm.OsmPrimitive;
11import org.openstreetmap.josm.data.osm.OsmUtils;
12import org.openstreetmap.josm.data.osm.Relation;
13import org.openstreetmap.josm.data.osm.Way;
14import org.openstreetmap.josm.data.validation.Severity;
15import org.openstreetmap.josm.data.validation.Test;
16import org.openstreetmap.josm.data.validation.TestError;
17import org.openstreetmap.josm.gui.progress.ProgressMonitor;
18
19/**
20 * Check area type ways for errors
21 *
22 * @author stoecker
23 */
24public class UnclosedWays extends Test {
25
26 /**
27 * Constructor
28 */
29 public UnclosedWays() {
30 super(tr("Unclosed Ways."), tr("This tests if ways which should be circular are closed."));
31 }
32
33 @Override
34 public void startTest(ProgressMonitor monitor) {
35 super.startTest(monitor);
36 }
37
38 @Override
39 public void endTest() {
40 super.endTest();
41 }
42
43 private String type;
44 private String etype;
45 private int mode;
46
47 public void set(int m, String text, String desc) {
48 etype = MessageFormat.format(text, desc);
49 type = tr(text, tr(desc));
50 mode = m;
51 }
52
53 public void set(int m, String text) {
54 etype = text;
55 type = tr(text);
56 mode = m;
57 }
58
59 @Override
60 public void visit(Way w) {
61 String test;
62 type = etype = null;
63 mode = 0;
64
65 if (!w.isUsable())
66 return;
67
68 test = w.get("natural");
69 if (test != null && !"coastline".equals(test) && !"cliff".equals(test) && !"tree_row".equals(test)) {
70 set(1101, marktr("natural type {0}"), test);
71 }
72 test = w.get("landuse");
73 if (test != null) {
74 set(1102, marktr("landuse type {0}"), test);
75 }
76 test = w.get("amenities");
77 if (test != null) {
78 set(1103, marktr("amenities type {0}"), test);
79 }
80 test = w.get("sport");
81 if (test != null && !test.equals("water_slide")) {
82 set(1104, marktr("sport type {0}"), test);
83 }
84 test = w.get("tourism");
85 if (test != null) {
86 set(1105, marktr("tourism type {0}"), test);
87 }
88 test = w.get("shop");
89 if (test != null) {
90 set(1106, marktr("shop type {0}"), test);
91 }
92 test = w.get("leisure");
93 if (test != null && !"track".contains(test)) {
94 set(1107, marktr("leisure type {0}"), test);
95 }
96 test = w.get("waterway");
97 if (test != null && test.equals("riverbank")) {
98 set(1108, marktr("waterway type {0}"), test);
99 }
100 Boolean btest = OsmUtils.getOsmBoolean(w.get("building"));
101 if (btest != null && btest) {
102 set(1120, marktr("building"));
103 }
104 btest = OsmUtils.getOsmBoolean(w.get("area"));
105 if (btest != null && btest) {
106 set(1130, marktr("area"));
107 }
108
109 if (type != null && !w.isClosed()) {
110 for (OsmPrimitive parent: w.getReferrers()) {
111 if (parent instanceof Relation && ((Relation)parent).isMultipolygon())
112 return;
113 }
114
115 errors.add(new TestError(this, Severity.WARNING, tr("Unclosed way"),
116 type, etype, mode,
117 Arrays.asList(w),
118 // The important parts of an unclosed way are the first and
119 // the last node which should be connected, therefore we highlight them
120 Arrays.asList(w.firstNode(), w.lastNode())));
121 }
122 }
123}
Note: See TracBrowser for help on using the repository browser.