Ticket #17188: 17188-v1.patch

File 17188-v1.patch, 3.5 KB (added by reichg, 5 years ago)

patch looks for nodes alongs ways with bus=yes and public_transport=stop_position that do not have a Node with highway=bus_stop and bus=yes within ~25 meters.

  • 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            List<Node> nearbyNodesWithinTwentyFiveMeters = getNearbyNodesWithinShortDistance(n, 0.0002);
     262            for (Node nearbyNodeWithinTwentyFiveMeters : nearbyNodesWithinTwentyFiveMeters) {
     263                if (nearbyNodeWithinTwentyFiveMeters.hasTag(HIGHWAY, "bus_stop") && nearbyNodeWithinTwentyFiveMeters.hasTag(BUS, "yes")) {
     264                    countOfNodesWithProperTags += 1;
     265                }
     266            }
     267            if (countOfNodesWithProperTags == 0) {
     268                errors.add(TestError.builder(this, Severity.WARNING, SOURCE_BUS_STOP_NEEDED)
     269                        .message(tr("Node {2} needs a nearby related node with tags: {0} and {1}.",
     270                                "highway=bus_stop", "bus=yes", n.getOsmId()))
     271                        .primitives(n)
     272                        .build());
     273            }
     274        }
     275        return;
     276    }
     277
     278    /**
     279     * Gathers list of Nodes within specified approximate distance (takes double but unit is LatLon degrees) of Node n.
     280     * @param n Node being visited
     281     * @param expanseDistance Distance to expand Node bounds. Units are in LatLon degrees.
     282     * @return List of Nodes
     283     */
     284    public List<Node> getNearbyNodesWithinShortDistance(Node n, double expanseDistance) {
     285
     286        DataSet nodeDataSet = n.getDataSet();
     287
     288        BBox nodeBBox= n.getBBox();
     289        nodeBBox.addLatLon(nodeBBox.getCenter(), expanseDistance);
     290
     291        return nodeDataSet.searchNodes(nodeBBox);
     292    }
     293
    246294    private void handleCarWay(Node n, Way w) {
    247295        carsWays++;
    248296        if (!w.isFirstLastNode(n) || carsWays > 1) {