Ticket #17188: 17188-v2.patch

File 17188-v2.patch, 3.6 KB (added by reichg, 3 years ago)

Adjusting distance to ~15 meters instead of 25 to fix reproducable issue provided with the data in the ticket.

  • src/org/openstreetmap/josm/data/validation/tests/Highways.java

     
    1515import java.util.stream.Collectors;
    1616
    1717import org.openstreetmap.josm.command.ChangePropertyCommand;
     18import org.openstreetmap.josm.data.osm.BBox;
     19import org.openstreetmap.josm.data.osm.DataSet;
    1820import org.openstreetmap.josm.data.osm.Node;
    1921import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2022import org.openstreetmap.josm.data.osm.OsmUtils;
     
    3840    protected static final int SOURCE_MAXSPEED_CONTEXT_MISMATCH_VS_MAXSPEED = 2705;
    3941    protected static final int SOURCE_MAXSPEED_CONTEXT_MISMATCH_VS_HIGHWAY = 2706;
    4042    protected static final int SOURCE_WRONG_LINK = 2707;
     43    protected static final int SOURCE_BUS_STOP_NEEDED = 2708;
    4144
    4245    protected static final String SOURCE_MAXSPEED = "source:maxspeed";
     46    protected static final String BUS = "bus";
     47    protected static final String PUBLIC_TRANSPORT = "public_transport";
    4348
    4449    /**
    4550     * Classified highways in order of importance
     
    9095                // as maxspeed is not set on highways here but on signs, speed cameras, etc.
    9196                testSourceMaxspeed(n, false);
    9297            }
     98
     99            // Test for 17188: complain about bus stop position without nearby highway=bus_stop
     100            testMissingBusStopNode(n);
    93101        }
    94102    }
    95103
     
    243251        }
    244252    }
    245253
     254    /**
     255     * Tests for bus stop ("public_transport"="stop_position"/"bus"="yes") Nodes a long a way that are missing a related nearby Node with "highway=bus_stop"
     256     * @param n Node being visited
     257     */
     258    public void testMissingBusStopNode(Node n) {
     259        if (n.hasTag(BUS, "yes") && n.hasTag(PUBLIC_TRANSPORT, "stop_position")) {
     260            int countOfNodesWithProperTags = 0;
     261            //Approximately 15 meters depending on Lat/Lon
     262            List<Node> nearbyNodesWithinTwentyFiveMeters = getNearbyNodesWithinShortDistance(n, 0.00015);
     263            for (Node nearbyNodeWithinTwentyFiveMeters : nearbyNodesWithinTwentyFiveMeters) {
     264                if (nearbyNodeWithinTwentyFiveMeters.hasTag(HIGHWAY, "bus_stop") && nearbyNodeWithinTwentyFiveMeters.hasTag(BUS, "yes")) {
     265                    countOfNodesWithProperTags += 1;
     266                }
     267            }
     268            if (countOfNodesWithProperTags == 0) {
     269                errors.add(TestError.builder(this, Severity.WARNING, SOURCE_BUS_STOP_NEEDED)
     270                        .message(tr("Node {2} needs a nearby related node with tags: {0} and {1}.",
     271                                "highway=bus_stop", "bus=yes", n.getOsmId()))
     272                        .primitives(n)
     273                        .build());
     274            }
     275        }
     276        return;
     277    }
     278
     279    /**
     280     * Gathers list of Nodes within specified approximate distance (takes double but unit is LatLon degrees) of Node n.
     281     * @param n Node being visited
     282     * @param expanseDistance Distance to expand Node bounds. Units are in LatLon degrees.
     283     * @return List of Nodes
     284     */
     285    public List<Node> getNearbyNodesWithinShortDistance(Node n, double expanseDistance) {
     286
     287        DataSet nodeDataSet = n.getDataSet();
     288
     289        BBox nodeBBox= n.getBBox();
     290        nodeBBox.addLatLon(nodeBBox.getCenter(), expanseDistance);
     291
     292        return nodeDataSet.searchNodes(nodeBBox);
     293    }
     294
    246295    private void handleCarWay(Node n, Way w) {
    247296        carsWays++;
    248297        if (!w.isFirstLastNode(n) || carsWays > 1) {