@Test public void testFindingWayGeometry() { Graph g = createGHStorage(encodingManager); NodeAccess na = g.getNodeAccess(); na.setNode(10, 51.2492152, 9.4317166); na.setNode(20, 52, 9); na.setNode(30, 51.2, 9.4); na.setNode(50, 49, 10); g.edge(20, 50, 1, true).setWayGeometry(Helper.createPointList(51.25, 9.43)); g.edge(10, 20, 1, true); g.edge(20, 30, 1, true); LocationIndex index = createIndex(g, 2000); assertEquals(20, findID(index, 51.25, 9.43)); }
@Override public LocationIndexTree createIndex(Graph g, int resolution) { if (resolution < 0) resolution = 500000; return (LocationIndexTree) createIndexNoPrepare(g, resolution).prepareIndex(); }
@Test public void testReverseSpatialKey() { LocationIndexTree index = createIndex(createTestGraph(encodingManager), 200); assertEquals(IntArrayList.from(new int[]{64, 64, 64, 4}), index.getEntries()); // 10111110111110101010 String str44 = "00000000000000000000000000000000000000000000"; assertEquals(str44 + "01010101111101111101", BitUtil.BIG.toBitString(index.createReverseKey(1.7, 0.099))); }
@Test public void testWayGeometry() { Graph g = createTestGraphWithWayGeometry(); LocationIndex index = createIndex(g, -1); assertEquals(1, findID(index, 0, 0)); assertEquals(1, findID(index, 0, 0.1)); assertEquals(1, findID(index, 0.1, 0.1)); assertEquals(1, findID(index, -0.5, -0.5)); }
@Test public void testFindNClosest() { Graph graph = createGHStorage(new RAMDirectory(), encodingManager, false); NodeAccess na = graph.getNodeAccess(); na.setNode(0, 0.0010, 0.0000); graph.edge(7, 8); LocationIndexTree index = createIndexNoPrepare(graph, 500); index.prepareIndex();
@Test public void testInMemIndex() { Graph graph = createTestGraph(encodingManager); LocationIndexTree index = createIndexNoPrepare(graph, 50000); index.prepareAlgo(); LocationIndexTree.InMemConstructionIndex inMemIndex = index.getPrepareInMemIndex(); index.findNetworkEntries(-0.5, -0.9, foundIds, 1); assertEquals(set, foundIds); assertEquals(2, findID(index, -0.5, -0.9));
@Test public void testInMemIndex3() { LocationIndexTree index = createIndexNoPrepare(createTestGraph(encodingManager), 10000); index.prepareAlgo(); LocationIndexTree.InMemConstructionIndex inMemIndex = index.getPrepareInMemIndex(); assertEquals(IntArrayList.from(new int[]{64, 4}), index.getEntries()); assertEquals(33, inMemIndex.getEntriesOf(0).size()); assertEquals(69, inMemIndex.getEntriesOf(1).size()); assertEquals(0, inMemIndex.getEntriesOf(2).size()); index.dataAccess.create(1024); inMemIndex.store(inMemIndex.root, LocationIndexTree.START_POINTER); assertEquals(1 << 20, index.getCapacity()); QueryResult res = index.findClosest(-.5, -.5, EdgeFilter.ALL_EDGES); assertEquals(1, res.getClosestNode()); }
@Test public void testInMemIndex2() { Graph graph = createTestGraph2(); LocationIndexTree index = createIndexNoPrepare(graph, 500); index.prepareAlgo(); LocationIndexTree.InMemConstructionIndex inMemIndex = index.getPrepareInMemIndex();
Graph createTestGraph(EncodingManager em) { Graph graph = createGHStorage(new RAMDirectory(), em, false); NodeAccess na = graph.getNodeAccess(); na.setNode(0, 0.5, -0.5); na.setNode(1, -0.5, -0.5); na.setNode(2, -1, -1); na.setNode(3, -0.4, 0.9); na.setNode(4, -0.6, 1.6); graph.edge(0, 1, 1, true); graph.edge(0, 2, 1, true); graph.edge(0, 4, 1, true); graph.edge(1, 3, 1, true); graph.edge(2, 3, 1, true); graph.edge(2, 4, 1, true); graph.edge(3, 4, 1, true); return graph; }
Graph graph = createGHStorage(new RAMDirectory(), tmpEM, false); NodeAccess na = graph.getNodeAccess(); LocationIndexTree index = createIndexNoPrepare(graph, 500); index.prepareIndex(); index.setMaxRegionSearch(8);
private Graph createTestGraphWithWayGeometry() { Graph graph = createGHStorage(encodingManager); NodeAccess na = graph.getNodeAccess(); na.setNode(0, 0.5, -0.5); na.setNode(1, -0.5, -0.5); na.setNode(2, -1, -1); na.setNode(3, -0.4, 0.9); na.setNode(4, -0.6, 1.6); graph.edge(0, 1, 1, true); graph.edge(0, 2, 1, true); // insert A and B, without this we would get 0 for 0,0 graph.edge(0, 4, 1, true).setWayGeometry(Helper.createPointList(1, 1)); graph.edge(1, 3, 1, true).setWayGeometry(Helper.createPointList(0, 0)); graph.edge(2, 3, 1, true); graph.edge(2, 4, 1, true); graph.edge(3, 4, 1, true); return graph; }
@Test public void testMoreReal() { Graph graph = createGHStorage(new EncodingManager("car")); NodeAccess na = graph.getNodeAccess(); na.setNode(1, 51.2492152, 9.4317166); na.setNode(0, 52, 9); na.setNode(2, 51.2, 9.4); na.setNode(3, 49, 10); graph.edge(1, 0, 1000, true); graph.edge(0, 2, 1000, true); graph.edge(0, 3, 1000, true).setWayGeometry(Helper.createPointList(51.21, 9.43)); LocationIndex index = createIndex(graph, -1); assertEquals(2, findID(index, 51.2, 9.4)); }
@Test public void testEdgeFilter() { Graph graph = createTestGraph(encodingManager); LocationIndexTree index = createIndex(graph, -1); assertEquals(1, index.findClosest(-.6, -.6, EdgeFilter.ALL_EDGES).getClosestNode()); assertEquals(2, index.findClosest(-.6, -.6, new EdgeFilter() { @Override public boolean accept(EdgeIteratorState iter) { return iter.getBaseNode() == 2 || iter.getAdjNode() == 2; } }).getClosestNode()); }
@Test public void testCrossBoundaryNetwork_issue667() { Graph graph = createGHStorage(new RAMDirectory(), encodingManager, false); NodeAccess na = graph.getNodeAccess(); na.setNode(0, 0.1, 179.5); LocationIndexTree index = createIndexNoPrepare(graph, 500); index.prepareIndex();
Graph createTestGraph2() { Graph graph = createGHStorage(new RAMDirectory(), encodingManager, false); NodeAccess na = graph.getNodeAccess(); na.setNode(8, 49.94553, 11.57214);
@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) {}*/ }
@Test public void testSnappedPointAndGeometry() { Graph graph = createTestGraph(encodingManager); LocationIndex index = createIndex(graph, -1); // query directly the tower node QueryResult res = index.findClosest(-0.4, 0.9, EdgeFilter.ALL_EDGES); assertTrue(res.isValid()); assertEquals(new GHPoint(-0.4, 0.9), res.getSnappedPoint()); res = index.findClosest(-0.6, 1.6, EdgeFilter.ALL_EDGES); assertTrue(res.isValid()); assertEquals(new GHPoint(-0.6, 1.6), res.getSnappedPoint()); // query the edge (1,3). The edge (0,4) has 27674 as distance res = index.findClosest(-0.2, 0.3, EdgeFilter.ALL_EDGES); assertTrue(res.isValid()); assertEquals(26936, res.getQueryDistance(), 1); assertEquals(new GHPoint(-0.441624, 0.317259), res.getSnappedPoint()); }