Search in sources :

Example 11 with Stop

use of com.conveyal.gtfs.model.Stop in project graphhopper by graphhopper.

the class PtLocationSnapper method snapAll.

public Result snapAll(List<GHLocation> locations, List<EdgeFilter> snapFilters) {
    PointList points = new PointList(2, false);
    ArrayList<Snap> pointSnaps = new ArrayList<>();
    ArrayList<Supplier<Label.NodeId>> allSnaps = new ArrayList<>();
    for (int i = 0; i < locations.size(); i++) {
        GHLocation location = locations.get(i);
        if (location instanceof GHPointLocation) {
            GHPoint point = ((GHPointLocation) location).ghPoint;
            final Snap closest = locationIndex.findClosest(point.lat, point.lon, snapFilters.get(i));
            if (!closest.isValid()) {
                IntHashSet result = new IntHashSet();
                gtfsStorage.getStopIndex().findEdgeIdsInNeighborhood(point.lat, point.lon, 0, result::add);
                gtfsStorage.getStopIndex().findEdgeIdsInNeighborhood(point.lat, point.lon, 1, result::add);
                if (result.isEmpty()) {
                    throw new PointNotFoundException("Cannot find point: " + point, i);
                }
                IntCursor stopNodeId = result.iterator().next();
                for (Map.Entry<GtfsStorage.FeedIdWithStopId, Integer> e : gtfsStorage.getStationNodes().entrySet()) {
                    if (e.getValue() == stopNodeId.value) {
                        Stop stop = gtfsStorage.getGtfsFeeds().get(e.getKey().feedId).stops.get(e.getKey().stopId);
                        final Snap stopSnap = new Snap(stop.stop_lat, stop.stop_lon);
                        stopSnap.setClosestNode(stopNodeId.value);
                        allSnaps.add(() -> new Label.NodeId(Optional.ofNullable(gtfsStorage.getPtToStreet().get(stopSnap.getClosestNode())).orElse(-1), stopSnap.getClosestNode()));
                        points.add(stopSnap.getQueryPoint().lat, stopSnap.getQueryPoint().lon);
                    }
                }
            } else {
                pointSnaps.add(closest);
                allSnaps.add(() -> new Label.NodeId(closest.getClosestNode(), Optional.ofNullable(gtfsStorage.getStreetToPt().get(closest.getClosestNode())).orElse(-1)));
                points.add(closest.getSnappedPoint());
            }
        } else if (location instanceof GHStationLocation) {
            final Snap stopSnap = findByStopId((GHStationLocation) location, i);
            allSnaps.add(() -> new Label.NodeId(Optional.ofNullable(gtfsStorage.getPtToStreet().get(stopSnap.getClosestNode())).orElse(-1), stopSnap.getClosestNode()));
            points.add(stopSnap.getQueryPoint().lat, stopSnap.getQueryPoint().lon);
        }
    }
    // modifies pointSnaps!
    QueryGraph queryGraph = QueryGraph.create(graphHopperStorage, pointSnaps);
    List<Label.NodeId> nodes = new ArrayList<>();
    for (Supplier<Label.NodeId> supplier : allSnaps) {
        nodes.add(supplier.get());
    }
    return new Result(queryGraph, nodes, points);
}
Also used : PointList(com.graphhopper.util.PointList) Stop(com.conveyal.gtfs.model.Stop) PointNotFoundException(com.graphhopper.util.exceptions.PointNotFoundException) ArrayList(java.util.ArrayList) IntHashSet(com.carrotsearch.hppc.IntHashSet) Snap(com.graphhopper.storage.index.Snap) IntCursor(com.carrotsearch.hppc.cursors.IntCursor) Supplier(java.util.function.Supplier) GHPoint(com.graphhopper.util.shapes.GHPoint) GHPoint(com.graphhopper.util.shapes.GHPoint) Map(java.util.Map) QueryGraph(com.graphhopper.routing.querygraph.QueryGraph)

Aggregations

Stop (com.conveyal.gtfs.model.Stop)11 GTFSFeed (com.conveyal.gtfs.GTFSFeed)4 StopTime (com.conveyal.gtfs.model.StopTime)4 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)4 ArrayList (java.util.ArrayList)3 Collectors (java.util.stream.Collectors)3 IntArrayList (com.carrotsearch.hppc.IntArrayList)2 Transfer (com.conveyal.gtfs.model.Transfer)2 Trip (com.conveyal.gtfs.model.Trip)2 GtfsRealtime (com.google.transit.realtime.GtfsRealtime)2 EdgeFilter (com.graphhopper.routing.util.EdgeFilter)2 Weighting (com.graphhopper.routing.weighting.Weighting)2 Graph (com.graphhopper.storage.Graph)2 NodeAccess (com.graphhopper.storage.NodeAccess)2 Snap (com.graphhopper.storage.index.Snap)2 PointNotFoundException (com.graphhopper.util.exceptions.PointNotFoundException)2 Instant (java.time.Instant)2 java.util (java.util)2 Map (java.util.Map)2 Stream (java.util.stream.Stream)2