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;
}
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;
}
Aggregations