source: josm/trunk/src/org/openstreetmap/josm/data/validation/tests/UntaggedWay.java@ 5352

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

fix #7874 - do not warn about "untagged ways" that are relation members with role "outer", "inner", "perimeter", "edge" or "outline"

  • Property svn:eol-style set to native
File size: 5.4 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.HashSet;
7import java.util.Map;
8import java.util.Set;
9
10import org.openstreetmap.josm.Main;
11import org.openstreetmap.josm.command.Command;
12import org.openstreetmap.josm.data.osm.OsmPrimitive;
13import org.openstreetmap.josm.data.osm.Relation;
14import org.openstreetmap.josm.data.osm.RelationMember;
15import org.openstreetmap.josm.data.osm.Way;
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.gui.progress.ProgressMonitor;
20
21/**
22 * Checks for untagged ways
23 *
24 * @author frsantos
25 */
26public class UntaggedWay extends Test
27{
28 /** Empty way error */
29 protected static final int EMPTY_WAY = 301;
30 /** Untagged way error */
31 protected static final int UNTAGGED_WAY = 302;
32 /** Unnamed way error */
33 protected static final int UNNAMED_WAY = 303;
34 /** One node way error */
35 protected static final int ONE_NODE_WAY = 304;
36 /** Unnamed junction error */
37 protected static final int UNNAMED_JUNCTION = 305;
38 /** Untagged, but commented way error */
39 protected static final int COMMENTED_WAY = 306;
40
41 private Set<Way> waysUsedInRelations;
42
43 /** Ways that must have a name */
44 public static final Set<String> NAMED_WAYS = new HashSet<String>();
45 static {
46 NAMED_WAYS.add( "motorway" );
47 NAMED_WAYS.add( "trunk" );
48 NAMED_WAYS.add( "primary" );
49 NAMED_WAYS.add( "secondary" );
50 NAMED_WAYS.add( "tertiary" );
51 NAMED_WAYS.add( "residential" );
52 NAMED_WAYS.add( "pedestrian" ); ;
53 }
54
55 /** Whitelist of roles allowed to reference an untagged way */
56 public static final Set<String> WHITELIST = new HashSet<String>();
57 static {
58 WHITELIST.add( "outer" );
59 WHITELIST.add( "inner" );
60 WHITELIST.add( "perimeter" );
61 WHITELIST.add( "edge" );
62 WHITELIST.add( "outline" );
63 }
64
65 /**
66 * Constructor
67 */
68 public UntaggedWay() {
69 super(tr("Untagged, empty and one node ways"),
70 tr("This test checks for untagged, empty and one node ways."));
71 }
72
73 @Override
74 public void visit(Way w) {
75 if (!w.isUsable())
76 return;
77
78 Map<String, String> tags = w.getKeys();
79 if (!tags.isEmpty()) {
80 String highway = tags.get("highway");
81 if (highway != null && NAMED_WAYS.contains(highway)) {
82 if (!tags.containsKey("name") && !tags.containsKey("ref")) {
83 boolean isRoundabout = false;
84 boolean hasName = false;
85 for (String key : w.keySet()) {
86 hasName = key.startsWith("name:") || key.endsWith("_name") || key.endsWith("_ref");
87 if (hasName) {
88 break;
89 }
90 if (key.equals("junction")) {
91 isRoundabout = w.get("junction").equals("roundabout");
92 break;
93 }
94 }
95
96 if (!hasName && !isRoundabout) {
97 errors.add(new TestError(this, Severity.WARNING, tr("Unnamed ways"), UNNAMED_WAY, w));
98 } else if (isRoundabout) {
99 errors.add(new TestError(this, Severity.WARNING, tr("Unnamed junction"), UNNAMED_JUNCTION, w));
100 }
101 }
102 }
103 }
104
105 if (!w.isTagged() && !waysUsedInRelations.contains(w)) {
106 if (w.hasKeys()) {
107 errors.add(new TestError(this, Severity.WARNING, tr("Untagged ways (commented)"), COMMENTED_WAY, w));
108 } else {
109 errors.add(new TestError(this, Severity.WARNING, tr("Untagged ways"), UNTAGGED_WAY, w));
110 }
111 }
112
113 if (w.getNodesCount() == 0) {
114 errors.add(new TestError(this, Severity.ERROR, tr("Empty ways"), EMPTY_WAY, w));
115 } else if (w.getNodesCount() == 1) {
116 errors.add(new TestError(this, Severity.ERROR, tr("One node ways"), ONE_NODE_WAY, w));
117 }
118 }
119
120 @Override
121 public void startTest(ProgressMonitor monitor) {
122 super.startTest(monitor);
123 waysUsedInRelations = new HashSet<Way>();
124 for (Relation r : Main.main.getCurrentDataSet().getRelations()) {
125 if (r.isUsable()) {
126 for (RelationMember m : r.getMembers()) {
127 if (r.isMultipolygon() || WHITELIST.contains(m.getRole())) {
128 OsmPrimitive member = m.getMember();
129 if (member != null && member instanceof Way && member.isUsable() && !member.isTagged()) {
130 waysUsedInRelations.add((Way)member);
131 }
132 }
133 }
134 }
135 }
136 }
137
138 @Override
139 public void endTest() {
140 waysUsedInRelations = null;
141 super.endTest();
142 }
143
144 @Override
145 public boolean isFixable(TestError testError) {
146 if (testError.getTester() instanceof UntaggedWay)
147 return testError.getCode() == EMPTY_WAY
148 || testError.getCode() == ONE_NODE_WAY;
149
150 return false;
151 }
152
153 @Override
154 public Command fixError(TestError testError) {
155 return deletePrimitivesIfNeeded(testError.getPrimitives());
156 }
157}
Note: See TracBrowser for help on using the repository browser.