Search in sources :

Example 1 with Transfer

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

the class Transfers method getTransfersFromStop.

List<Transfer> getTransfersFromStop(String fromStopId, String fromRouteId) {
    final List<Transfer> allOutboundTransfers = transfersFromStop.getOrDefault(fromStopId, Collections.emptyList());
    final Map<String, List<Transfer>> byToStop = allOutboundTransfers.stream().filter(t -> t.transfer_type == 2).filter(t -> t.from_route_id == null || fromRouteId.equals(t.from_route_id)).collect(Collectors.groupingBy(t -> t.to_stop_id));
    final List<Transfer> result = new ArrayList<>();
    byToStop.forEach((toStop, transfers) -> {
        routesByStop.getOrDefault(toStop, Collections.emptySet()).forEach(toRouteId -> {
            final Transfer mostSpecificRule = findMostSpecificRule(transfers, fromRouteId, toRouteId);
            final Transfer myRule = new Transfer();
            myRule.to_route_id = toRouteId;
            myRule.from_route_id = fromRouteId;
            myRule.to_stop_id = mostSpecificRule.to_stop_id;
            myRule.from_stop_id = mostSpecificRule.from_stop_id;
            myRule.transfer_type = mostSpecificRule.transfer_type;
            myRule.min_transfer_time = mostSpecificRule.min_transfer_time;
            myRule.from_trip_id = mostSpecificRule.from_trip_id;
            myRule.to_trip_id = mostSpecificRule.to_trip_id;
            result.add(myRule);
        });
    });
    return result;
}
Also used : java.util(java.util) Transfer(com.conveyal.gtfs.model.Transfer) GTFSFeed(com.conveyal.gtfs.GTFSFeed) Collectors(java.util.stream.Collectors) Transfer(com.conveyal.gtfs.model.Transfer)

Example 2 with Transfer

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

the class Transfers method getTransfersToStop.

// Starts implementing the proposed GTFS extension for route and trip specific transfer rules.
// So far, only the route is supported.
List<Transfer> getTransfersToStop(String toStopId, String toRouteId) {
    final List<Transfer> allInboundTransfers = transfersToStop.getOrDefault(toStopId, Collections.emptyList());
    final Map<String, List<Transfer>> byFromStop = allInboundTransfers.stream().filter(t -> t.transfer_type == 2).filter(t -> t.to_route_id == null || toRouteId.equals(t.to_route_id)).collect(Collectors.groupingBy(t -> t.from_stop_id));
    final List<Transfer> result = new ArrayList<>();
    byFromStop.forEach((fromStop, transfers) -> {
        routesByStop.getOrDefault(fromStop, Collections.emptySet()).forEach(fromRoute -> {
            final Transfer mostSpecificRule = findMostSpecificRule(transfers, fromRoute, toRouteId);
            final Transfer myRule = new Transfer();
            myRule.to_route_id = toRouteId;
            myRule.from_route_id = fromRoute;
            myRule.to_stop_id = mostSpecificRule.to_stop_id;
            myRule.from_stop_id = mostSpecificRule.from_stop_id;
            myRule.transfer_type = mostSpecificRule.transfer_type;
            myRule.min_transfer_time = mostSpecificRule.min_transfer_time;
            myRule.from_trip_id = mostSpecificRule.from_trip_id;
            myRule.to_trip_id = mostSpecificRule.to_trip_id;
            result.add(myRule);
        });
    });
    return result;
}
Also used : java.util(java.util) Transfer(com.conveyal.gtfs.model.Transfer) GTFSFeed(com.conveyal.gtfs.GTFSFeed) Collectors(java.util.stream.Collectors) Transfer(com.conveyal.gtfs.model.Transfer)

Aggregations

GTFSFeed (com.conveyal.gtfs.GTFSFeed)2 Transfer (com.conveyal.gtfs.model.Transfer)2 java.util (java.util)2 Collectors (java.util.stream.Collectors)2