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