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);
}
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;
}
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);
}
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.");
}
};
}
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;
}
Aggregations