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