Search in sources :

Example 6 with SpatialIndexEntry

use of org.bboxdb.storage.sstable.spatialindex.SpatialIndexEntry in project bboxdb by jnidzwetzki.

the class TestRTreeIndex method testBoxQuery1d0.

/**
 * Test to query the index
 */
@Test(timeout = 60000)
public void testBoxQuery1d0() {
    final List<SpatialIndexEntry> tupleList = RTreeTestHelper.getEntryList();
    final SpatialIndexBuilder index = new RTreeBuilder(4);
    index.bulkInsert(tupleList);
    RTreeTestHelper.queryIndex(tupleList, index);
}
Also used : RTreeBuilder(org.bboxdb.storage.sstable.spatialindex.rtree.RTreeBuilder) SpatialIndexBuilder(org.bboxdb.storage.sstable.spatialindex.SpatialIndexBuilder) SpatialIndexEntry(org.bboxdb.storage.sstable.spatialindex.SpatialIndexEntry) Test(org.junit.Test)

Example 7 with SpatialIndexEntry

use of org.bboxdb.storage.sstable.spatialindex.SpatialIndexEntry in project bboxdb by jnidzwetzki.

the class TestRTreeIndex method testBoxQuery5d.

/**
 * Test to query the index
 */
@Test(timeout = 60000)
public void testBoxQuery5d() {
    final List<SpatialIndexEntry> tupleList = RTreeTestHelper.generateRandomTupleList(5);
    final SpatialIndexBuilder index = new RTreeBuilder();
    index.bulkInsert(tupleList);
    RTreeTestHelper.queryIndex(tupleList, index);
}
Also used : RTreeBuilder(org.bboxdb.storage.sstable.spatialindex.rtree.RTreeBuilder) SpatialIndexBuilder(org.bboxdb.storage.sstable.spatialindex.SpatialIndexBuilder) SpatialIndexEntry(org.bboxdb.storage.sstable.spatialindex.SpatialIndexEntry) Test(org.junit.Test)

Example 8 with SpatialIndexEntry

use of org.bboxdb.storage.sstable.spatialindex.SpatialIndexEntry in project bboxdb by jnidzwetzki.

the class TestRTreeMemoryDeserializer method testSerializeIndexSmall.

/**
 * Test the encoding and the decoding of the index with only one entry
 * = data is encoded in the root node
 *
 * @throws StorageManagerException
 * @throws IOException
 * @throws InterruptedException
 */
@Test(timeout = 60000)
public void testSerializeIndexSmall() throws StorageManagerException, IOException, InterruptedException {
    final List<SpatialIndexEntry> tupleList = new ArrayList<>();
    tupleList.add(new SpatialIndexEntry(new BoundingBox(1.0, 1.2), 2));
    final SpatialIndexBuilder index = new RTreeBuilder();
    index.bulkInsert(tupleList);
    RTreeTestHelper.queryIndex(tupleList, index);
    final File tempFile = File.createTempFile("rtree-", "-test");
    tempFile.deleteOnExit();
    final RandomAccessFile raf = new RandomAccessFile(tempFile, "rw");
    index.writeToFile(raf);
    raf.close();
    final AbstractRTreeReader indexRead = getRTreeReader();
    final RandomAccessFile rafRead = new RandomAccessFile(tempFile, "r");
    indexRead.readFromFile(rafRead);
    rafRead.close();
    final List<? extends SpatialIndexEntry> resultList = indexRead.getEntriesForRegion(new BoundingBox(1.1, 1.2));
    Assert.assertEquals(1, resultList.size());
    indexRead.close();
}
Also used : RTreeBuilder(org.bboxdb.storage.sstable.spatialindex.rtree.RTreeBuilder) RandomAccessFile(java.io.RandomAccessFile) AbstractRTreeReader(org.bboxdb.storage.sstable.spatialindex.rtree.AbstractRTreeReader) SpatialIndexBuilder(org.bboxdb.storage.sstable.spatialindex.SpatialIndexBuilder) BoundingBox(org.bboxdb.commons.math.BoundingBox) ArrayList(java.util.ArrayList) SpatialIndexEntry(org.bboxdb.storage.sstable.spatialindex.SpatialIndexEntry) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Test(org.junit.Test)

Example 9 with SpatialIndexEntry

use of org.bboxdb.storage.sstable.spatialindex.SpatialIndexEntry in project bboxdb by jnidzwetzki.

the class SSTableWriter method addNextTuple.

/**
 * Add the next tuple into the result sstable
 * @param tuple
 * @throws IOException
 * @throws StorageManagerException
 */
public void addNextTuple(final Tuple tuple) throws StorageManagerException {
    try {
        // Add Tuple to the index
        final int tuplePosition = (int) sstableOutputStream.getCount();
        writeIndexEntry(tuplePosition);
        final int newPosition = (int) sstableOutputStream.getCount();
        final int writtenBytes = newPosition - tuplePosition;
        // Add Tuple to the SSTable file
        TupleHelper.writeTupleToStream(tuple, sstableOutputStream);
        metadataBuilder.addTuple(tuple);
        // Add tuple to the bloom filter
        bloomFilter.put(tuple.getKey());
        // Add tuple to the spatial index
        final SpatialIndexEntry sIndexentry = new SpatialIndexEntry(tuple.getBoundingBox(), tuplePosition);
        spatialIndex.insert(sIndexentry);
        writtenTuplesTotal.inc();
        writtenTuplesBytes.inc(writtenBytes);
    } catch (IOException e) {
        exceptionDuringWrite = true;
        throw new StorageManagerException("Unable to write tuple to SSTable", e);
    }
}
Also used : IOException(java.io.IOException) StorageManagerException(org.bboxdb.storage.StorageManagerException) SpatialIndexEntry(org.bboxdb.storage.sstable.spatialindex.SpatialIndexEntry)

Example 10 with SpatialIndexEntry

use of org.bboxdb.storage.sstable.spatialindex.SpatialIndexEntry in project bboxdb by jnidzwetzki.

the class RTreeMemoryReader method readEntryNodes.

/**
 * Read the entry nodes
 * @param inputStream
 * @throws IOException
 */
protected void readEntryNodes(final RandomAccessFile randomAccessFile) throws IOException {
    final byte[] followingByte = new byte[RTreeBuilder.MAGIC_VALUE_SIZE];
    for (int i = 0; i < maxNodeSize; i++) {
        randomAccessFile.readFully(followingByte, 0, followingByte.length);
        if (Arrays.equals(followingByte, RTreeBuilder.MAGIC_CHILD_NODE_FOLLOWING)) {
            final SpatialIndexEntry spatialIndexEntry = SpatialIndexEntry.readFromFile(randomAccessFile);
            rootNode.indexEntries.add(spatialIndexEntry);
        } else if (!Arrays.equals(followingByte, RTreeBuilder.MAGIC_CHILD_NODE_NOT_EXISTING)) {
            throw new IllegalArgumentException("Unknown node type following: " + followingByte);
        }
    }
}
Also used : SpatialIndexEntry(org.bboxdb.storage.sstable.spatialindex.SpatialIndexEntry)

Aggregations

SpatialIndexEntry (org.bboxdb.storage.sstable.spatialindex.SpatialIndexEntry)27 Test (org.junit.Test)14 SpatialIndexBuilder (org.bboxdb.storage.sstable.spatialindex.SpatialIndexBuilder)13 RTreeBuilder (org.bboxdb.storage.sstable.spatialindex.rtree.RTreeBuilder)12 BoundingBox (org.bboxdb.commons.math.BoundingBox)8 RandomAccessFile (java.io.RandomAccessFile)6 ArrayList (java.util.ArrayList)6 StorageManagerException (org.bboxdb.storage.StorageManagerException)6 File (java.io.File)5 AbstractRTreeReader (org.bboxdb.storage.sstable.spatialindex.rtree.AbstractRTreeReader)4 List (java.util.List)3 Random (java.util.Random)3 Collectors (java.util.stream.Collectors)3 IOException (java.io.IOException)2 Iterator (java.util.Iterator)2 SpatialIndexReader (org.bboxdb.storage.sstable.spatialindex.SpatialIndexReader)2 Assert (org.junit.Assert)2 ByteBuffer (java.nio.ByteBuffer)1 MappedByteBuffer (java.nio.MappedByteBuffer)1 FileChannel (java.nio.channels.FileChannel)1