Search in sources :

Example 1 with TransferEdge

use of org.opentripplanner.routing.edgetype.TransferEdge in project OpenTripPlanner by opentripplanner.

the class GTFSPatternHopFactory method createTransfersTxtTransfers.

/**
 * Create transfer edges between stops which are listed in transfers.txt.
 *
 * NOTE: this method is only called when transfersTxtDefinesStationPaths is set to
 * True for a given GFTS feed.
 */
public void createTransfersTxtTransfers() {
    /* Create transfer edges based on transfers.txt. */
    for (Transfer transfer : _dao.getAllTransfers()) {
        int type = transfer.getTransferType();
        if (// type 3 = transfer not possible
        type == 3)
            continue;
        if (transfer.getFromStop().equals(transfer.getToStop())) {
            continue;
        }
        TransitStationStop fromv = context.stationStopNodes.get(transfer.getFromStop());
        TransitStationStop tov = context.stationStopNodes.get(transfer.getToStop());
        double distance = SphericalDistanceLibrary.distance(fromv.getCoordinate(), tov.getCoordinate());
        int time;
        if (transfer.getTransferType() == 2) {
            time = transfer.getMinTransferTime();
        } else {
            // fixme: handle timed transfers
            time = (int) distance;
        }
        TransferEdge transferEdge = new TransferEdge(fromv, tov, distance, time);
        CoordinateSequence sequence = new PackedCoordinateSequence.Double(new Coordinate[] { fromv.getCoordinate(), tov.getCoordinate() }, 2);
        LineString geometry = _geometryFactory.createLineString(sequence);
        transferEdge.setGeometry(geometry);
    }
}
Also used : CoordinateSequence(com.vividsolutions.jts.geom.CoordinateSequence) PackedCoordinateSequence(org.opentripplanner.common.geometry.PackedCoordinateSequence) LineString(com.vividsolutions.jts.geom.LineString) StopTransfer(org.opentripplanner.routing.core.StopTransfer) Transfer(org.onebusaway.gtfs.model.Transfer) TransferEdge(org.opentripplanner.routing.edgetype.TransferEdge) TimedTransferEdge(org.opentripplanner.routing.edgetype.TimedTransferEdge) TransitStationStop(org.opentripplanner.routing.vertextype.TransitStationStop) ShapePoint(org.onebusaway.gtfs.model.ShapePoint)

Example 2 with TransferEdge

use of org.opentripplanner.routing.edgetype.TransferEdge in project OpenTripPlanner by opentripplanner.

the class TransferGraphLinker method run.

public void run() {
    // Create a mapping from StopId to StopVertices
    Map<AgencyAndId, TransitStationStop> stopNodes = new HashMap<AgencyAndId, TransitStationStop>();
    for (Vertex v : graph.getVertices()) {
        if (v instanceof TransitStationStop) {
            TransitStationStop transitStationStop = (TransitStationStop) v;
            Stop stop = transitStationStop.getStop();
            stopNodes.put(stop.getId(), transitStationStop);
        }
    }
    // Create edges
    for (TransferTable.Transfer transfer : graph.getTransferTable().getAllFirstSpecificTransfers()) {
        TransitStationStop fromVertex = stopNodes.get(transfer.fromStopId);
        TransitStationStop toVertex = stopNodes.get(transfer.toStopId);
        double distance = SphericalDistanceLibrary.distance(fromVertex.getCoordinate(), toVertex.getCoordinate());
        TransferEdge edge = null;
        switch(transfer.seconds) {
            case StopTransfer.FORBIDDEN_TRANSFER:
            case StopTransfer.UNKNOWN_TRANSFER:
                break;
            case StopTransfer.PREFERRED_TRANSFER:
            case StopTransfer.TIMED_TRANSFER:
                edge = new TransferEdge(fromVertex, toVertex, distance);
                break;
            default:
                edge = new TransferEdge(fromVertex, toVertex, distance, transfer.seconds);
        }
        if (edge != null) {
            LineString geometry = GeometryUtils.getGeometryFactory().createLineString(new Coordinate[] { fromVertex.getCoordinate(), toVertex.getCoordinate() });
            edge.setGeometry(geometry);
        }
    }
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) TransferTable(org.opentripplanner.routing.core.TransferTable) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) HashMap(java.util.HashMap) TransitStationStop(org.opentripplanner.routing.vertextype.TransitStationStop) Stop(org.onebusaway.gtfs.model.Stop) LineString(com.vividsolutions.jts.geom.LineString) TransferEdge(org.opentripplanner.routing.edgetype.TransferEdge) TransitStationStop(org.opentripplanner.routing.vertextype.TransitStationStop)

Aggregations

LineString (com.vividsolutions.jts.geom.LineString)2 TransferEdge (org.opentripplanner.routing.edgetype.TransferEdge)2 TransitStationStop (org.opentripplanner.routing.vertextype.TransitStationStop)2 CoordinateSequence (com.vividsolutions.jts.geom.CoordinateSequence)1 HashMap (java.util.HashMap)1 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)1 ShapePoint (org.onebusaway.gtfs.model.ShapePoint)1 Stop (org.onebusaway.gtfs.model.Stop)1 Transfer (org.onebusaway.gtfs.model.Transfer)1 PackedCoordinateSequence (org.opentripplanner.common.geometry.PackedCoordinateSequence)1 StopTransfer (org.opentripplanner.routing.core.StopTransfer)1 TransferTable (org.opentripplanner.routing.core.TransferTable)1 TimedTransferEdge (org.opentripplanner.routing.edgetype.TimedTransferEdge)1 Vertex (org.opentripplanner.routing.graph.Vertex)1