Search in sources :

Example 21 with PointList

use of com.graphhopper.util.PointList in project graphhopper by graphhopper.

the class WebHelper method decodePolyline.

public static PointList decodePolyline(String encoded, int initCap, boolean is3D) {
    PointList poly = new PointList(initCap, is3D);
    int index = 0;
    int len = encoded.length();
    int lat = 0, lng = 0, ele = 0;
    while (index < len) {
        // latitude
        int b, shift = 0, result = 0;
        do {
            b = encoded.charAt(index++) - 63;
            result |= (b & 0x1f) << shift;
            shift += 5;
        } while (b >= 0x20);
        int deltaLatitude = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
        lat += deltaLatitude;
        // longitute
        shift = 0;
        result = 0;
        do {
            b = encoded.charAt(index++) - 63;
            result |= (b & 0x1f) << shift;
            shift += 5;
        } while (b >= 0x20);
        int deltaLongitude = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
        lng += deltaLongitude;
        if (is3D) {
            // elevation
            shift = 0;
            result = 0;
            do {
                b = encoded.charAt(index++) - 63;
                result |= (b & 0x1f) << shift;
                shift += 5;
            } while (b >= 0x20);
            int deltaElevation = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
            ele += deltaElevation;
            poly.add((double) lat / 1e5, (double) lng / 1e5, (double) ele / 100);
        } else
            poly.add((double) lat / 1e5, (double) lng / 1e5);
    }
    return poly;
}
Also used : PointList(com.graphhopper.util.PointList)

Example 22 with PointList

use of com.graphhopper.util.PointList in project massim by agentcontest.

the class CityMap method getNewCarRoute.

private Route getNewCarRoute(Location from, Location to) {
    GHResponse rsp = queryGH(from, to);
    if (rsp.hasErrors())
        return null;
    Route route = new Route();
    // points, distance in meters and time in millis of the full path
    PointList pointList = rsp.getBest().getPoints();
    Iterator<GHPoint3D> pIterator = pointList.iterator();
    if (!pIterator.hasNext())
        return null;
    GHPoint prevPoint = pIterator.next();
    double remainder = 0;
    Location loc = null;
    while (pIterator.hasNext()) {
        GHPoint nextPoint = pIterator.next();
        double length = getLength(prevPoint, nextPoint);
        if (length == 0) {
            prevPoint = nextPoint;
            continue;
        }
        long i = 0;
        for (; i * cellSize + remainder < length; i++) {
            loc = getIntermediateLoc(prevPoint, nextPoint, length, i * cellSize + remainder);
            if (!from.equals(loc)) {
                route.addPoint(loc);
            }
        }
        remainder = i * cellSize + remainder - length;
        prevPoint = nextPoint;
    }
    if (!to.equals(loc)) {
        route.addPoint(to);
    }
    return route;
}
Also used : PointList(com.graphhopper.util.PointList) GHPoint3D(com.graphhopper.util.shapes.GHPoint3D) GHResponse(com.graphhopper.GHResponse) GHPoint(com.graphhopper.util.shapes.GHPoint) Route(massim.scenario.city.data.Route) Location(massim.scenario.city.data.Location)

Aggregations

PointList (com.graphhopper.util.PointList)22 Test (org.junit.Test)7 GHPoint (com.graphhopper.util.shapes.GHPoint)6 NodeAccess (com.graphhopper.storage.NodeAccess)5 ArrayList (java.util.ArrayList)3 PathWrapper (com.graphhopper.PathWrapper)2 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)2 BBox (com.graphhopper.util.shapes.BBox)2 GHPoint3D (com.graphhopper.util.shapes.GHPoint3D)2 IntHashSet (com.carrotsearch.hppc.IntHashSet)1 IntIntHashMap (com.carrotsearch.hppc.IntIntHashMap)1 IntLongHashMap (com.carrotsearch.hppc.IntLongHashMap)1 GTFSFeed (com.conveyal.gtfs.GTFSFeed)1 Agency (com.conveyal.gtfs.model.Agency)1 Fare (com.conveyal.gtfs.model.Fare)1 StopTime (com.conveyal.gtfs.model.StopTime)1 Trip (com.conveyal.gtfs.model.Trip)1 GtfsRealtime (com.google.transit.realtime.GtfsRealtime)1 NO_DATA (com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.NO_DATA)1 SKIPPED (com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SKIPPED)1