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

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