/** * 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; }
@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; }
private static List<Coordinate> toCoordinateArray(PointList pointList) { List<Coordinate> coordinates = new ArrayList<>(pointList.size()); for (int i = 0; i < pointList.size(); i++) { coordinates.add(pointList.getDimension() == 3 ? new Coordinate(pointList.getLon(i), pointList.getLat(i)) : new Coordinate(pointList.getLon(i), pointList.getLat(i), pointList.getEle(i))); } return coordinates; }
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; }
if (pointList.getDimension() != nodeAccess.getDimension()) throw new AssertionError("Dimension does not match for pointList vs. nodeAccess " + pointList.getDimension() + " <-> " + nodeAccess.getDimension()); 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()); int nodes = pointList.getSize(); for (int i = 1; i < nodes; i++) { lat = pointList.getLatitude(i); 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); prevLon = lon; if (nodes > 2 && i < nodes - 1) { if (pillarNodes.is3D()) pillarNodes.add(lat, lon, ele); else pillarNodes.add(lat, lon);
if (fullPoints.isEmpty()) fullPoints = new PointList(tmpPoints.size(), tmpPoints.is3D()); tmpPoints.removeLastPoint(); fullPoints.add(tmpPoints); altRsp.addPathDetails(path.calcDetails(requestedPathDetails, pathBuilderFactory, origPoints)); origPoints = fullPoints.size(); if (!fullPoints.isEmpty()) { String debug = altRsp.getDebugInfo() + ", simplify (" + origPoints + "->" + fullPoints.getSize() + ")"; altRsp.addDebugInfo(debug); if (fullPoints.is3D)
@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(); }
@Override public int hashCode() { int hash = 5; for (int i = 0; i < getSize(); i++) { hash = 73 * hash + (int) Math.round(getLatitude(i) * 1000000); hash = 73 * hash + (int) Math.round(getLongitude(i) * 1000000); } hash = 73 * hash + this.getSize(); return hash; }
PointList pointList = new PointList(osmNodeIds.size(), nodeAccess.is3D()); List<EdgeIteratorState> newEdges = new ArrayList<>(5); int firstNode = -1; if (!pointList.isEmpty() && lastInBoundsPillarNode > -TOWER_NODE) { if (pointList.getSize() > 1 && firstNode >= 0) { pointList.clear(); pointList.add(nodeAccess, tmpNode); pointList.add(nodeAccess, tmpNode); if (firstNode >= 0) { newEdges.add(addEdge(firstNode, tmpNode, pointList, flags, wayOsmId)); pointList.clear(); pointList.add(nodeAccess, tmpNode);
public static PointList createPointList3D(double... list) { if (list.length % 3 != 0) throw new IllegalArgumentException("list should consist of lat,lon,ele tuples!"); int max = list.length / 3; PointList res = new PointList(max, true); for (int i = 0; i < max; i++) { res.add(list[3 * i], list[3 * i + 1], list[3 * i + 2]); } return res; }
/** * 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); }
private void setWayGeometry_( PointList pillarNodes, long edgePointer, boolean reverse ) if (pillarNodes != null && !pillarNodes.isEmpty()) if (pillarNodes.getDimension() != nodeAccess.getDimension()) throw new IllegalArgumentException("Cannot use pointlist which is " + pillarNodes.getDimension() + "D for graph which is " + nodeAccess.getDimension() + "D"); int len = pillarNodes.getSize(); int dim = nodeAccess.getDimension(); long tmpRef = nextGeoRef(len * dim); bitUtil.fromInt(bytes, len, 0); if (reverse) pillarNodes.reverse(); 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; bitUtil.fromInt(bytes, Helper.eleToInt(pillarNodes.getElevation(i)), tmpOffset); tmpOffset += 4;
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); }
Instruction prevInstr, Instruction nextInstr, boolean firstInstr) { checkOne(); int len = points.size(); long prevTime = time; double lat = points.getLatitude(0); double lon = points.getLongitude(0); double ele = Double.NaN; 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);
@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); }
@Test public void testSimplifyCheckPointCount() { PointList pointList = new PointList(); pointList.parse2DJSON(points1); DouglasPeucker dp = new DouglasPeucker().setMaxDistance(.5); assertEquals(32, pointList.getSize()); dp.simplify(pointList); assertEquals(20, pointList.getSize()); assertFalse(pointList.toString(), pointList.toString().contains("NaN")); pointList.clear(); pointList.parse2DJSON(points1); dp.simplify(pointList, 0, pointList.size() -1); assertEquals(20, pointList.getSize()); pointList.clear(); pointList.parse2DJSON(points1); int removed1 = dp.simplify(pointList.copy(10, 20)); pointList.clear(); pointList.parse2DJSON(points1); int removed2 = dp.simplify(pointList, 10, 19); assertEquals(removed1, removed2); }
public GHPoint3D toGHPoint(int index) { return new GHPoint3D(getLatitude(index), getLongitude(index), getElevation(index)); }
public double calcDistance(DistanceCalc calc) { double prevLat = Double.NaN; double prevLon = Double.NaN; double prevEle = Double.NaN; double dist = 0; for (int i = 0; i < size(); i++) { if (i > 0) { if (is3D()) dist += distCalc3D.calcDist(prevLat, prevLon, prevEle, getLat(i), getLon(i), getEle(i)); else dist += calc.calcDist(prevLat, prevLon, getLat(i), getLon(i)); } prevLat = getLat(i); prevLon = getLon(i); if (is3D()) prevEle = getEle(i); } return dist; }
private void setWayGeometry_(PointList pillarNodes, long edgePointer, boolean reverse) { if (pillarNodes != null && !pillarNodes.isEmpty()) { if (pillarNodes.getDimension() != nodeAccess.getDimension()) throw new IllegalArgumentException("Cannot use pointlist which is " + pillarNodes.getDimension() + "D for graph which is " + nodeAccess.getDimension() + "D"); long existingGeoRef = Helper.toUnsignedLong(edges.getInt(edgePointer + E_GEO)); int len = pillarNodes.getSize(); int dim = nodeAccess.getDimension(); if (existingGeoRef > 0) { final int count = wayGeometry.getInt(existingGeoRef * 4L); if (len <= count) { setWayGeometryAtGeoRef(pillarNodes, edgePointer, reverse, existingGeoRef); return; } } long nextGeoRef = nextGeoRef(len * dim); setWayGeometryAtGeoRef(pillarNodes, edgePointer, reverse, nextGeoRef); } else { edges.setInt(edgePointer + E_GEO, 0); } }
/** * 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.fromLineString((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); } } }