double startLat = nodeAccess.getLat(baseNode); double startLon = nodeAccess.getLon(baseNode); double heading = Helper.ANGLE_CALC.calcAzimuth(startLat, startLon, latitude, longitude);
@Override public void updateBestPath(EdgeIteratorState es, SPTEntry entry, int traversalId, boolean reverse) { if (g2 != null) { mg.plotEdge(g2, na.getLat(entry.parent.adjNode), na.getLon(entry.parent.adjNode), na.getLat(entry.adjNode), na.getLon(entry.adjNode), .8f); } // System.out.println("new node:" + currLoc); super.updateBestPath(es, entry, traversalId, reverse); } }
/** * @return the calculated landmarks as GeoJSON string. */ String getLandmarksAsGeoJSON() { NodeAccess na = graph.getNodeAccess(); String str = ""; for (int subnetwork = 1; subnetwork < landmarkIDs.size(); subnetwork++) { int[] lmArray = landmarkIDs.get(subnetwork); for (int lmIdx = 0; lmIdx < lmArray.length; lmIdx++) { int index = lmArray[lmIdx]; if (!str.isEmpty()) str += ","; str += "{ \"type\": \"Feature\", \"geometry\": {\"type\": \"Point\", \"coordinates\": [" + na.getLon(index) + ", " + na.getLat(index) + "]},"; str += " \"properties\":{\"node_index\":" + index + "," + "\"subnetwork\":" + subnetwork + "," + "\"lm_index\":" + lmIdx + "}" + "}"; } } return "{ \"type\": \"FeatureCollection\", \"features\": [" + str + "]}"; }
final double calcMinDistance(double queryLat, double queryLon, GHIntHashSet pointset) { double min = Double.MAX_VALUE; Iterator<IntCursor> itr = pointset.iterator(); while (itr.hasNext()) { int node = itr.next().value; double lat = nodeAccess.getLat(node); double lon = nodeAccess.getLon(node); double dist = distCalc.calcDist(queryLat, queryLon, lat, lon); if (dist < min) { min = dist; } } return min; }
private String getCoords(EdgeIteratorState edge, Graph graph) { NodeAccess na = graph.getNodeAccess(); int base = edge.getBaseNode(); int adj = edge.getAdjNode(); return base + "->" + adj + " (" + edge.getEdge() + "); " + na.getLat(base) + "," + na.getLon(base) + " -> " + na.getLat(adj) + "," + na.getLon(adj); }
private void interpolateElevationsOfInnerNodesForThreeOuterNodes(int firstOuterNodeId, int secondOuterNodeId, int thirdOuterNodeId, int[] innerNodeIds) { NodeAccess nodeAccess = storage.getNodeAccess(); double lat0 = nodeAccess.getLat(firstOuterNodeId); double lon0 = nodeAccess.getLon(firstOuterNodeId); double ele0 = nodeAccess.getEle(firstOuterNodeId); double lat1 = nodeAccess.getLat(secondOuterNodeId); double lon1 = nodeAccess.getLon(secondOuterNodeId); double ele1 = nodeAccess.getEle(secondOuterNodeId); double lat2 = nodeAccess.getLat(thirdOuterNodeId); double lon2 = nodeAccess.getLon(thirdOuterNodeId); double ele2 = nodeAccess.getEle(thirdOuterNodeId); for (int innerNodeId : innerNodeIds) { double lat = nodeAccess.getLat(innerNodeId); double lon = nodeAccess.getLon(innerNodeId); double ele = elevationInterpolator.calculateElevationBasedOnThreePoints(lat, lon, lat0, lon0, ele0, lat1, lon1, ele1, lat2, lon2, ele2); nodeAccess.setNode(innerNodeId, lat, lon, ele); } }
private void interpolateElevationsOfInnerNodesForTwoOuterNodes(int firstOuterNodeId, int secondOuterNodeId, int[] innerNodeIds) { final NodeAccess nodeAccess = storage.getNodeAccess(); double lat0 = nodeAccess.getLat(firstOuterNodeId); double lon0 = nodeAccess.getLon(firstOuterNodeId); double ele0 = nodeAccess.getEle(firstOuterNodeId); double lat1 = nodeAccess.getLat(secondOuterNodeId); double lon1 = nodeAccess.getLon(secondOuterNodeId); double ele1 = nodeAccess.getEle(secondOuterNodeId); for (int innerNodeId : innerNodeIds) { double lat = nodeAccess.getLat(innerNodeId); double lon = nodeAccess.getLon(innerNodeId); double ele = elevationInterpolator.calculateElevationBasedOnTwoPoints(lat, lon, lat0, lon0, ele0, lat1, lon1, ele1); nodeAccess.setNode(innerNodeId, lat, lon, ele); } }
public void debugPrint() { final int printMax = 100; System.out.println("nodes:"); String formatNodes = "%12s | %12s | %12s | %12s \n"; System.out.format(Locale.ROOT, formatNodes, "#", "N_EDGE_REF", "N_LAT", "N_LON"); NodeAccess nodeAccess = getNodeAccess(); for (int i = 0; i < Math.min(nodeCount, printMax); ++i) { System.out.format(Locale.ROOT, formatNodes, i, edgeAccess.getEdgeRef(i), nodeAccess.getLat(i), nodeAccess.getLon(i)); } if (nodeCount > printMax) { System.out.format(Locale.ROOT, " ... %d more nodes\n", nodeCount - printMax); } System.out.println("edges:"); String formatEdges = "%12s | %12s | %12s | %12s | %12s | %12s | %12s \n"; System.out.format(Locale.ROOT, formatEdges, "#", "E_NODEA", "E_NODEB", "E_LINKA", "E_LINKB", "E_DIST", "E_FLAGS"); for (int i = 0; i < Math.min(edgeCount, printMax); ++i) { System.out.format(Locale.ROOT, formatEdges, i, edges.getInt((long) (i * edgeEntryBytes) + edgeAccess.E_NODEA), edges.getInt((long) (i * edgeEntryBytes) + edgeAccess.E_NODEB), edges.getInt((long) (i * edgeEntryBytes) + edgeAccess.E_LINKA), edges.getInt((long) (i * edgeEntryBytes) + edgeAccess.E_LINKB), edges.getInt((long) (i * edgeEntryBytes) + edgeAccess.E_DIST), edges.getInt((long) (i * edgeEntryBytes) + edgeAccess.E_FLAGS)); } if (edgeCount > printMax) { System.out.printf(Locale.ROOT, " ... %d more edges", edgeCount - printMax); } }
private void interpolateElevationsOfInnerNodesForOneOuterNode(int outerNodeId, int[] innerNodeIds) { NodeAccess nodeAccess = storage.getNodeAccess(); double ele = nodeAccess.getEle(outerNodeId); for (int innerNodeId : innerNodeIds) { double lat = nodeAccess.getLat(innerNodeId); double lon = nodeAccess.getLon(innerNodeId); nodeAccess.setNode(innerNodeId, lat, lon, ele); } }
public static void printGraphForUnitTest(Graph g, FlagEncoder encoder, BBox bBox) { NodeAccess na = g.getNodeAccess(); for (int node = 0; node < g.getNodes(); ++node) { if (bBox.contains(na.getLat(node), na.getLon(node))) { System.out.printf(Locale.ROOT, "na.setNode(%d, %f, %f);\n", node, na.getLat(node), na.getLon(node)); } } AllEdgesIterator iter = g.getAllEdges(); while (iter.next()) { if (bBox.contains(na.getLat(iter.getBaseNode()), na.getLon(iter.getBaseNode())) && bBox.contains(na.getLat(iter.getAdjNode()), na.getLon(iter.getAdjNode()))) { printUnitTestEdge(encoder, iter); } } }
PointList points = new PointList(2, false); final int fromnode = gtfsStorage.getStationNodes().get(e.getValue().from_stop_id); final QueryResult fromstation = new QueryResult(graphHopperStorage.getNodeAccess().getLat(fromnode), graphHopperStorage.getNodeAccess().getLon(fromnode)); fromstation.setClosestNode(fromnode); points.add(graphHopperStorage.getNodeAccess().getLat(fromnode), graphHopperStorage.getNodeAccess().getLon(fromnode)); final QueryResult tostation = new QueryResult(graphHopperStorage.getNodeAccess().getLat(tonode), graphHopperStorage.getNodeAccess().getLon(tonode)); tostation.setClosestNode(tonode); points.add(graphHopperStorage.getNodeAccess().getLat(tonode), graphHopperStorage.getNodeAccess().getLon(tonode));
private double getAngle(int n1, int n2, int n3, int n4) { double inOrientation = Helper.ANGLE_CALC.calcOrientation(na.getLat(n1), na.getLon(n1), na.getLat(n2), na.getLon(n2)); double outOrientation = Helper.ANGLE_CALC.calcOrientation(na.getLat(n3), na.getLon(n3), na.getLat(n4), na.getLon(n4)); outOrientation = Helper.ANGLE_CALC.alignOrientation(inOrientation, outOrientation); double delta = (inOrientation - outOrientation); delta = clockwise ? (Math.PI + delta) : -1 * (Math.PI - delta); return delta; } }
final void setWeight(CommonEdgeIterator edge, double weight) { if (weight < 0) throw new IllegalArgumentException("weight cannot be negative but was " + weight); long weightLong; if (weight < MIN_WEIGHT) { NodeAccess nodeAccess = getNodeAccess(); LOGGER.warn("Setting weights smaller than " + MIN_WEIGHT + " is not allowed in CHGraphImpl#setWeight. " + "You passed: " + weight + " for the edge " + edge.getEdge() + " from " + nodeAccess.getLat(edge.getBaseNode()) + "," + nodeAccess.getLon(edge.getBaseNode()) + " to " + nodeAccess.getLat(edge.getAdjNode()) + "," + nodeAccess.getLon(edge.getAdjNode())); weight = MIN_WEIGHT; } if (weight > MAX_WEIGHT) weightLong = MAX_WEIGHT_LONG; else weightLong = ((long) (weight * WEIGHT_FACTOR)) << 2; long accessFlags = edge.getDirectFlags() & scDirMask; edge.setFlags(weightLong | accessFlags); }
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); } } }
private void interpolateElevationsOfPillarNodes() { final EdgeIterator edge = storage.getAllEdges(); final NodeAccess nodeAccess = storage.getNodeAccess(); while (edge.next()) { if (isInterpolatableEdge(edge)) { int firstNodeId = edge.getBaseNode(); int secondNodeId = edge.getAdjNode(); double lat0 = nodeAccess.getLat(firstNodeId); double lon0 = nodeAccess.getLon(firstNodeId); double ele0 = nodeAccess.getEle(firstNodeId); double lat1 = nodeAccess.getLat(secondNodeId); double lon1 = nodeAccess.getLon(secondNodeId); double ele1 = nodeAccess.getEle(secondNodeId); final PointList pointList = edge.fetchWayGeometry(0); final int count = pointList.size(); for (int index = 0; index < count; index++) { double lat = pointList.getLat(index); double lon = pointList.getLon(index); double ele = elevationInterpolator.calculateElevationBasedOnTwoPoints(lat, lon, lat0, lon0, ele0, lat1, lon1, ele1); pointList.set(index, lat, lon, ele); } edge.setWayGeometry(pointList); } } } }
String toString(FlagEncoder encoder, EdgeIterator iter) { String str = ""; while (iter.next()) { int adjNode = iter.getAdjNode(); str += adjNode + " (" + ghStorage.getNodeAccess().getLat(adjNode) + "," + ghStorage.getNodeAccess().getLon(adjNode) + "), "; str += "speed (fwd:" + encoder.getSpeed(iter.getFlags()) + ", rev:" + encoder.getReverseSpeed(iter.getFlags()) + "), "; str += "access (fwd:" + encoder.isForward(iter.getFlags()) + ", rev:" + encoder.isBackward(iter.getFlags()) + "), "; str += "distance:" + iter.getDistance(); str += ";\n "; } return str; }
@Test public void testRMin() { Graph graph = createTestGraph(encodingManager); LocationIndexTree index = createIndex(graph, 50000); //query: 0.05 | -0.3 DistanceCalc distCalc = new DistancePlaneProjection(); double rmin = index.calculateRMin(0.05, -0.3); double check = distCalc.calcDist(0.05, Math.abs(graph.getNodeAccess().getLon(2)) - index.getDeltaLon(), -0.3, -0.3); assertTrue((rmin - check) < 0.0001); double rmin2 = index.calculateRMin(0.05, -0.3, 1); double check2 = distCalc.calcDist(0.05, Math.abs(graph.getNodeAccess().getLat(0)), -0.3, -0.3); assertTrue((rmin2 - check2) < 0.0001); GHIntHashSet points = new GHIntHashSet(); assertEquals(Double.MAX_VALUE, index.calcMinDistance(0.05, -0.3, points), 1e-1); points.add(0); points.add(1); assertEquals(54757.03, index.calcMinDistance(0.05, -0.3, points), 1e-1); /*GraphVisualizer gv = new GraphVisualizer(graph, index.getDeltaLat(), index.getDeltaLon(), index.getCenter(0, 0).lat, index.getCenter(0, 0).lon); try { Thread.sleep(4000); } catch(InterruptedException ie) {}*/ }
QueryResult qr = index.findClosest(na.getLat(i), na.getLon(i), EdgeFilter.ALL_EDGES); assertEquals(i, qr.getClosestNode());
private void interpolateElevationsOfInnerNodesForOneOuterNode(int outerNodeId, int[] innerNodeIds) { NodeAccess nodeAccess = storage.getNodeAccess(); double ele = nodeAccess.getEle(outerNodeId); for (int innerNodeId : innerNodeIds) { double lat = nodeAccess.getLat(innerNodeId); double lon = nodeAccess.getLon(innerNodeId); nodeAccess.setNode(innerNodeId, lat, lon, ele); } }