@Override public double getEle(int index) { return getElevation(index); }
double getFirstEle() { return points.getElevation(0); }
@Override public double getElevation(int index) { if (index > getSize()) throw new ArrayIndexOutOfBoundsException(ERR_MSG + " index:" + index + ", size:" + getSize()); return wrappedPointList.getElevation(fromOffset + index); }
private void calcAscendDescend(final PathWrapper rsp, final PointList pointList) { double ascendMeters = 0; double descendMeters = 0; double lastEle = pointList.getElevation(0); for (int i = 1; i < pointList.size(); ++i) { double ele = pointList.getElevation(i); double diff = Math.abs(ele - lastEle); if (ele > lastEle) ascendMeters += diff; else descendMeters += diff; lastEle = ele; } rsp.setAscend(ascendMeters); rsp.setDescend(descendMeters); }
@Override public double getElevation(int nodeId) { if (isVirtualNode(nodeId)) return virtualNodes.getElevation(nodeId - mainNodes); return mainNodeAccess.getElevation(nodeId); }
@Override public String toString() { StringBuilder sb = new StringBuilder(); for (int i = 0; i < getSize(); i++) { if (i > 0) sb.append(", "); sb.append('('); sb.append(getLatitude(i)); sb.append(','); sb.append(getLongitude(i)); if (this.is3D()) { sb.append(','); sb.append(getElevation(i)); } sb.append(')'); } return sb.toString(); }
public GHPoint3D toGHPoint(int index) { return new GHPoint3D(getLatitude(index), getLongitude(index), getElevation(index)); }
public static String encodePolyline(PointList poly, boolean includeElevation, double precision) { StringBuilder sb = new StringBuilder(); int size = poly.getSize(); int prevLat = 0; int prevLon = 0; int prevEle = 0; for (int i = 0; i < size; i++) { int num = (int) Math.floor(poly.getLatitude(i) * precision); encodeNumber(sb, num - prevLat); prevLat = num; num = (int) Math.floor(poly.getLongitude(i) * precision); encodeNumber(sb, num - prevLon); prevLon = num; if (includeElevation) { num = (int) Math.floor(poly.getElevation(i) * 100); encodeNumber(sb, num - prevEle); prevEle = num; } } return sb.toString(); }
public void add(PointList points) { ensureMutability(); int newSize = size + points.getSize(); incCap(newSize); for (int i = 0; i < points.getSize(); i++) { int tmp = size + i; latitudes[tmp] = points.getLatitude(i); longitudes[tmp] = points.getLongitude(i); if (is3D) elevations[tmp] = points.getElevation(i); } size = newSize; }
boolean is3D = points.is3D(); if (is3D) ele = points.getElevation(0); double nextLat = last ? nextInstr.getFirstLat() : points.getLatitude(i + 1); double nextLon = last ? nextInstr.getFirstLon() : points.getLongitude(i + 1); double nextEle = is3D ? (last ? nextInstr.getFirstEle() : points.getElevation(i + 1)) : Double.NaN; if (is3D) prevTime = Math.round(prevTime + this.time * Helper.DIST_3D.calcDist(nextLat, nextLon, nextEle, lat, lon, ele) / distance);
/** * 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); }
/** * compress list: move points into EMPTY slots */ void compressNew(PointList points, int removed) { int freeIndex = -1; for (int currentIndex = 0; currentIndex < points.getSize(); currentIndex++) { if (Double.isNaN(points.getLatitude(currentIndex))) { if (freeIndex < 0) freeIndex = currentIndex; continue; } else if (freeIndex < 0) { continue; } points.set(freeIndex, points.getLatitude(currentIndex), points.getLongitude(currentIndex), points.getElevation(currentIndex)); points.set(currentIndex, Double.NaN, Double.NaN, Double.NaN); // find next free index int max = currentIndex; int searchIndex = freeIndex + 1; freeIndex = currentIndex; for (; searchIndex < max; searchIndex++) { if (Double.isNaN(points.getLatitude(searchIndex))) { freeIndex = searchIndex; break; } } } points.trimToSize(points.getSize() - removed); }
@Override public boolean equals(Object obj) { if (obj == null) return false; PointList other = (PointList) obj; if (this.isEmpty() && other.isEmpty()) return true; if (this.getSize() != other.getSize() || this.is3D() != other.is3D()) return false; for (int i = 0; i < size(); i++) { if (!equalsEps(getLatitude(i), other.getLatitude(i))) return false; if (!equalsEps(getLongitude(i), other.getLongitude(i))) return false; if (this.is3D() && !equalsEps(getElevation(i), other.getElevation(i))) return false; } return true; }
double prevLat = pointList.getLatitude(0); double prevLon = pointList.getLongitude(0); double prevEle = pointList.is3D() ? pointList.getElevation(0) : Double.NaN; double lat, lon, ele = Double.NaN; PointList pillarNodes = new PointList(pointList.getSize() - 2, nodeAccess.is3D()); lon = pointList.getLongitude(i); if (pointList.is3D()) { ele = pointList.getElevation(i); if (!distCalc.isCrossBoundary(lon, prevLon)) towerNodeDistance += distCalc3D.calcDist(prevLat, prevLon, prevEle, lat, lon, ele);
double decEleSum = 0, decDist2DSum = 0; double prevEle = pl.getElevation(0); double fullDist2D = edge.getDistance(); return; double eleDelta = pl.getElevation(pl.size() - 1) - prevEle; if (eleDelta > 0.1) { incEleSum = eleDelta;
/** * Clones this PointList. If this PointList was immutable, the cloned will be mutable. If this PointList was a * ShallowImmutablePointList, the cloned PointList will be a regular PointList. */ public PointList clone(boolean reverse) { PointList clonePL = new PointList(getSize(), is3D()); if (is3D()) for (int i = 0; i < getSize(); i++) { clonePL.add(getLatitude(i), getLongitude(i), getElevation(i)); } else for (int i = 0; i < getSize(); i++) { clonePL.add(getLatitude(i), getLongitude(i)); } if (reverse) clonePL.reverse(); return clonePL; }
private byte[] createWayGeometryBytes(PointList pillarNodes, boolean reverse) { int len = pillarNodes.getSize(); int dim = nodeAccess.getDimension(); int totalLen = len * dim * 4 + 4; byte[] bytes = new byte[totalLen]; bitUtil.fromInt(bytes, len, 0); if (reverse) pillarNodes.reverse(); int tmpOffset = 4; boolean is3D = nodeAccess.is3D(); for (int i = 0; i < len; i++) { double lat = pillarNodes.getLatitude(i); bitUtil.fromInt(bytes, Helper.degreeToInt(lat), tmpOffset); tmpOffset += 4; bitUtil.fromInt(bytes, Helper.degreeToInt(pillarNodes.getLongitude(i)), tmpOffset); tmpOffset += 4; if (is3D) { bitUtil.fromInt(bytes, Helper.eleToInt(pillarNodes.getElevation(i)), tmpOffset); tmpOffset += 4; } } return bytes; }
public LineString toLineString(boolean includeElevation) { GeometryFactory gf = new GeometryFactory(); Coordinate[] coordinates = new Coordinate[getSize() == 1 ? 2 : getSize()]; for (int i = 0; i < getSize(); i++) { coordinates[i] = includeElevation ? new Coordinate( round6(getLongitude(i)), round6(getLatitude(i)), round2(getElevation(i))) : new Coordinate( round6(getLongitude(i)), round6(getLatitude(i))); } // special case as just 1 point is not supported in the specification #1412 if (getSize() == 1) coordinates[1] = coordinates[0]; return gf.createLineString(coordinates); }
@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); }
private List<NavigationPosition> asPositions(PointList points) { List<NavigationPosition> result = new ArrayList<>(); for (int i = 0, c = points.getSize(); i < c; i++) { result.add(new SimpleNavigationPosition(points.getLongitude(i), points.getLatitude(i), points.getElevation(i), null)); } return result; }