@Override public void setTo(int toNode) { toLat = nodeAccess.getLatitude(toNode); toLon = nodeAccess.getLongitude(toNode); }
public void plotNode(Graphics2D g2, NodeAccess na, int loc, Color c, int size, String text) { double lat = na.getLatitude(loc); double lon = na.getLongitude(loc); if (lat < bounds.minLat || lat > bounds.maxLat || lon < bounds.minLon || lon > bounds.maxLon) { return; } Color old = g2.getColor(); g2.setColor(c); plot(g2, lat, lon, size); g2.setColor(old); }
void plotNodeName(Graphics2D g2, int node) { double lat = na.getLatitude(node); double lon = na.getLongitude(node); mg.plotText(g2, lat, lon, "" + node); }
private boolean isInsideBBox(int nodeId) { BBox bbox = localShape.getBounds(); double lat = na.getLatitude(nodeId); double lon = na.getLongitude(nodeId); return lat <= bbox.maxLat && lat >= bbox.minLat && lon <= bbox.maxLon && lon >= bbox.minLon; } };
@Override public double getLatitude(int nodeId) { if (isVirtualNode(nodeId)) return virtualNodes.getLatitude(nodeId - mainNodes); return mainNodeAccess.getLatitude(nodeId); }
@Override protected boolean goFurther(int baseNode) { currNode = baseNode; currLat = nodeAccess.getLatitude(baseNode); currLon = nodeAccess.getLongitude(baseNode); currNormedDist = distCalc.calcNormalizedDist(queryLat, queryLon, currLat, currLon); return goFurther; }
@Override protected boolean goFurther(int nodeId) { if (isPolygon) return isInsideBBox(nodeId); return localShape.contains(na.getLatitude(nodeId), na.getLongitude(nodeId)); }
@Override public double approximate(int fromNode) { double fromLat = nodeAccess.getLatitude(fromNode); double fromLon = nodeAccess.getLongitude(fromNode); double dist2goal = distanceCalc.calcDist(toLat, toLon, fromLat, fromLon); double weight2goal = weighting.getMinWeight(dist2goal); return weight2goal * epsilon; }
private static void warmUpCHSubNetwork(GraphHopper graphHopper, int iterations) { GraphHopperStorage ghStorage = graphHopper.getGraphHopperStorage(); Random rand = new Random(0); for (int i = 0; i < iterations; i++) { int startNode = rand.nextInt(graphHopper.getMaxVisitedNodes() + 1); int endNode = rand.nextInt(graphHopper.getMaxVisitedNodes() + 1); double fromLatitude = ghStorage.getNodeAccess().getLatitude(startNode); double fromLongitude = ghStorage.getNodeAccess().getLongitude(startNode); double toLatitude = ghStorage.getNodeAccess().getLatitude(endNode); double toLongitude = ghStorage.getNodeAccess().getLongitude(endNode); GHRequest request = new GHRequest(fromLatitude, fromLongitude, toLatitude, toLongitude); graphHopper.route(request); } }
private static GHPoint createPoint(Graph graph, int nodeId) { return new GHPoint(graph.getNodeAccess().getLatitude(nodeId), graph.getNodeAccess().getLongitude(nodeId)); }
public static int getIdOf(Graph g, double latitude) { int s = g.getNodes(); NodeAccess na = g.getNodeAccess(); for (int i = 0; i < s; i++) { if (Math.abs(na.getLatitude(i) - latitude) < 1e-4) { return i; } } return -1; }
public static int getIdOf(Graph g, double latitude, double longitude) { int s = g.getNodes(); NodeAccess na = g.getNodeAccess(); for (int i = 0; i < s; i++) { if (Math.abs(na.getLatitude(i) - latitude) < 1e-4 && Math.abs(na.getLongitude(i) - longitude) < 1e-4) { return i; } } throw new IllegalArgumentException("did not find node with location " + (float) latitude + "," + (float) longitude); }
public boolean containsLatitude(Graph g, EdgeIterator iter, double latitude) { NodeAccess na = g.getNodeAccess(); while (iter.next()) { if (Math.abs(na.getLatitude(iter.getAdjNode()) - latitude) < 1e-4) return true; } return false; }
public InstructionsFromEdges(int tmpNode, Graph graph, Weighting weighting, FlagEncoder encoder, NodeAccess nodeAccess, Translation tr, InstructionList ways) { this.weighting = weighting; this.encoder = encoder; this.nodeAccess = nodeAccess; this.tr = tr; this.ways = ways; prevLat = this.nodeAccess.getLatitude(tmpNode); prevLon = this.nodeAccess.getLongitude(tmpNode); prevNode = -1; prevInRoundabout = false; prevName = null; outEdgeExplorer = graph.createEdgeExplorer(DefaultEdgeFilter.outEdges(encoder)); crossingExplorer = graph.createEdgeExplorer(DefaultEdgeFilter.allEdges(encoder)); }
@Override protected boolean checkAdjacent(EdgeIteratorState edge) { int adjNodeId = edge.getAdjNode(); if (localShape.contains(na.getLatitude(adjNodeId), na.getLongitude(adjNodeId))) { edgeIds.add(edge.getEdge()); return true; } return isPolygon && isInsideBBox(adjNodeId); }
@Test public void testSort() { Graph g = initUnsorted(createGraph()); Graph newG = GHUtility.sortDFS(g, createGraph()); assertEquals(g.getNodes(), newG.getNodes()); NodeAccess na = newG.getNodeAccess(); assertEquals(0, na.getLatitude(0), 1e-4); // 0 assertEquals(2.5, na.getLatitude(1), 1e-4); // 1 assertEquals(4.5, na.getLatitude(2), 1e-4); // 2 assertEquals(4.6, na.getLatitude(3), 1e-4); // 8 assertEquals(3.0, na.getLatitude(4), 1e-4); // 3 assertEquals(5.0, na.getLatitude(5), 1e-4); // 7 assertEquals(4.2, na.getLatitude(6), 1e-4); // 5 }
@Test public void testSort2() { Graph g = initUnsorted(createGraph()); Graph newG = GHUtility.sortDFS(g, createGraph()); assertEquals(g.getNodes(), newG.getNodes()); NodeAccess na = newG.getNodeAccess(); assertEquals(0, na.getLatitude(0), 1e-4); // 0 assertEquals(2.5, na.getLatitude(1), 1e-4); // 1 assertEquals(4.5, na.getLatitude(2), 1e-4); // 2 assertEquals(4.6, na.getLatitude(3), 1e-4); // 8 }
static GHPoint getPointForOrientationCalculation(EdgeIteratorState edgeIteratorState, NodeAccess nodeAccess) { double tmpLat; double tmpLon; PointList tmpWayGeo = edgeIteratorState.fetchWayGeometry(3); if (tmpWayGeo.getSize() <= 2) { tmpLat = nodeAccess.getLatitude(edgeIteratorState.getAdjNode()); tmpLon = nodeAccess.getLongitude(edgeIteratorState.getAdjNode()); } else { tmpLat = tmpWayGeo.getLatitude(1); tmpLon = tmpWayGeo.getLongitude(1); } return new GHPoint(tmpLat, tmpLon); } }
public static String getNodeInfo(CHGraph g, int nodeId, EdgeFilter filter) { CHEdgeExplorer ex = g.createEdgeExplorer(filter); CHEdgeIterator iter = ex.setBaseNode(nodeId); NodeAccess na = g.getNodeAccess(); String str = nodeId + ":" + na.getLatitude(nodeId) + "," + na.getLongitude(nodeId) + "\n"; while (iter.next()) { str += " ->" + iter.getAdjNode() + "(" + iter.getSkippedEdge1() + "," + iter.getSkippedEdge2() + ") " + iter.getEdge() + " \t" + BitUtil.BIG.toBitString(iter.getFlags(), 8) + "\n"; } return str; }
public static String getNodeInfo(Graph g, int nodeId, EdgeFilter filter) { EdgeIterator iter = g.createEdgeExplorer(filter).setBaseNode(nodeId); NodeAccess na = g.getNodeAccess(); String str = nodeId + ":" + na.getLatitude(nodeId) + "," + na.getLongitude(nodeId) + "\n"; while (iter.next()) { str += " ->" + iter.getAdjNode() + " (" + iter.getDistance() + ") pillars:" + iter.fetchWayGeometry(0).getSize() + ", edgeId:" + iter.getEdge() + "\t" + BitUtil.BIG.toBitString(iter.getFlags(), 8) + "\n"; } return str; }