Search in sources :

Example 1 with IntersectionTransitLink

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

the class SampleStopLinker method link.

/**
 * Link all transit stops. If makeTransfers is true, create direct transfer
 * edges between stops linked to the same pair of vertices. This is important
 * e.g. for transit centers where there are many stops on the same street segment;
 * we don't want to force the user to walk to the end of the street and back.
 *
 * If you're not generating transfers via the street network there is no need to make
 * transfers at this stage. But if you're not generating transfers via the street network,
 * why are you using this module at all?
 */
public void link(boolean makeTransfers) {
    if (makeTransfers)
        links = HashMultimap.create();
    SampleFactory sf = graph.getSampleFactory();
    for (TransitStop tstop : Iterables.filter(graph.getVertices(), TransitStop.class)) {
        Sample s = sf.getSample(tstop.getLon(), tstop.getLat());
        // TODO: stop unlinked annotation
        if (s == null)
            continue;
        new IntersectionTransitLink(tstop, (OsmVertex) s.v0, s.d0);
        new IntersectionTransitLink((OsmVertex) s.v0, tstop, s.d0);
        new IntersectionTransitLink(tstop, (OsmVertex) s.v1, s.d1);
        new IntersectionTransitLink((OsmVertex) s.v1, tstop, s.d1);
        if (makeTransfers) {
            // save the sample so we can make direct transfers between stops
            VertexPair vp = new VertexPair(s.v0, s.v1);
            links.put(vp, tstop);
        }
    }
    if (makeTransfers) {
        // make direct transfers between stops
        for (Collection<TransitStop> tss : links.asMap().values()) {
            for (TransitStop ts0 : tss) {
                for (TransitStop ts1 : tss) {
                    // make a geometry
                    GeometryFactory gf = GeometryUtils.getGeometryFactory();
                    LineString geom = gf.createLineString(new Coordinate[] { ts0.getCoordinate(), ts1.getCoordinate() });
                    double dist = SphericalDistanceLibrary.distance(ts0.getLat(), ts0.getLon(), ts1.getLat(), ts1.getLon());
                    // building unidirectional edge, we'll hit this again in the opposite direction
                    new SimpleTransfer(ts1, ts1, dist, geom);
                }
            }
        }
    }
}
Also used : GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) IntersectionTransitLink(org.opentripplanner.routing.edgetype.IntersectionTransitLink) SampleFactory(org.opentripplanner.analyst.request.SampleFactory) LineString(com.vividsolutions.jts.geom.LineString) Sample(org.opentripplanner.analyst.core.Sample) SimpleTransfer(org.opentripplanner.routing.edgetype.SimpleTransfer)

Aggregations

GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)1 LineString (com.vividsolutions.jts.geom.LineString)1 Sample (org.opentripplanner.analyst.core.Sample)1 SampleFactory (org.opentripplanner.analyst.request.SampleFactory)1 IntersectionTransitLink (org.opentripplanner.routing.edgetype.IntersectionTransitLink)1 SimpleTransfer (org.opentripplanner.routing.edgetype.SimpleTransfer)1 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)1