Package org.opentripplanner.common.geometry

Examples of org.opentripplanner.common.geometry.DistanceLibrary


     *
     * Orders the endpoints u, v so that they are consistent with the direction of the edge e.
     */
    private PartialStreetEdge makePartialEdgeAlong(StreetEdge e, StreetVertex u,
            StreetVertex v) {
        DistanceLibrary dLib = SphericalDistanceLibrary.getInstance();

        Vertex head = e.getFromVertex();
        double uDist = dLib.fastDistance(head.getCoordinate(), u.getCoordinate());
        double vDist = dLib.fastDistance(head.getCoordinate(), v.getCoordinate());

        // Order the vertices along the partial edge by distance from the head of the edge.
        // TODO(flamholz): this logic is insufficient for curvy streets/roundabouts.
        StreetVertex first = u;
        StreetVertex second = v;
View Full Code Here


    private static final Logger LOG = LoggerFactory.getLogger(OnBoardDepartServiceImpl.class);

    @Override
    public Vertex setupDepartOnBoard(RoutingContext ctx) {
        DistanceLibrary distanceLibrary = SphericalDistanceLibrary.getInstance();
        RoutingRequest opt = ctx.opt;
        opt.rctx = ctx;

        /* 1. Get the list of PatternHop for the given trip ID. */
        AgencyAndId tripId = opt.startingTransitTripId;
        Trip trip = ctx.graph.index.tripForId.get(tripId);
        TripPattern tripPattern = ctx.graph.index.patternForTrip.get(trip);
        if (tripPattern == null) {
            // TODO Shouldn't we bailout on a normal trip plan here, returning null ?
            throw new IllegalArgumentException("Unknown/invalid trip ID: " + tripId);
        }
        List<PatternHop> hops = tripPattern.getPatternHops();

        Double lon = opt.from.lng; // Origin point, optional
        Double lat = opt.from.lat;
        PatternStopVertex nextStop;
        TripTimes bestTripTimes = null;
        ServiceDay bestServiceDay = null;
        int bestStopIndex = 0;
        double fractionCovered;
        LineString geomRemaining;

        Coordinate point = lon == null || lat == null ? null : new Coordinate(lon, lat);
        if (point != null) {
            /*
             * 2. Get the best hop from the list, given the parameters. Currently look for nearest hop,
             * taking into account shape if available. If no shape are present, the computed hop and
             * fraction may be a bit away from what it should be.
             */
            PatternHop bestHop = null;
            double minDist = Double.MAX_VALUE;
            for (PatternHop hop : hops) {
                LineString line = hop.getGeometry();
                double dist = distanceLibrary.fastDistance(point, line);
                if (dist < minDist) {
                    minDist = dist;
                    bestHop = hop;
                }
            }
            if (minDist > 1000) LOG.warn(
                    "On-board depart: origin point suspiciously away from nearest trip shape ({} meters)",
                    minDist);
            else LOG.info("On-board depart: origin point {} meters away from hop shape", minDist);

            /*
             * 3. Compute the fraction covered percentage of the current hop. This assume a constant
             * trip speed alongside the whole hop: this should be quite precise for small hops
             * (buses), a bit less for longer ones (long distance train). Shape linear distance is
             * of no help here, as the unit is arbitrary (and probably usually a distance).
             */
            LineString geometry = bestHop.getGeometry();
            P2<LineString> geomPair = GeometryUtils.splitGeometryAtPoint(geometry, point);
            geomRemaining = geomPair.second;
            double total = distanceLibrary.fastLength(geometry);
            double remaining = distanceLibrary.fastLength(geomRemaining);
            fractionCovered = total > 0.0 ? (double) (1.0 - remaining / total) : 0.0;

            nextStop = (PatternStopVertex) bestHop.getToVertex();
            bestStopIndex = bestHop.getStopIndex();

View Full Code Here

        exit = false;
        initGeometry();
    }

    private void initGeometry() {
        DistanceLibrary distanceLibrary = SphericalDistanceLibrary.getInstance();
        Coordinate fromc = fromv.getCoordinate();
        Coordinate toc = tov.getCoordinate();
        geometry = GeometryUtils.getGeometryFactory().createLineString(
                new Coordinate[] { fromc, toc });
        linkDistance = distanceLibrary.distance(fromc, toc);
    }
View Full Code Here

     */
    public static void sampleSPT(ShortestPathTree spt, ZSampleGrid<WTWD> sampleGrid, final double d0,
            final double gridSizeMeters, final double v0, final double maxWalkDistance,
            final double cosLat) {

        final DistanceLibrary distanceLibrary = SphericalDistanceLibrary.getInstance();

        // Below is a closure that makes use of the parameters to the enclosing function.

        /**
         * Any given sample is weighted according to the inverse of the squared normalized distance
         * + 1 to the grid sample. We add to the sampling time a default off-road walk distance to
         * account for off-road sampling.
         */
        AccumulativeMetric<WTWD> accMetric = new AccumulativeMetric<WTWD>() {
            @Override
            public WTWD cumulateSample(Coordinate C0, Coordinate Cs, WTWD z, WTWD zS) {
                double t = z.wTime / z.w;
                double b = z.wBoardings / z.w;
                double wd = z.wWalkDist / z.w;
                double d = distanceLibrary.fastDistance(C0, Cs, cosLat);
                // additionnal time
                double dt = d / v0;
                // t weight
                double w = 1 / ((d + d0) * (d + d0));
                if (zS == null) {
View Full Code Here

    public void testFastDistance() {

      // Seed the random generator, if we have a failure
      // we'd like to be able to reproduce it...
      Random r = new Random(42);
      DistanceLibrary distanceLibrary = SphericalDistanceLibrary.getInstance();
     
      for (int i = 0; i < N_TEST; i++) {
        double lat1 = r.nextDouble() * 2.0 * MAX_LAT - MAX_LAT;
        double lon1 = r.nextDouble() * 360.0;
        double lat2 = lat1 + r.nextDouble() * 2.0 * MAX_DELTA_LAT - MAX_DELTA_LAT;
        double lon2 = lon1 + r.nextDouble() * 2.0 * MAX_DELTA_LON - MAX_DELTA_LON;
        double de = distanceLibrary.distance(lat1, lon1, lat2, lon2);
        double da = distanceLibrary.fastDistance(lat1, lon1, lat2, lon2);
        assertTrue(da <= de);
        assertTrue(da >= de / 1.00054);
      }
    }
View Full Code Here

        if (graph.streetIndex == null) {
            graph.streetIndex = new StreetVertexIndexServiceImpl(graph);
            LOG.debug("street index built.");
        }
        StreetVertexIndexService streetIndexService = graph.streetIndex;
        DistanceLibrary distanceLibrary;
        if (streetIndexService instanceof StreetVertexIndexServiceImpl) {
            distanceLibrary = ((StreetVertexIndexServiceImpl) streetIndexService).distanceLibrary;
        } else {
            distanceLibrary = SphericalDistanceLibrary.getInstance();
        }
View Full Code Here

TOP

Related Classes of org.opentripplanner.common.geometry.DistanceLibrary

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.