Search in sources :

Example 16 with PointList

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

the class MainActivity method createPathLayer.

private PathLayer createPathLayer(PathWrapper response) {
    Style style = Style.builder().fixed(true).generalization(Style.GENERALIZATION_SMALL).strokeColor(0x9900cc33).strokeWidth(4 * getResources().getDisplayMetrics().density).build();
    PathLayer pathLayer = new PathLayer(mapView.map(), style);
    List<GeoPoint> geoPoints = new ArrayList<>();
    PointList pointList = response.getPoints();
    for (int i = 0; i < pointList.getSize(); i++) geoPoints.add(new GeoPoint(pointList.getLatitude(i), pointList.getLongitude(i)));
    pathLayer.setPoints(geoPoints);
    return pathLayer;
}
Also used : PathLayer(org.oscim.layers.vector.PathLayer) GeoPoint(org.oscim.core.GeoPoint) PointList(com.graphhopper.util.PointList) ArrayList(java.util.ArrayList) Style(org.oscim.layers.vector.geometries.Style) GeoPoint(org.oscim.core.GeoPoint)

Example 17 with PointList

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

the class AlternativeRoutingTemplate method isReady.

@Override
public boolean isReady(PathMerger pathMerger, Translation tr) {
    if (pathList.isEmpty())
        throw new RuntimeException("Empty paths for alternative route calculation not expected");
    // if alternative route calculation was done then create the responses from single paths
    PointList wpList = getWaypoints();
    altResponse.setWaypoints(wpList);
    ghResponse.add(altResponse);
    pathMerger.doWork(altResponse, Collections.singletonList(pathList.get(0)), tr);
    for (int index = 1; index < pathList.size(); index++) {
        PathWrapper tmpAltRsp = new PathWrapper();
        tmpAltRsp.setWaypoints(wpList);
        ghResponse.add(tmpAltRsp);
        pathMerger.doWork(tmpAltRsp, Collections.singletonList(pathList.get(index)), tr);
    }
    return true;
}
Also used : PointList(com.graphhopper.util.PointList) PathWrapper(com.graphhopper.PathWrapper) GHPoint(com.graphhopper.util.shapes.GHPoint)

Example 18 with PointList

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

the class GraphEdgeIdFinder method fillEdgeIDs.

/**
 * This method fills the edgeIds hash with edgeIds found inside the specified geometry
 */
public void fillEdgeIDs(GHIntHashSet edgeIds, Geometry geometry, EdgeFilter filter) {
    if (geometry instanceof Point) {
        GHPoint point = GHPoint.create((Point) geometry);
        findClosestEdgeToPoint(edgeIds, point, filter);
    } else if (geometry instanceof LineString) {
        PointList pl = PointList.from((LineString) geometry);
        // TODO do map matching or routing
        int lastIdx = pl.size() - 1;
        if (pl.size() >= 2) {
            double meanLat = (pl.getLatitude(0) + pl.getLatitude(lastIdx)) / 2;
            double meanLon = (pl.getLongitude(0) + pl.getLongitude(lastIdx)) / 2;
            findClosestEdge(edgeIds, meanLat, meanLon, filter);
        }
    } else if (geometry instanceof MultiPoint) {
        for (Coordinate coordinate : geometry.getCoordinates()) {
            findClosestEdge(edgeIds, coordinate.y, coordinate.x, filter);
        }
    }
}
Also used : PointList(com.graphhopper.util.PointList) GHPoint(com.graphhopper.util.shapes.GHPoint) GHPoint(com.graphhopper.util.shapes.GHPoint)

Example 19 with PointList

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

the class QueryResult method calcSnappedPoint.

/**
 * Calculates the closet point on the edge from the query point.
 */
public void calcSnappedPoint(DistanceCalc distCalc) {
    if (closestEdge == null)
        throw new IllegalStateException("No closest edge?");
    if (snappedPoint != null)
        throw new IllegalStateException("Calculate snapped point only once");
    PointList fullPL = getClosestEdge().fetchWayGeometry(3);
    double tmpLat = fullPL.getLatitude(wayIndex);
    double tmpLon = fullPL.getLongitude(wayIndex);
    double tmpEle = fullPL.getElevation(wayIndex);
    if (snappedPosition != Position.EDGE) {
        snappedPoint = new GHPoint3D(tmpLat, tmpLon, tmpEle);
        return;
    }
    double queryLat = getQueryPoint().lat, queryLon = getQueryPoint().lon;
    double adjLat = fullPL.getLatitude(wayIndex + 1), adjLon = fullPL.getLongitude(wayIndex + 1);
    if (distCalc.validEdgeDistance(queryLat, queryLon, tmpLat, tmpLon, adjLat, adjLon)) {
        GHPoint tmpPoint = distCalc.calcCrossingPointToEdge(queryLat, queryLon, tmpLat, tmpLon, adjLat, adjLon);
        double adjEle = fullPL.getElevation(wayIndex + 1);
        snappedPoint = new GHPoint3D(tmpPoint.lat, tmpPoint.lon, (tmpEle + adjEle) / 2);
    } else
        // outside of edge boundaries
        snappedPoint = new GHPoint3D(tmpLat, tmpLon, tmpEle);
}
Also used : PointList(com.graphhopper.util.PointList) GHPoint3D(com.graphhopper.util.shapes.GHPoint3D) GHPoint(com.graphhopper.util.shapes.GHPoint)

Example 20 with PointList

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

the class GraphElevationSmoothingTest method interpolatesElevationOfPillarNodes.

@Test
public void interpolatesElevationOfPillarNodes() {
    PointList pl1 = new PointList(3, true);
    pl1.add(0, 0, 0);
    pl1.add(0.0005, 0.0005, 100);
    pl1.add(0.001, 0.001, 50);
    GraphElevationSmoothing.smoothElevation(pl1);
    assertEquals(3, pl1.size());
    assertEquals(50, pl1.getElevation(1), .1);
    PointList pl2 = new PointList(3, true);
    pl2.add(0.001, 0.001, 50);
    pl2.add(0.0015, 0.0015, 160);
    pl2.add(0.0016, 0.0015, 150);
    pl2.add(0.0017, 0.0015, 220);
    pl2.add(0.002, 0.002, 20);
    GraphElevationSmoothing.smoothElevation(pl2);
    assertEquals(5, pl2.size());
    assertEquals(120, pl2.getElevation(1), .1);
    // This is not 120 anymore, as the point at index 1 was smoothed from 160=>120
    assertEquals(112, pl2.getElevation(2), .1);
    assertEquals(50, pl2.getEle(0), .1);
}
Also used : PointList(com.graphhopper.util.PointList) Test(org.junit.Test)

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