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);
}
}
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);
}
}
};
}
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;
}
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);
}
}
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);
}
Aggregations