Search in sources :

Example 1 with CloseableCollection

use of org.geotoolkit.index.CloseableCollection in project geotoolkit by Geomatys.

the class FileSystemNodeTest method testNoerror.

/**
 * Just test it doesn't raise an error.
 * TODO : move tests from shapefile.
 */
@Test
public void testNoerror() throws Exception {
    final File file = new File("src/test/resources/org/geotoolkit/index/sample.qix");
    final FileSystemIndexStore store = new FileSystemIndexStore(file);
    final DataReader reader = new DataReader() {

        @Override
        public Data read(final int id) throws IOException {
            return new DefaultData(DATA_DEFINITION) {

                @Override
                public String toString() {
                    return Integer.toString(id);
                }
            };
        }

        @Override
        public void close() throws IOException {
        }

        @Override
        public void read(int[] ids, Data[] buffer, int size) throws IOException {
            for (int i = 0; i < size; i++) {
                buffer[i] = read(ids[i]);
            }
        }
    };
    final QuadTree tree = store.load();
    assertEquals(10, tree.getMaxDepth());
    assertEquals(new Envelope(-8.86966023318779, 3.188061808903407, 36.113981340792286, 43.55971524165336), tree.getRoot().getBounds(new Envelope()));
    assertEquals(3602, tree.getNumShapes());
    final AbstractNode root = tree.getRoot();
    for (int i = 0; i < 4; i++) {
        root.getSubNode(i);
    }
    CloseableCollection col = tree.search(reader, new Envelope(-8, 3, 37, 40));
    Iterator ite = col.iterator();
    while (ite.hasNext()) {
        ite.next();
    }
}
Also used : DataReader(org.geotoolkit.index.quadtree.DataReader) QuadTree(org.geotoolkit.index.quadtree.QuadTree) AbstractNode(org.geotoolkit.index.quadtree.AbstractNode) CloseableCollection(org.geotoolkit.index.CloseableCollection) Iterator(java.util.Iterator) Envelope(org.locationtech.jts.geom.Envelope) File(java.io.File) DefaultData(org.geotoolkit.index.DefaultData) Test(org.junit.Test)

Aggregations

File (java.io.File)1 Iterator (java.util.Iterator)1 CloseableCollection (org.geotoolkit.index.CloseableCollection)1 DefaultData (org.geotoolkit.index.DefaultData)1 AbstractNode (org.geotoolkit.index.quadtree.AbstractNode)1 DataReader (org.geotoolkit.index.quadtree.DataReader)1 QuadTree (org.geotoolkit.index.quadtree.QuadTree)1 Test (org.junit.Test)1 Envelope (org.locationtech.jts.geom.Envelope)1