public void add(double lat, double lon) { if (is3D) throw new IllegalStateException("Cannot add point without elevation data in 3D mode"); add(lat, lon, Double.NaN); }
/** * Takes the string from a json array ala [lon1,lat1], [lon2,lat2], ... and fills the list from * it. */ public void parse2DJSON(String str) { for (String latlon : str.split("\\[")) { if (latlon.trim().length() == 0) continue; String ll[] = latlon.split(","); String lat = ll[1].replace("]", "").trim(); add(Double.parseDouble(lat), Double.parseDouble(ll[0].trim()), Double.NaN); } }
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; }
@Override public void set(double lat, double lon) { points.add(lat, lon); } };
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; }
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; }
@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); } }
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; }
/** * @return converted tower node */ private int handlePillarNode(int tmpNode, long osmId, PointList pointList, boolean convertToTowerNode) { tmpNode = tmpNode - 3; double lat = pillarInfo.getLatitude(tmpNode); double lon = pillarInfo.getLongitude(tmpNode); double ele = pillarInfo.getElevation(tmpNode); if (lat == Double.MAX_VALUE || lon == Double.MAX_VALUE) throw new RuntimeException("Conversion pillarNode to towerNode already happended!? " + "osmId:" + osmId + " pillarIndex:" + tmpNode); if (convertToTowerNode) { // convert pillarNode type to towerNode, make pillar values invalid pillarInfo.setNode(tmpNode, Double.MAX_VALUE, Double.MAX_VALUE, Double.MAX_VALUE); tmpNode = addTowerNode(osmId, lat, lon, ele); } else if (pointList.is3D()) pointList.add(lat, lon, ele); else pointList.add(lat, lon); return (int) tmpNode; }
@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); }
/** * 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 void updatePointsAndInstruction(EdgeIteratorState edge, PointList pl) { // skip adjNode int len = pl.size() - 1; for (int i = 0; i < len; i++) { prevInstruction.getPoints().add(pl, i); } double newDist = edge.getDistance(); prevInstruction.setDistance(newDist + prevInstruction.getDistance()); prevInstruction.setTime(weighting.calcMillis(edge, false, EdgeIterator.NO_EDGE) + prevInstruction.getTime()); }
@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); }
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); } } }
@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 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); }