Search in sources :

Example 11 with SpatialIndexEntry

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

the class RTreeMMFReader method getEntriesForRegion.

@Override
public synchronized List<SpatialIndexEntry> getEntriesForRegion(final BoundingBox boundingBox) throws StorageManagerException {
    final List<SpatialIndexEntry> resultList = new ArrayList<>();
    final Queue<Integer> readTasks = new LinkedTransferQueue<>();
    readTasks.add(firstNodePos);
    try {
        while (!readTasks.isEmpty()) {
            final int position = readTasks.remove();
            memory.position(position);
            final DirectoryNode directoryNode = new DirectoryNode();
            directoryNode.initFromByteBuffer(memory, maxNodeSize);
            if (directoryNode.getBoundingBox().overlaps(boundingBox)) {
                readTasks.addAll(directoryNode.getChildNodes());
                final List<SpatialIndexEntry> foundEntries = directoryNode.getIndexEntries().stream().filter(e -> e.getBoundingBox().overlaps(boundingBox)).collect(Collectors.toList());
                resultList.addAll(foundEntries);
            }
        }
        return resultList;
    } catch (IOException e) {
        throw new StorageManagerException(e);
    }
}
Also used : RandomAccessFile(java.io.RandomAccessFile) LinkedTransferQueue(java.util.concurrent.LinkedTransferQueue) Logger(org.slf4j.Logger) DataEncoderHelper(org.bboxdb.commons.io.DataEncoderHelper) UnsafeMemoryHelper(org.bboxdb.commons.io.UnsafeMemoryHelper) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) BoundingBox(org.bboxdb.commons.math.BoundingBox) ArrayList(java.util.ArrayList) Const(org.bboxdb.misc.Const) AbstractRTreeReader(org.bboxdb.storage.sstable.spatialindex.rtree.AbstractRTreeReader) List(java.util.List) Queue(java.util.Queue) StorageManagerException(org.bboxdb.storage.StorageManagerException) FileChannel(java.nio.channels.FileChannel) SpatialIndexEntry(org.bboxdb.storage.sstable.spatialindex.SpatialIndexEntry) MappedByteBuffer(java.nio.MappedByteBuffer) ArrayList(java.util.ArrayList) IOException(java.io.IOException) StorageManagerException(org.bboxdb.storage.StorageManagerException) SpatialIndexEntry(org.bboxdb.storage.sstable.spatialindex.SpatialIndexEntry) LinkedTransferQueue(java.util.concurrent.LinkedTransferQueue)

Example 12 with SpatialIndexEntry

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

the class SSTableFacade method getAllTuplesInBoundingBox.

@Override
public Iterator<Tuple> getAllTuplesInBoundingBox(final BoundingBox boundingBox) {
    assert (usage.get() > 0);
    List<SpatialIndexEntry> entries;
    try {
        entries = spatialIndex.getEntriesForRegion(boundingBox);
    } catch (StorageManagerException e) {
        throw new RuntimeException(e);
    }
    final Iterator<SpatialIndexEntry> entryIterator = entries.iterator();
    return new Iterator<Tuple>() {

        @Override
        public boolean hasNext() {
            return entryIterator.hasNext();
        }

        @Override
        public Tuple next() {
            final SpatialIndexEntry entry = entryIterator.next();
            final int tuplePosition = entry.getValue();
            try {
                return ssTableReader.getTupleAtPosition(tuplePosition);
            } catch (StorageManagerException e) {
                throw new RuntimeException(e);
            }
        }
    };
}
Also used : Iterator(java.util.Iterator) StorageManagerException(org.bboxdb.storage.StorageManagerException) SpatialIndexEntry(org.bboxdb.storage.sstable.spatialindex.SpatialIndexEntry)

Example 13 with SpatialIndexEntry

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

the class RTreeTestHelper method generateRandomTupleList.

/**
 * Generate some random tuples
 * @return
 */
public static List<SpatialIndexEntry> generateRandomTupleList(final int dimensions) {
    final List<SpatialIndexEntry> entryList = new ArrayList<SpatialIndexEntry>();
    final Random random = new Random();
    for (int i = 0; i < 5000; i++) {
        final double[] boundingBoxData = new double[dimensions * 2];
        for (int d = 0; d < dimensions; d++) {
            final double begin = random.nextInt() % 1000;
            final double extent = Math.abs(random.nextInt() % 1000);
            // Start coordinate
            boundingBoxData[2 * d] = begin;
            // End coordinate
            boundingBoxData[2 * d + 1] = begin + extent;
        }
        final SpatialIndexEntry entry = new SpatialIndexEntry(new BoundingBox(boundingBoxData), i);
        entryList.add(entry);
    }
    return entryList;
}
Also used : Random(java.util.Random) BoundingBox(org.bboxdb.commons.math.BoundingBox) ArrayList(java.util.ArrayList) SpatialIndexEntry(org.bboxdb.storage.sstable.spatialindex.SpatialIndexEntry)

Example 14 with SpatialIndexEntry

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

the class RTreeTestHelper method queryIndex.

/**
 * Test the query
 *
 * @param entries
 * @param index
 */
public static void queryIndex(final List<SpatialIndexEntry> entries, final SpatialIndexBuilder index) {
    for (final SpatialIndexEntry entry : entries) {
        final List<? extends SpatialIndexEntry> resultList = index.getEntriesForRegion(entry.getBoundingBox());
        Assert.assertTrue(resultList.size() >= 1);
        final List<Integer> keyResult = resultList.stream().map(e -> e.getValue()).filter(k -> k.equals(entry.getValue())).collect(Collectors.toList());
        Assert.assertTrue("Searching for: " + entry, keyResult.size() == 1);
    }
}
Also used : List(java.util.List) SpatialIndexReader(org.bboxdb.storage.sstable.spatialindex.SpatialIndexReader) Random(java.util.Random) StorageManagerException(org.bboxdb.storage.StorageManagerException) Assert(org.junit.Assert) Collectors(java.util.stream.Collectors) BoundingBox(org.bboxdb.commons.math.BoundingBox) SpatialIndexBuilder(org.bboxdb.storage.sstable.spatialindex.SpatialIndexBuilder) SpatialIndexEntry(org.bboxdb.storage.sstable.spatialindex.SpatialIndexEntry) ArrayList(java.util.ArrayList) SpatialIndexEntry(org.bboxdb.storage.sstable.spatialindex.SpatialIndexEntry)

Example 15 with SpatialIndexEntry

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

the class TestRTreeIndex method testBoxQuery4d.

/**
 * Test to query the index
 */
@Test(timeout = 60000)
public void testBoxQuery4d() {
    final List<SpatialIndexEntry> tupleList = RTreeTestHelper.generateRandomTupleList(4);
    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)

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