Ticket #24851: 24851-powerlines.patch
| File 24851-powerlines.patch, 4.7 KB (added by , 33 hours ago) |
|---|
-
src/org/openstreetmap/josm/data/validation/tests/PowerLines.java
11 11 import java.util.EnumSet; 12 12 import java.util.HashMap; 13 13 import java.util.HashSet; 14 import java.util.LinkedHashSet; 14 15 import java.util.List; 15 16 import java.util.Map; 17 import java.util.Map.Entry; 16 18 import java.util.Set; 17 19 18 20 import org.openstreetmap.josm.data.coor.ILatLon; … … 75 77 76 78 private double hillyCompensation; 77 79 private double hillyThreshold; 78 private final Set<Node> badConnections = new HashSet<>();79 private final Set<Node> missingTags = new HashSet<>();80 private final Map<Node, Set<OsmPrimitive>> badConnections = new HashMap<>(); 81 private final Map<Node, Set<OsmPrimitive>> missingTags = new HashMap<>(); 80 82 private final Set<Way> wrongLineType = new HashSet<>(); 81 83 private final Set<WaySegment> missingNodes = new HashSet<>(); 82 84 private final Set<OsmPrimitive> refDiscontinuities = new HashSet<>(); … … 99 101 @Override 100 102 public void visit(Node n) { 101 103 boolean nodeInLineOrCable = false; 102 boolean connectedToUnrelated = false;104 List<Way> unrelatedParents = new ArrayList<>(); 103 105 for (Way parent : n.getParentWays()) { 104 106 if (parent.hasTag(POWER, "line", MINOR_LINE, "cable")) 105 107 nodeInLineOrCable = true; 106 108 else if (!isRelatedToPower(parent)) 107 connectedToUnrelated = true;109 unrelatedParents.add(parent); 108 110 } 109 if (nodeInLineOrCable && connectedToUnrelated) 110 badConnections.add(n); 111 if (nodeInLineOrCable && !unrelatedParents.isEmpty()) { 112 Set<OsmPrimitive> old = badConnections.get(n); 113 if (old == null) { 114 old = new HashSet<>(); 115 badConnections.put(n, old); 116 } 117 old.addAll(unrelatedParents); 118 } 111 119 } 112 120 113 121 @Override … … 162 170 powerlineChecks(w); 163 171 } 164 172 // Then return the errors 165 for (Node n : missingTags) { 173 for (Entry<Node, Set<OsmPrimitive>> entry : missingTags.entrySet()) { 174 Node n = entry.getKey(); 166 175 if (!isInPowerStation(n)) { 167 176 errors.add(TestError.builder(this, Severity.WARNING, POWER_SUPPORT) 168 177 // the "missing tag" grouping can become broken if the MapCSS message get reworded 169 178 .message(tr("missing tag"), tr("node without power=*")) 170 .primitives(n) 179 .primitives(getAllPrimitives(entry)) 180 .highlight(n) 171 181 .build()); 172 182 } 173 183 } 174 184 175 for ( Node n : badConnections) {185 for (Entry<Node, Set<OsmPrimitive>> entry : badConnections.entrySet()) { 176 186 errors.add(TestError.builder(this, Severity.WARNING, POWER_CONNECTION) 177 187 .message(tr("Node connects a power line or cable with an object " 178 188 + "which is not related to the power infrastructure")) 179 .primitives(n) 189 .primitives(getAllPrimitives(entry)) 190 .highlight(entry.getKey()) 180 191 .build()); 181 192 } 182 193 … … 224 235 } 225 236 226 237 /** 238 * Combine the node and the related objects. 239 * @param entry a map entry with a node and related objects 240 * @return set containing the node and the related objects 241 */ 242 private Collection<? extends OsmPrimitive> getAllPrimitives(Entry<Node, Set<OsmPrimitive>> entry) { 243 Set<OsmPrimitive> primitives = new LinkedHashSet<>(); 244 primitives.add(entry.getKey()); 245 primitives.addAll(entry.getValue()); 246 return primitives; 247 } 248 249 /** 227 250 * The base powerline checks 228 251 * @param w The powerline to check 229 252 */ … … 253 276 254 277 /// handle missing power line support tags (e.g. tower) 255 278 if (!isPowerTower(n) && !isPowerInfrastructure(n) && IN_DOWNLOADED_AREA.test(n) 256 && (!w.isFirstLastNode(n) || !isPowerStation(n))) 257 missingTags.add(n); 279 && (!w.isFirstLastNode(n) || !isPowerStation(n))) { 280 Set<OsmPrimitive> old = missingTags.get(n); 281 if (old == null) { 282 old = new HashSet<>(); 283 missingTags.put(n, old); 284 } 285 old.add(w); 286 } 258 287 259 288 /// handle missing nodes 260 289 double segmentLen = n.greatCircleDistance(prevNode);
