Legend:
- Unmodified
- Added
- Removed
-
trunk/resources/data/validator/geometry.mapcss
r17106 r17111 345 345 } 346 346 347 /* #12577 */348 way[power=line] > node,349 way[power=minor_line] > node,350 way[power=cable] > node {351 set node_in_power_way;352 }353 way[!power][!building] > node.node_in_power_way {354 throwWarning: tr("Node connects a power line or cable with an object which is not related to the power infrastructure.");355 }356 357 347 /* #12646, #12992, #16334 */ 358 348 way[waterway=~/^(stream|river|drain)$/]!:closed >[index=-1] node[natural!=sinkhole][natural!=cave_entrance]!:connection:in-downloaded-area { -
trunk/src/org/openstreetmap/josm/data/validation/tests/PowerLines.java
r16445 r17111 7 7 import java.util.Arrays; 8 8 import java.util.Collection; 9 import java.util.LinkedHashSet; 9 10 import java.util.List; 11 import java.util.Set; 10 12 11 13 import org.openstreetmap.josm.data.osm.Node; 12 14 import org.openstreetmap.josm.data.osm.OsmPrimitive; 13 15 import org.openstreetmap.josm.data.osm.Relation; 16 import org.openstreetmap.josm.data.osm.RelationMember; 14 17 import org.openstreetmap.josm.data.osm.Way; 15 18 import org.openstreetmap.josm.data.osm.visitor.paint.relations.Multipolygon; … … 30 33 /** Test identifier */ 31 34 protected static final int POWER_LINES = 2501; 35 protected static final int POWER_CONNECTION = 2502; 32 36 33 37 /** Values for {@code power} key interpreted as power lines */ … … 43 47 "portal", "terminal", "insulator"); 44 48 45 private final List<TestError> potentialErrors = new ArrayList<>(); 49 private final Set<Node> badConnections = new LinkedHashSet<>(); 50 private final Set<Node> missingTowerOrPole = new LinkedHashSet<>(); 46 51 47 52 private final List<OsmPrimitive> powerStations = new ArrayList<>(); … … 61 66 if (!isPowerTower(n) && !isPowerAllowed(n) && IN_DOWNLOADED_AREA.test(n) 62 67 && (!w.isFirstLastNode(n) || !isPowerStation(n))) { 63 potentialErrors.add(TestError.builder(this, Severity.WARNING, POWER_LINES) 64 .message(tr("Missing power tower/pole within power line")) 65 .primitives(n) 66 .build()); 68 missingTowerOrPole.add(n); 67 69 } 68 70 } … … 71 73 } 72 74 } 75 } 76 77 @Override 78 public void visit(Node n) { 79 boolean nodeInLineOrCable = false; 80 boolean connectedToUnrelated = false; 81 for (Way parent : n.getParentWays()) { 82 if (parent.hasTag("power", "line", "minor_line", "cable")) 83 nodeInLineOrCable = true; 84 else if (!isRelatedToPower(parent)) { 85 connectedToUnrelated = true; 86 } 87 } 88 if (nodeInLineOrCable && connectedToUnrelated) 89 badConnections.add(n); 90 } 91 92 private static boolean isRelatedToPower(Way way) { 93 if (way.hasTag("power") || way.hasTag("building")) 94 return true; 95 for (OsmPrimitive ref : way.getReferrers()) { 96 if (ref instanceof Relation && ref.isMultipolygon() && (ref.hasTag("power") || ref.hasTag("building"))) { 97 for (RelationMember rm : ((Relation) ref).getMembers()) { 98 if (way == rm.getMember()) 99 return true; 100 } 101 } 102 } 103 return false; 73 104 } 74 105 … … 83 114 public void startTest(ProgressMonitor progressMonitor) { 84 115 super.startTest(progressMonitor); 85 powerStations.clear(); 86 potentialErrors.clear(); 116 clearCollections(); 87 117 } 88 118 89 119 @Override 90 120 public void endTest() { 91 for (TestError e : potentialErrors) { 92 e.primitives(Node.class) 93 .filter(n -> !isInPowerStation(n)) 94 .findAny() 95 .ifPresent(ignore -> errors.add(e)); 96 } 97 potentialErrors.clear(); 98 powerStations.clear(); 121 for (Node n : missingTowerOrPole) { 122 if (!isInPowerStation(n)) { 123 errors.add(TestError.builder(this, Severity.WARNING, POWER_LINES) 124 .message(tr("Missing power tower/pole within power line")) 125 .primitives(n) 126 .build()); 127 } 128 } 129 130 for (Node n : badConnections) { 131 errors.add(TestError.builder(this, Severity.WARNING, POWER_CONNECTION) 132 .message(tr("Node connects a power line or cable with an object " 133 + "which is not related to the power infrastructure.")) 134 .primitives(n).build()); 135 } 136 clearCollections(); 99 137 super.endTest(); 100 138 } … … 177 215 return p.hasTag("building", values); 178 216 } 217 218 private void clearCollections() { 219 powerStations.clear(); 220 badConnections.clear(); 221 missingTowerOrPole.clear(); 222 } 179 223 }
Note:
See TracChangeset
for help on using the changeset viewer.