Search in sources :

Example 51 with BoundingBox

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

the class QuadtreeSpacePartitioner method createBoundingBoxes.

/**
 * Create a list with bounding boxes
 * @param box
 * @return
 */
private List<BoundingBox> createBoundingBoxes(final BoundingBox box) {
    final List<DoubleInterval> list1 = new ArrayList<>();
    final List<DoubleInterval> list2 = new ArrayList<>();
    generateIntervalLists(box, list1, list2);
    List<List<DoubleInterval>> intervalCombinations = ListHelper.getCombinations(list1, list2);
    final List<BoundingBox> childBoxes = new ArrayList<>();
    for (List<DoubleInterval> boxAsIntervals : intervalCombinations) {
        childBoxes.add(new BoundingBox(boxAsIntervals));
    }
    return childBoxes;
}
Also used : BoundingBox(org.bboxdb.commons.math.BoundingBox) ArrayList(java.util.ArrayList) DoubleInterval(org.bboxdb.commons.math.DoubleInterval) ArrayList(java.util.ArrayList) List(java.util.List)

Example 52 with BoundingBox

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

the class BBoxDBClientExample method main.

/**
 * Connect to the BBoxDB Server at localhost and insert some tuples
 *
 * @param args
 * @throws ExecutionException
 * @throws InterruptedException
 * @throws BBoxDBException
 */
public static void main(String[] args) throws InterruptedException, ExecutionException, BBoxDBException {
    // A 2 dimensional table (member of distribution group 'mygroup3') with the name 'testdata'
    final int dimensions = 2;
    final String distributionGroup = "mygroup3";
    final String mytable = distributionGroup + "_testdata";
    // The name of the cluster
    final String clustername = "mycluster";
    // The zookeeper connect points
    final List<String> connectPoints = Arrays.asList("localhost:2181");
    // Connect to the server
    final BBoxDB bboxdbClient = new BBoxDBCluster(connectPoints, clustername);
    bboxdbClient.connect();
    // Check the connection state
    if (!bboxdbClient.isConnected()) {
        System.out.println("Error while connecting to the BBoxDB cluster");
        System.exit(-1);
    }
    // Clean the old content of the distribution group
    final EmptyResultFuture deleteGroupResult = bboxdbClient.deleteDistributionGroup(distributionGroup);
    deleteGroupResult.waitForAll();
    if (deleteGroupResult.isFailed()) {
        System.err.println("Unable to delete distribution group: " + distributionGroup);
        System.err.println(deleteGroupResult.getAllMessages());
        System.exit(-1);
    }
    // Create a new distribution group
    final DistributionGroupConfiguration configuration = DistributionGroupConfigurationBuilder.create(dimensions).withReplicationFactor((short) 3).build();
    final EmptyResultFuture createGroupResult = bboxdbClient.createDistributionGroup(distributionGroup, configuration);
    createGroupResult.waitForAll();
    if (createGroupResult.isFailed()) {
        System.err.println("Unable to create distribution group: " + distributionGroup);
        System.err.println(createGroupResult.getAllMessages());
        System.exit(-1);
    }
    // Create the table
    final TupleStoreConfiguration tableConfig = TupleStoreConfigurationBuilder.create().allowDuplicates(false).build();
    final EmptyResultFuture createTableResult = bboxdbClient.createTable(mytable, tableConfig);
    createTableResult.waitForAll();
    if (createTableResult.isFailed()) {
        System.err.println("Unable to create table group: " + mytable);
        System.err.println(createTableResult.getAllMessages());
        System.exit(-1);
    }
    // Insert two new tuples
    final Tuple tuple1 = new Tuple("key1", new BoundingBox(0d, 5d, 0d, 1d), "mydata1".getBytes());
    final EmptyResultFuture insertResult1 = bboxdbClient.insertTuple(mytable, tuple1);
    final Tuple tuple2 = new Tuple("key2", new BoundingBox(-1d, 2d, -1d, 2d), "mydata2".getBytes());
    final EmptyResultFuture insertResult2 = bboxdbClient.insertTuple(mytable, tuple2);
    // Wait for the insert operations to complete
    insertResult1.waitForAll();
    insertResult2.waitForAll();
    if (insertResult1.isFailed()) {
        System.err.println("Unable to insert tuple: " + insertResult1.getAllMessages());
        System.exit(-1);
    }
    if (insertResult2.isFailed()) {
        System.err.println("Unable to insert tuple: " + insertResult2.getAllMessages());
        System.exit(-1);
    }
    // Query by key
    final TupleListFuture resultFuture1 = bboxdbClient.queryKey(mytable, "key");
    // We got a future object, the search is performed asynchronous
    // Wait for the result
    resultFuture1.waitForAll();
    if (resultFuture1.isFailed()) {
        System.err.println("NetworkOperationFuture is failed: " + resultFuture1.getAllMessages());
        System.exit(-1);
    }
    // Output all tuples
    for (final Tuple tuple : resultFuture1) {
        System.out.println(tuple);
    }
    // Query by bounding box
    final TupleListFuture resultFuture2 = bboxdbClient.queryBoundingBox(mytable, new BoundingBox(-0.5d, 1d, -0.5d, 1d));
    // Again, we got a future object, the search is performed asynchronous
    resultFuture2.waitForAll();
    if (resultFuture2.isFailed()) {
        System.err.println("NetworkOperationFuture is failed: " + resultFuture2.getAllMessages());
        System.exit(-1);
    }
    // Output all tuples
    for (final Tuple tuple : resultFuture2) {
        System.out.println("Tuple: " + tuple);
    }
    bboxdbClient.disconnect();
}
Also used : BBoxDB(org.bboxdb.network.client.BBoxDB) TupleStoreConfiguration(org.bboxdb.storage.entity.TupleStoreConfiguration) BoundingBox(org.bboxdb.commons.math.BoundingBox) TupleListFuture(org.bboxdb.network.client.future.TupleListFuture) BBoxDBCluster(org.bboxdb.network.client.BBoxDBCluster) DistributionGroupConfiguration(org.bboxdb.storage.entity.DistributionGroupConfiguration) Tuple(org.bboxdb.storage.entity.Tuple) EmptyResultFuture(org.bboxdb.network.client.future.EmptyResultFuture)

Example 53 with BoundingBox

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

the class ExperimentStatistics method getSplit.

/**
 * Take a certain number of samples and generate a split position
 * @param sampleSize
 * @param numberOfElements
 * @return
 * @throws IOException
 * @throws ClassNotFoundException
 */
protected double getSplit(final float sampleSize, final long numberOfElements) throws ClassNotFoundException, IOException {
    final Set<Long> takenSamples = new HashSet<>();
    final List<BoundingBox> samples = new ArrayList<>();
    final TupleBuilder tupleBuilder = TupleBuilderFactory.getBuilderForFormat(format);
    try (final RandomAccessFile randomAccessFile = new RandomAccessFile(filename, "r")) {
        while (takenSamples.size() < sampleSize) {
            final long sampleId = ThreadLocalRandom.current().nextLong(numberOfElements);
            if (takenSamples.contains(sampleId)) {
                continue;
            }
            // Line 1 is sample 0 in the file
            final long pos = fli.locateLine(sampleId + 1);
            randomAccessFile.seek(pos);
            final String line = randomAccessFile.readLine();
            final Tuple tuple = tupleBuilder.buildTuple(Long.toString(sampleId), line);
            // E.g. Table header
            if (tuple == null) {
                continue;
            }
            final BoundingBox boundingBox = tuple.getBoundingBox();
            samples.add(boundingBox);
            tupleDimension = boundingBox.getDimension();
            takenSamples.add(sampleId);
        }
    }
    samples.sort((b1, b2) -> Double.compare(b1.getCoordinateLow(0), b2.getCoordinateLow(0)));
    return samples.get(samples.size() / 2).getCoordinateLow(0);
}
Also used : TupleBuilder(org.bboxdb.tools.converter.tuple.TupleBuilder) RandomAccessFile(java.io.RandomAccessFile) BoundingBox(org.bboxdb.commons.math.BoundingBox) ArrayList(java.util.ArrayList) Tuple(org.bboxdb.storage.entity.Tuple) HashSet(java.util.HashSet)

Example 54 with BoundingBox

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

the class TestBoundingBoxQuery method run.

@Override
public void run() {
    System.out.format("# Reading %s%n", filename);
    final BoundingBox boundingBox = ExperimentHelper.determineBoundingBox(filename, format);
    System.out.println("Connecting to BBoxDB cluster");
    final BBoxDB bboxDBConnection = new BBoxDBCluster(endpoint, cluster);
    if (!bboxDBConnection.connect()) {
        System.err.println("Unable to connect to the BBoxDB cluster, exiting");
        System.exit(-1);
    }
    final List<Double> experimentSize = Arrays.asList(0.001, 0.01, 0.1, 1.0);
    experimentSize.forEach(e -> runExperiment(e, boundingBox, bboxDBConnection));
    pendingFutures.shutdown();
}
Also used : BBoxDB(org.bboxdb.network.client.BBoxDB) BoundingBox(org.bboxdb.commons.math.BoundingBox) BBoxDBCluster(org.bboxdb.network.client.BBoxDBCluster)

Example 55 with BoundingBox

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

the class TestFixedGrid method run.

@Override
public void run() {
    System.out.format("Reading %s%n", filename);
    final BoundingBox boundingBox = ExperimentHelper.determineBoundingBox(filename, format);
    for (final Integer cellsPerDimension : cellSizes) {
        System.out.println("Cells per Dimension: " + cellsPerDimension);
        final CellGrid cellGrid = CellGrid.buildWithFixedAmountOfCells(boundingBox, cellsPerDimension);
        runExperiment(cellGrid);
    }
}
Also used : BoundingBox(org.bboxdb.commons.math.BoundingBox) CellGrid(org.bboxdb.storage.entity.CellGrid)

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