Search in sources :

Example 6 with GHPoint3D

use of com.graphhopper.util.shapes.GHPoint3D in project graphhopper by graphhopper.

the class NearestServlet method doGet.

@Override
public void doGet(HttpServletRequest httpReq, HttpServletResponse httpRes) throws ServletException, IOException {
    String pointStr = getParam(httpReq, "point", null);
    boolean enabledElevation = getBooleanParam(httpReq, "elevation", false);
    ObjectNode result = objectMapper.createObjectNode();
    if (pointStr != null && !pointStr.equalsIgnoreCase("")) {
        GHPoint place = GHPoint.parse(pointStr);
        QueryResult qr = index.findClosest(place.lat, place.lon, EdgeFilter.ALL_EDGES);
        if (!qr.isValid()) {
            result.put("error", "Nearest point cannot be found!");
        } else {
            GHPoint3D snappedPoint = qr.getSnappedPoint();
            result.put("type", "Point");
            ArrayNode coord = result.putArray("coordinates");
            coord.add(snappedPoint.lon);
            coord.add(snappedPoint.lat);
            if (hasElevation && enabledElevation)
                coord.add(snappedPoint.ele);
            // Distance from input to snapped point in meters
            result.put("distance", calc.calcDist(place.lat, place.lon, snappedPoint.lat, snappedPoint.lon));
        }
    } else {
        result.put("error", "No lat/lon specified!");
    }
    writeJson(httpReq, httpRes, result);
}
Also used : QueryResult(com.graphhopper.storage.index.QueryResult) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) GHPoint3D(com.graphhopper.util.shapes.GHPoint3D) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) GHPoint(com.graphhopper.util.shapes.GHPoint)

Example 7 with GHPoint3D

use of com.graphhopper.util.shapes.GHPoint3D 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)

Example 8 with GHPoint3D

use of com.graphhopper.util.shapes.GHPoint3D in project graphhopper by graphhopper.

the class Snap method calcSnappedPoint.

/**
 * Calculates the closest 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(FetchMode.ALL);
    double tmpLat = fullPL.getLat(wayIndex);
    double tmpLon = fullPL.getLon(wayIndex);
    double tmpEle = fullPL.getEle(wayIndex);
    if (snappedPosition != Position.EDGE) {
        snappedPoint = new GHPoint3D(tmpLat, tmpLon, tmpEle);
        return;
    }
    double queryLat = getQueryPoint().lat, queryLon = getQueryPoint().lon;
    double adjLat = fullPL.getLat(wayIndex + 1), adjLon = fullPL.getLon(wayIndex + 1);
    if (distCalc.validEdgeDistance(queryLat, queryLon, tmpLat, tmpLon, adjLat, adjLon)) {
        GHPoint tmpPoint = distCalc.calcCrossingPointToEdge(queryLat, queryLon, tmpLat, tmpLon, adjLat, adjLon);
        double adjEle = fullPL.getEle(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 : GHPoint3D(com.graphhopper.util.shapes.GHPoint3D) GHPoint(com.graphhopper.util.shapes.GHPoint)

Example 9 with GHPoint3D

use of com.graphhopper.util.shapes.GHPoint3D in project graphhopper by graphhopper.

the class PointList method iterator.

@Override
public Iterator<GHPoint3D> iterator() {
    return new Iterator<GHPoint3D>() {

        int counter = 0;

        @Override
        public boolean hasNext() {
            return counter < size();
        }

        @Override
        public GHPoint3D next() {
            if (counter >= size())
                throw new NoSuchElementException();
            GHPoint3D point = PointList.this.get(counter);
            counter++;
            return point;
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException("Not supported.");
        }
    };
}
Also used : GHPoint3D(com.graphhopper.util.shapes.GHPoint3D) Iterator(java.util.Iterator) NoSuchElementException(java.util.NoSuchElementException)

Example 10 with GHPoint3D

use of com.graphhopper.util.shapes.GHPoint3D in project graphhopper by graphhopper.

the class ExtendedJsonResponseTest method getGpxExtension.

private List<State> getGpxExtension() {
    List<State> list = new ArrayList<>();
    Snap snap1 = new Snap(-3.4445, -38.9990) {

        @Override
        public GHPoint3D getSnappedPoint() {
            return new GHPoint3D(-3.4446, -38.9996, 0);
        }
    };
    Snap snap2 = new Snap(-3.4445, -38.9990) {

        @Override
        public GHPoint3D getSnappedPoint() {
            return new GHPoint3D(-3.4449, -38.9999, 0);
        }
    };
    list.add(new State(new Observation(new GHPoint(-3.4446, -38.9996)), snap1));
    list.add(new State(new Observation(new GHPoint(-3.4448, -38.9999)), snap2));
    return list;
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) State(com.graphhopper.matching.State) VirtualEdgeIteratorState(com.graphhopper.routing.querygraph.VirtualEdgeIteratorState) GHPoint3D(com.graphhopper.util.shapes.GHPoint3D) ArrayList(java.util.ArrayList) Observation(com.graphhopper.matching.Observation) Snap(com.graphhopper.storage.index.Snap) GHPoint(com.graphhopper.util.shapes.GHPoint)

Aggregations

GHPoint3D (com.graphhopper.util.shapes.GHPoint3D)14 GHPoint (com.graphhopper.util.shapes.GHPoint)8 Snap (com.graphhopper.storage.index.Snap)3 ArrayList (java.util.ArrayList)3 GHIntObjectHashMap (com.graphhopper.coll.GHIntObjectHashMap)2 CHProfile (com.graphhopper.config.CHProfile)2 LMProfile (com.graphhopper.config.LMProfile)2 Profile (com.graphhopper.config.Profile)2 SRTMProvider (com.graphhopper.reader.dem.SRTMProvider)2 CustomProfile (com.graphhopper.routing.weighting.custom.CustomProfile)2 QueryResult (com.graphhopper.storage.index.QueryResult)2 PointList (com.graphhopper.util.PointList)2 Test (org.junit.jupiter.api.Test)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 IntArrayList (com.carrotsearch.hppc.IntArrayList)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 GHResponse (com.graphhopper.GHResponse)1 Observation (com.graphhopper.matching.Observation)1 State (com.graphhopper.matching.State)1