public static PointList createPointList(double... list) { if (list.length % 2 != 0) throw new IllegalArgumentException("list should consist of lat,lon pairs!"); int max = list.length / 2; PointList res = new PointList(max, false); for (int i = 0; i < max; i++) { res.add(list[2 * i], list[2 * i + 1], Double.NaN); } return res; }
@Override public EdgeIteratorState edge(int a, int b) { int edge = firstEdge++; final VirtualEdgeIteratorState newEdge = new VirtualEdgeIteratorState(-1, edge, a, b, 0.0, 0, "", new PointList()); final VirtualEdgeIteratorState reverseNewEdge = new VirtualEdgeIteratorState(-1, edge, b, a, 0.0, 0, "", new PointList()); newEdge.setReverseEdge(reverseNewEdge); reverseNewEdge.setReverseEdge(newEdge); additionalEdges.push(newEdge); return newEdge; }
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; }
protected PointList getWaypoints() { PointList pointList = new PointList(queryResults.size(), true); for (QueryResult qr : queryResults) { pointList.add(qr.getSnappedPoint()); } return pointList; } }
private PointList pointListFrom(List<QueryResult> queryResults) { PointList waypoints = new PointList(queryResults.size(), true); for (QueryResult qr : queryResults) { waypoints.add(qr.getSnappedPoint()); } return waypoints; }
public static PointList fromLineString(LineString lineString) { final PointList pointList = new PointList(); for (Coordinate coordinate : lineString.getCoordinates()) { pointList.add(new GHPoint(coordinate.y, coordinate.x)); } return pointList; }
public static PointList from(LineString lineString) { final PointList pointList = new PointList(); for (Coordinate coordinate : lineString.getCoordinates()) { pointList.add(new GHPoint(coordinate.y, coordinate.x)); } return pointList; }
private void createEdges(int origTraversalKey, int origRevTraversalKey, GHPoint3D prevSnapped, int prevWayIndex, GHPoint3D currSnapped, int wayIndex, PointList fullPL, EdgeIteratorState closestEdge, int prevNodeId, int nodeId, long reverseFlags) { int max = wayIndex + 1; // basePoints must have at least the size of 2 to make sure fetchWayGeometry(3) returns at least 2 PointList basePoints = new PointList(max - prevWayIndex + 1, mainNodeAccess.is3D()); basePoints.add(prevSnapped.lat, prevSnapped.lon, prevSnapped.ele); for (int i = prevWayIndex; i < max; i++) { basePoints.add(fullPL, i); } basePoints.add(currSnapped.lat, currSnapped.lon, currSnapped.ele); PointList baseReversePoints = basePoints.clone(true); double baseDistance = basePoints.calcDistance(Helper.DIST_PLANE); int virtEdgeId = mainEdges + virtualEdges.size(); // edges between base and snapped point VirtualEdgeIteratorState baseEdge = new VirtualEdgeIteratorState(origTraversalKey, virtEdgeId, prevNodeId, nodeId, baseDistance, closestEdge.getFlags(), closestEdge.getName(), basePoints); VirtualEdgeIteratorState baseReverseEdge = new VirtualEdgeIteratorState(origRevTraversalKey, virtEdgeId, nodeId, prevNodeId, baseDistance, reverseFlags, closestEdge.getName(), baseReversePoints); baseEdge.setReverseEdge(baseReverseEdge); baseReverseEdge.setReverseEdge(baseEdge); virtualEdges.add(baseEdge); virtualEdges.add(baseReverseEdge); }
private void interpolateElevationsOfInnerNodesForNOuterNodes(int[] outerNodeIds, int[] innerNodeIds) { NodeAccess nodeAccess = storage.getNodeAccess(); PointList pointList = new PointList(outerNodeIds.length, true); for (int outerNodeId : outerNodeIds) { pointList.add(nodeAccess.getLat(outerNodeId), nodeAccess.getLon(outerNodeId), nodeAccess.getEle(outerNodeId)); } for (int innerNodeId : innerNodeIds) { double lat = nodeAccess.getLat(innerNodeId); double lon = nodeAccess.getLon(innerNodeId); double ele = elevationInterpolator.calculateElevationBasedOnPointList(lat, lon, pointList); nodeAccess.setNode(innerNodeId, lat, lon, ele); } } }
/** * This method calculated a list of points for this path * <p> * * @return this path its geometry */ public PointList calcPoints() { final PointList points = new PointList(edgeIds.size() + 1, nodeAccess.is3D()); if (edgeIds.isEmpty()) { if (isFound()) { points.add(graph.getNodeAccess(), endNode); } return points; } int tmpNode = getFromNode(); points.add(nodeAccess, tmpNode); forEveryEdge(new EdgeVisitor() { @Override public void next(EdgeIteratorState eb, int index, int prevEdgeId) { PointList pl = eb.fetchWayGeometry(2); for (int j = 0; j < pl.getSize(); j++) { points.add(pl, j); } } @Override public void finish() { } }); return points; }
@Test public void testCreateGPXCorrectFormattingSmallNumbers() { InstructionList instructions = new InstructionList(usTR); PointList pl = new PointList(); pl.add(0.000001, 0.000001); pl.add(-0.000123, -0.000125); Instruction instruction = new Instruction(0, "do it", null, pl); instructions.add(instruction); instructions.add(new FinishInstruction(0.000852, 0.000852, 0)); String gpxStr = instructions.createGPX("test", 0, true, true, true, true, Constants.VERSION); assertFalse(gpxStr, gpxStr.contains("E-")); assertTrue(gpxStr, gpxStr.contains("0.000001")); assertTrue(gpxStr, gpxStr.contains("-0.000125")); verifyGPX(gpxStr); }
/** * 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; }
@Test public void testCreateGPX() { InstructionAnnotation ea = InstructionAnnotation.EMPTY; InstructionList instructions = new InstructionList(usTR); PointList pl = new PointList(); pl.add(49.942576, 11.580384); pl.add(49.941858, 11.582422); instructions.add(new Instruction(Instruction.CONTINUE_ON_STREET, "temp", ea, pl).setDistance(240).setTime(15000)); pl = new PointList(); pl.add(49.941575, 11.583501); instructions.add(new Instruction(Instruction.TURN_LEFT, "temp2", ea, pl).setDistance(25).setTime(4000)); pl = new PointList(); pl.add(49.941389, 11.584311); instructions.add(new Instruction(Instruction.TURN_LEFT, "temp2", ea, pl).setDistance(25).setTime(3000)); instructions.add(new FinishInstruction(49.941029, 11.584514, 0)); List<GPXEntry> result = instructions.createGPXList(); assertEquals(5, result.size()); assertEquals(0, result.get(0).getTime()); assertEquals(10391, result.get(1).getTime()); assertEquals(15000, result.get(2).getTime()); assertEquals(19000, result.get(3).getTime()); assertEquals(22000, result.get(4).getTime()); verifyGPX(instructions.createGPX(Constants.VERSION)); }
@Test public void testPathSimplify() { PointList pointList = new PointList(); pointList.parse2DJSON(points1); assertEquals(32, pointList.getSize()); new DouglasPeucker().setMaxDistance(.5).simplify(pointList); // Arrays.asList(2, 4, 6, 7, 8, 9, 12, 14, 15, 17, 18, 19, 20, 22, 24, 27, 28, 29, 31, 33), assertEquals(20, pointList.getSize()); }
@Test public void testSimplifyCheckPointOrder() { PointList pointList = new PointList(); pointList.parse2DJSON(points2); assertEquals(13, pointList.getSize()); new DouglasPeucker().setMaxDistance(.5).simplify(pointList); assertEquals(11, pointList.getSize()); assertFalse(pointList.toString(), pointList.toString().contains("NaN")); assertEquals("(50.203764443183644,9.961074440801317), (50.20318963087774,9.960999562464645), (50.202952888673984,9.96094144793469), (50.20267889356641,9.96223002587773), (50.201853928011374,9.961859918278305), " + "(50.20138565901039,9.961668810881722), (50.20128507617008,9.96216874485095), (50.20088553877664,9.961953795595925), (50.200686794534775,9.961899033827313), (50.20014066696481,9.961716680863127), (50.199798499043254,9.961588158344957)", pointList.toString()); } }
@Test public void testParse() { PointList pointList = new PointList(); pointList.parse2DJSON("[[11.571499218899739,49.945605917549265],[11.571664621792689,49.94570668665409]]"); assertEquals(49.945605917549265, pointList.getLatitude(0), 1e-6); assertEquals(11.571499218899739, pointList.getLongitude(0), 1e-6); assertEquals(49.94570668665409, pointList.getLatitude(1), 1e-6); assertEquals(11.571664621792689, pointList.getLongitude(1), 1e-6); }
@Test public void testCreateGPXIncludesRoundaboutExitNumber() { InstructionList instructions = new InstructionList(usTR); PointList pl = new PointList(); pl.add(52.555423473315, 13.43890086052345); pl.add(52.555550691982, 13.43946393816465); pl.add(52.555619423589, 13.43886994061328); RoundaboutInstruction instr = new RoundaboutInstruction(Instruction.USE_ROUNDABOUT, "streetname", InstructionAnnotation.EMPTY, pl) .setRadian(2.058006514284998d) .setExitNumber(3) .setExited(); instructions.add(instr); instructions.add(new FinishInstruction(52.555619423589, 13.43886994061328, 0)); String gpxStr = instructions.createGPX("test", 0, true, true, false, false, Constants.VERSION); assertTrue(gpxStr, gpxStr.contains("<gh:exit_number>3</gh:exit_number>")); verifyGPX(gpxStr); }
@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); }
@Test public void testNoInstructionIfSameStreet() { Graph g = new GraphBuilder(carManager).create(); // 2 // \. 5 // \/ // 4 // / // 3 NodeAccess na = g.getNodeAccess(); na.setNode(2, 10.3, 10.15); na.setNode(3, 10.0, 10.05); na.setNode(4, 10.1, 10.10); na.setNode(5, 10.2, 10.15); g.edge(3, 4, 100, true).setName("street"); g.edge(4, 5, 100, true).setName("4-5"); EdgeIteratorState iter = g.edge(2, 4, 100, true); iter.setName("street"); PointList list = new PointList(); list.add(10.20, 10.05); iter.setWayGeometry(list); Path p = new Dijkstra(g, new ShortestWeighting(carEncoder), tMode).calcPath(2, 3); InstructionList wayList = p.calcInstructions(usTR); List<String> tmpList = pick("text", wayList.createJson()); assertEquals(Arrays.asList("Continue onto street", "Turn right onto street", "Arrive at destination"), tmpList); }