diff --git a/src/org/openstreetmap/josm/data/validation/tests/PowerLines.java b/src/org/openstreetmap/josm/data/validation/tests/PowerLines.java
index fa5d1e273f..23cd15063b 100644
|
a
|
b
|
import static org.openstreetmap.josm.tools.I18n.tr;
|
| 5 | 5 | |
| 6 | 6 | import java.awt.geom.Point2D; |
| 7 | 7 | import java.util.ArrayList; |
| 8 | | import java.util.Arrays; |
| 9 | 8 | import java.util.Collection; |
| 10 | | import java.util.Collections; |
| 11 | 9 | import java.util.EnumSet; |
| 12 | 10 | import java.util.HashMap; |
| 13 | 11 | import java.util.HashSet; |
| … |
… |
public class PowerLines extends Test {
|
| 65 | 63 | protected static final String PREFIX = ValidatorPrefHelper.PREFIX + "." + PowerLines.class.getSimpleName(); |
| 66 | 64 | |
| 67 | 65 | /** Values for {@code power} key interpreted as power lines */ |
| 68 | | static final Collection<String> POWER_LINE_TAGS = Arrays.asList("line", MINOR_LINE); |
| | 66 | static final Set<String> POWER_LINE_TAGS = Set.of("line", MINOR_LINE); |
| 69 | 67 | /** Values for {@code power} key interpreted as power towers */ |
| 70 | | static final Collection<String> POWER_TOWER_TAGS = Arrays.asList("catenary_mast", "pole", "portal", "tower"); |
| | 68 | static final Set<String> POWER_TOWER_TAGS = Set.of("catenary_mast", "pole", "portal", "tower"); |
| 71 | 69 | /** Values for {@code power} key interpreted as power stations */ |
| 72 | | static final Collection<String> POWER_STATION_TAGS = Arrays.asList("generator", "plant", "substation"); |
| | 70 | static final Set<String> POWER_STATION_TAGS = Set.of("generator", "plant", "substation"); |
| 73 | 71 | /** Values for {@code building} key interpreted as power stations */ |
| 74 | | static final Collection<String> BUILDING_STATION_TAGS = Collections.singletonList("transformer_tower"); |
| | 72 | static final Set<String> BUILDING_STATION_TAGS = Set.of("transformer_tower"); |
| 75 | 73 | /** Values for {@code power} key interpreted as allowed power items */ |
| 76 | | static final Collection<String> POWER_INFRASTRUCTURE_TAGS = Arrays.asList("compensator", "connection", "converter", |
| | 74 | static final Set<String> POWER_INFRASTRUCTURE_TAGS = Set.of("compensator", "connection", "converter", |
| 77 | 75 | "generator", "insulator", "switch", "switchgear", "terminal", "transformer"); |
| 78 | 76 | |
| | 77 | /** Values for {@code power} key interpreted as power lines or cables */ |
| | 78 | private static final Set<String> POWER_LINE_OR_CABLE_TAGS = Set.of("line", MINOR_LINE, "cable"); |
| | 79 | |
| 79 | 80 | private double hillyCompensation; |
| 80 | 81 | private double hillyThreshold; |
| 81 | 82 | private final Map<Node, Set<OsmPrimitive>> badConnections = new HashMap<>(); |
| … |
… |
public class PowerLines extends Test {
|
| 189 | 190 | errors.add(TestError.builder(this, Severity.WARNING, POWER_SEGMENT_LENGTH) |
| 190 | 191 | .message(tr("Possibly missing line support node within power line")) |
| 191 | 192 | .primitives(s.getFirstNode(), s.getSecondNode()) |
| 192 | | .highlightWaySegments(new HashSet<>(Collections.singleton(s))) |
| | 193 | .highlightWaySegments(Set.of(s)) |
| 193 | 194 | .build()); |
| 194 | 195 | } |
| 195 | 196 | |
| … |
… |
public class PowerLines extends Test {
|
| 249 | 250 | final double mean = w.getLength() / segmentCount; |
| 250 | 251 | final double stdDev = Utils.getStandardDeviation(w.getSegmentLengths(), mean); |
| 251 | 252 | final boolean isContinuesAsMinorLine = isContinuesAsMinorLine(w); |
| 252 | | boolean isCrossingWater = false; |
| | 253 | // the crossings only depend on the way, so look them up once instead of for every node |
| | 254 | final Set<Way> crossingWaterWays = new HashSet<>(8); |
| | 255 | final Set<ILatLon> crossingPositions = new HashSet<>(8); |
| | 256 | findCrossings(this.cellSegmentsWater, w, crossingWaterWays, crossingPositions); |
| | 257 | final boolean isCrossingWater = !crossingWaterWays.isEmpty(); |
| 253 | 258 | int poleCount = 0; |
| 254 | 259 | int towerCount = 0; |
| 255 | 260 | Node prevNode = w.firstNode(); |
| … |
… |
public class PowerLines extends Test {
|
| 277 | 282 | |
| 278 | 283 | /// handle missing nodes |
| 279 | 284 | double segmentLen = n.greatCircleDistance(prevNode); |
| 280 | | final Set<Way> crossingWaterWays = new HashSet<>(8); |
| 281 | | final Set<ILatLon> crossingPositions = new HashSet<>(8); |
| 282 | | findCrossings(this.cellSegmentsWater, w, crossingWaterWays, crossingPositions); |
| 283 | | |
| 284 | | if (!crossingWaterWays.isEmpty()) { |
| | 285 | if (isCrossingWater) { |
| 285 | 286 | double compensation = calculateIntersectingLen(prevNode, crossingPositions); |
| 286 | 287 | segmentLen -= compensation; |
| 287 | 288 | } |
| … |
… |
public class PowerLines extends Test {
|
| 293 | 294 | missingNodes.add(WaySegment.forNodePair(w, prevNode, n)); |
| 294 | 295 | |
| 295 | 296 | /// handle wrong line types |
| 296 | | if (!crossingWaterWays.isEmpty()) |
| 297 | | isCrossingWater = true; |
| 298 | | |
| 299 | 297 | if (n.hasTag(POWER, "pole")) |
| 300 | 298 | poleCount++; |
| 301 | 299 | else if (n.hasTag(POWER, "tower", "portal")) |
| … |
… |
public class PowerLines extends Test {
|
| 599 | 597 | if (way.hasTag(POWER) || way.hasTag(BUILDING)) |
| 600 | 598 | return true; |
| 601 | 599 | for (OsmPrimitive ref : way.getReferrers()) { |
| 602 | | if (ref instanceof Relation && ref.isMultipolygon() && (ref.hasTag(POWER) || ref.hasTag(BUILDING))) { |
| 603 | | for (RelationMember rm : ((Relation) ref).getMembers()) { |
| 604 | | if (way == rm.getMember()) |
| 605 | | return true; |
| | 600 | if (ref instanceof Relation) { |
| | 601 | Relation r = (Relation) ref; |
| | 602 | if (r.isMultipolygon() && (r.hasTag(POWER) || r.hasTag(BUILDING))) { |
| | 603 | for (RelationMember rm : r.getMembers()) { |
| | 604 | if (rm.getMember() == way) |
| | 605 | return true; |
| | 606 | } |
| 606 | 607 | } |
| 607 | 608 | } |
| 608 | 609 | } |
| … |
… |
public class PowerLines extends Test {
|
| 658 | 659 | */ |
| 659 | 660 | protected final boolean isInPowerStation(Node n) { |
| 660 | 661 | for (OsmPrimitive station : powerStations) { |
| 661 | | List<List<Node>> nodesLists = new ArrayList<>(); |
| 662 | 662 | if (station instanceof Way) { |
| 663 | | nodesLists.add(((Way) station).getNodes()); |
| | 663 | if (Geometry.nodeInsidePolygon(n, ((Way) station).getNodes())) { |
| | 664 | return true; |
| | 665 | } |
| 664 | 666 | } else if (station instanceof Relation) { |
| 665 | 667 | Multipolygon polygon = MultipolygonCache.getInstance().get((Relation) station); |
| 666 | 668 | if (polygon != null) { |
| 667 | 669 | for (JoinedWay outer : Multipolygon.joinWays(polygon.getOuterWays())) { |
| 668 | | nodesLists.add(outer.getNodes()); |
| | 670 | if (Geometry.nodeInsidePolygon(n, outer.getNodes())) { |
| | 671 | return true; |
| | 672 | } |
| 669 | 673 | } |
| 670 | 674 | } |
| 671 | 675 | } |
| 672 | | for (List<Node> nodes : nodesLists) { |
| 673 | | if (Geometry.nodeInsidePolygon(n, nodes)) { |
| 674 | | return true; |
| 675 | | } |
| 676 | | } |
| 677 | 676 | } |
| 678 | 677 | return false; |
| 679 | 678 | } |
| … |
… |
public class PowerLines extends Test {
|
| 693 | 692 | * @return {@code true} if power key is set and equal to line,minor_line or cable |
| 694 | 693 | */ |
| 695 | 694 | protected static boolean isPowerLineOrCable(Way w) { |
| 696 | | return isPowerIn(w, Arrays.asList("line", MINOR_LINE, "cable")); |
| | 695 | return isPowerIn(w, POWER_LINE_OR_CABLE_TAGS); |
| 697 | 696 | } |
| 698 | 697 | |
| 699 | 698 | /** |