Search in sources :

Example 86 with BoundingBox

use of org.bboxdb.commons.math.BoundingBox in project bboxdb by jnidzwetzki.

the class TestTupleBuilder method testGeoJsonTupleBuilder.

/**
 * Test the geo json tuple builder
 */
@Test
public void testGeoJsonTupleBuilder() {
    final TupleBuilder tupleBuilder = TupleBuilderFactory.getBuilderForFormat(TupleBuilderFactory.Name.GEOJSON);
    final Tuple tuple = tupleBuilder.buildTuple("1", GEO_JSON_LINE);
    Assert.assertTrue(tuple != null);
    Assert.assertEquals(Integer.toString(1), tuple.getKey());
    final BoundingBox expectedBox = new BoundingBox(52.4688608, 52.4688608, 13.3327994, 13.3327994);
    Assert.assertEquals(expectedBox, tuple.getBoundingBox());
}
Also used : TupleBuilder(org.bboxdb.tools.converter.tuple.TupleBuilder) BoundingBox(org.bboxdb.commons.math.BoundingBox) Tuple(org.bboxdb.storage.entity.Tuple) Test(org.junit.Test)

Example 87 with BoundingBox

use of org.bboxdb.commons.math.BoundingBox in project bboxdb by jnidzwetzki.

the class TPCHOrderPointBuilder method buildTuple.

@Override
public // 1|738001|O|215050.73|1996-01-02|5-LOW|Clerk#000019011|0|nstructions sleep furiously among |
Tuple buildTuple(final String keyData, final String valueData) {
    final String[] data = valueData.split("\\|");
    try {
        final Date orderDate = dateParser.parse(data[4]);
        final double orderDateTime = (double) orderDate.getTime();
        final BoundingBox boundingBox = new BoundingBox(orderDateTime, orderDateTime);
        final Tuple tuple = new Tuple(keyData, boundingBox, valueData.getBytes());
        return tuple;
    } catch (ParseException e) {
        logger.error("Unabe to parse: ", e);
        return null;
    }
}
Also used : BoundingBox(org.bboxdb.commons.math.BoundingBox) ParseException(java.text.ParseException) Date(java.util.Date) Tuple(org.bboxdb.storage.entity.Tuple)

Example 88 with BoundingBox

use of org.bboxdb.commons.math.BoundingBox in project bboxdb by jnidzwetzki.

the class RTreeMemoryReader method readDirectoryNode.

/**
 * Read the directory node
 * @param randomAccessFile
 * @param parent
 * @return
 * @throws IOException
 */
protected RTreeDirectoryNode readDirectoryNode(final RandomAccessFile randomAccessFile, final RTreeDirectoryNode parent) throws IOException {
    // Node data
    final int nodeId = DataEncoderHelper.readIntFromDataInput(randomAccessFile);
    final RTreeDirectoryNode node = new RTreeDirectoryNode(nodeId);
    node.setParentNode(parent);
    if (parent != null) {
        parent.directoryNodeChilds.add(node);
    }
    // Make this to the new root node
    if (rootNode == null) {
        rootNode = node;
    }
    // Bounding box data
    final int boundingBoxLength = DataEncoderHelper.readIntFromDataInput(randomAccessFile);
    final byte[] boundingBoxBytes = new byte[boundingBoxLength];
    randomAccessFile.readFully(boundingBoxBytes, 0, boundingBoxBytes.length);
    final BoundingBox boundingBox = BoundingBox.fromByteArray(boundingBoxBytes);
    node.setBoundingBox(boundingBox);
    // Read entry entries
    readEntryNodes(randomAccessFile);
    // Read directory nodes
    readDirectoryNodes(randomAccessFile, node);
    return node;
}
Also used : BoundingBox(org.bboxdb.commons.math.BoundingBox)

Example 89 with BoundingBox

use of org.bboxdb.commons.math.BoundingBox 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 90 with BoundingBox

use of org.bboxdb.commons.math.BoundingBox in project bboxdb by jnidzwetzki.

the class SpatialIndexEntry method readFromByteBuffer.

/**
 * Read the node from a byte buffer
 * @param inputStream
 * @return
 * @throws IOException
 */
public static SpatialIndexEntry readFromByteBuffer(final ByteBuffer buffer) throws IOException {
    final byte[] keyBytes = new byte[DataEncoderHelper.INT_BYTES];
    final byte[] boxLengthBytes = new byte[DataEncoderHelper.INT_BYTES];
    buffer.get(keyBytes, 0, keyBytes.length);
    buffer.get(boxLengthBytes, 0, boxLengthBytes.length);
    final int key = DataEncoderHelper.readIntFromByte(keyBytes);
    final int bboxLength = DataEncoderHelper.readIntFromByte(boxLengthBytes);
    final byte[] bboxBytes = new byte[bboxLength];
    buffer.get(bboxBytes, 0, bboxBytes.length);
    final BoundingBox boundingBox = BoundingBox.fromByteArray(bboxBytes);
    return new SpatialIndexEntry(boundingBox, key);
}
Also used : BoundingBox(org.bboxdb.commons.math.BoundingBox)

Aggregations

BoundingBox (org.bboxdb.commons.math.BoundingBox)194 Test (org.junit.Test)113 Tuple (org.bboxdb.storage.entity.Tuple)61 ArrayList (java.util.ArrayList)25 JoinedTuple (org.bboxdb.storage.entity.JoinedTuple)24 DeletedTuple (org.bboxdb.storage.entity.DeletedTuple)23 BBoxDBException (org.bboxdb.misc.BBoxDBException)22 DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)20 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)16 List (java.util.List)15 DistributionRegionIdMapper (org.bboxdb.distribution.region.DistributionRegionIdMapper)13 ZookeeperException (org.bboxdb.distribution.zookeeper.ZookeeperException)13 TupleStoreConfiguration (org.bboxdb.storage.entity.TupleStoreConfiguration)13 TupleListFuture (org.bboxdb.network.client.future.TupleListFuture)12 ZookeeperNotFoundException (org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException)11 EmptyResultFuture (org.bboxdb.network.client.future.EmptyResultFuture)11 IOException (java.io.IOException)10 Date (java.util.Date)10 DoubleInterval (org.bboxdb.commons.math.DoubleInterval)10 SpatialIndexReadOperator (org.bboxdb.storage.queryprocessor.operator.SpatialIndexReadOperator)10