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);
}
}
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);
}
}
}
Aggregations