Search in sources :

Example 1 with ByteArray

use of org.locationtech.geowave.core.index.ByteArray in project datawave by NationalSecurityAgency.

the class GeoWaveUtilsTest method createByteArrayRangeTest.

@Test
public void createByteArrayRangeTest() {
    // String, String
    ByteArrayRange byteArrayRange = GeoWaveUtils.createByteArrayRange("0100", "0103");
    Assert.assertEquals("0100", new ByteArray(byteArrayRange.getStart()).getHexString().replace(" ", ""));
    Assert.assertEquals("0103", new ByteArray(byteArrayRange.getEnd()).getHexString().replace(" ", ""));
    // int, long, long
    byteArrayRange = GeoWaveUtils.createByteArrayRange(4, 0, 20);
    Assert.assertEquals("0400", new ByteArray(byteArrayRange.getStart()).getHexString().replace(" ", ""));
    Assert.assertEquals("0414", new ByteArray(byteArrayRange.getEnd()).getHexString().replace(" ", ""));
}
Also used : ByteArray(org.locationtech.geowave.core.index.ByteArray) ByteArrayRange(org.locationtech.geowave.core.index.ByteArrayRange) Test(org.junit.Test)

Example 2 with ByteArray

use of org.locationtech.geowave.core.index.ByteArray in project geowave by locationtech.

the class SpatialBinningTypeTest method testGeometry.

private void testGeometry(final Geometry geom, final Function<Geometry, Double> measurementFunction) {
    final double originalMeasurement = measurementFunction.apply(geom);
    for (final SpatialBinningType type : SpatialBinningType.values()) {
        final double errorThreshold = TYPE_TO_ERROR_THRESHOLD.get(type);
        for (int precision = 1; precision < 7; precision++) {
            final int finalPrecision = type.equals(SpatialBinningType.S2) ? precision * 2 : precision;
            final ByteArray[] bins = type.getSpatialBins(geom, finalPrecision);
            double weight = 0;
            final List<Geometry> cellGeoms = new ArrayList<>();
            for (final ByteArray bin : bins) {
                final Geometry binGeom = type.getBinGeometry(bin, finalPrecision);
                cellGeoms.add(binGeom.intersection(geom));
                final double intersectionMeasurement = measurementFunction.apply(binGeom.intersection(geom));
                final double fieldWeight = intersectionMeasurement / originalMeasurement;
                weight += fieldWeight;
            }
            // cumulative weight should be 1, within the threshold of error
            Assert.assertEquals(String.format("Combined weight is off by more than threshold for type '%s' with precision '%d' for geometry '%s'", type, finalPrecision, geom), 1, weight, errorThreshold);
            // the union of the geometries should be within the within the threshold of error of the
            // original measurement
            Assert.assertEquals(String.format("Measurement on geometric union is off by more than threshold for type '%s' with precision '%d' for geometry '%s'", type, finalPrecision, geom), 1, measurementFunction.apply(GeometryUtils.GEOMETRY_FACTORY.buildGeometry(cellGeoms)) / originalMeasurement, errorThreshold);
        }
    }
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) ArrayList(java.util.ArrayList) ByteArray(org.locationtech.geowave.core.index.ByteArray)

Example 3 with ByteArray

use of org.locationtech.geowave.core.index.ByteArray in project geowave by locationtech.

the class SpatialFieldValueBinningStrategy method getWeight.

@Override
public <T> double getWeight(final ByteArray bin, final DataTypeAdapter<T> type, final T entry, final GeoWaveRow... rows) {
    if (ComplexGeometryBinningOption.USE_FULL_GEOMETRY_SCALE_BY_OVERLAP.equals(complexGeometry)) {
        // only compute if its intended to scale by percent overlap
        final ByteBuffer buffer = ByteBuffer.wrap(bin.getBytes());
        double weight = 1;
        int i = 0;
        while (buffer.remaining() > 0) {
            final byte[] binId = new byte[this.type.getBinByteLength(precision)];
            buffer.get(binId);
            final Geometry binGeom = this.type.getBinGeometry(new ByteArray(binId), precision);
            final Object value = type.getFieldValue(entry, fields.get(i++));
            if (value instanceof Geometry) {
                // This approach could be fairly expensive, but is accurate and general-purpose
                // take the intersection of the field geometry with the bin geometry and take the area
                // weight is the ratio of the intersection area to the entire field geometry area
                final double area = ((Geometry) value).getArea();
                if (area > 0) {
                    if (binGeom.intersects((Geometry) value)) {
                        final double intersectionArea = binGeom.intersection((Geometry) value).getArea();
                        final double fieldWeight = intersectionArea / ((Geometry) value).getArea();
                        weight *= fieldWeight;
                    }
                } else {
                    final double length = ((Geometry) value).getLength();
                    if (length > 0) {
                        final double intersectionLength = binGeom.intersection((Geometry) value).getLength();
                        final double fieldWeight = intersectionLength / ((Geometry) value).getLength();
                        weight *= fieldWeight;
                    }
                // if it has no area and no length it must be point data and not very applicable for
                // scaling
                }
            }
        }
        return weight;
    }
    return 1;
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) ByteArray(org.locationtech.geowave.core.index.ByteArray) ByteBuffer(java.nio.ByteBuffer)

Example 4 with ByteArray

use of org.locationtech.geowave.core.index.ByteArray in project geowave by locationtech.

the class DBScanMapReduceTest method test8With4.

@Test
public void test8With4() throws IOException {
    final Random r = new Random(3434);
    for (int i = 0; i < 8; i++) {
        final SimpleFeature feature = createTestFeature("f" + i, new Coordinate(round(30.0 + (r.nextGaussian() * 0.00001)), round(30.0 + (r.nextGaussian() * 0.00001))));
        mapDriver.addInput(new GeoWaveInputKey(adapterId, new ByteArray(feature.getID())), feature);
    }
    final List<Pair<PartitionDataWritable, AdapterWithObjectWritable>> mapperResults = mapDriver.run();
    final List<Pair<PartitionDataWritable, List<AdapterWithObjectWritable>>> partitions = getReducerDataFromMapperInput(mapperResults);
    reduceDriver.addAll(partitions);
    reduceDriver.getConfiguration().setInt(GeoWaveConfiguratorBase.enumToConfKey(NNMapReduce.class, ClusteringParameters.Clustering.MINIMUM_SIZE), 4);
    final List<Pair<GeoWaveInputKey, ObjectWritable>> reduceResults = reduceDriver.run();
    assertEquals(1, reduceResults.size());
}
Also used : AdapterWithObjectWritable(org.locationtech.geowave.analytic.AdapterWithObjectWritable) Random(java.util.Random) Coordinate(org.locationtech.jts.geom.Coordinate) ByteArray(org.locationtech.geowave.core.index.ByteArray) GeoWaveInputKey(org.locationtech.geowave.mapreduce.input.GeoWaveInputKey) SimpleFeature(org.opengis.feature.simple.SimpleFeature) NNMapReduce(org.locationtech.geowave.analytic.mapreduce.nn.NNMapReduce) Pair(org.apache.hadoop.mrunit.types.Pair) Test(org.junit.Test)

Example 5 with ByteArray

use of org.locationtech.geowave.core.index.ByteArray in project geowave by locationtech.

the class DBScanMapReduceTest method testReducer.

@Test
public void testReducer() throws IOException {
    final SimpleFeature feature1 = createTestFeature("f1", new Coordinate(30.0, 30.00000001));
    final SimpleFeature feature2 = createTestFeature("f2", new Coordinate(50.001, 50.001));
    final SimpleFeature feature3 = createTestFeature("f3", new Coordinate(30.00000001, 30.00000001));
    final SimpleFeature feature4 = createTestFeature("f4", new Coordinate(50.0011, 50.00105));
    final SimpleFeature feature5 = createTestFeature("f5", new Coordinate(50.00112, 50.00111));
    final SimpleFeature feature6 = createTestFeature("f6", new Coordinate(30.00000001, 30.00000002));
    final SimpleFeature feature7 = createTestFeature("f7", new Coordinate(50.00113, 50.00114));
    final SimpleFeature feature8 = createTestFeature("f8", new Coordinate(40.00000001, 40.000000002));
    mapDriver.addInput(new GeoWaveInputKey(adapterId, new ByteArray(feature1.getID())), feature1);
    mapDriver.addInput(new GeoWaveInputKey(adapterId, new ByteArray(feature2.getID())), feature2);
    mapDriver.addInput(new GeoWaveInputKey(adapterId, new ByteArray(feature3.getID())), feature3);
    mapDriver.addInput(new GeoWaveInputKey(adapterId, new ByteArray(feature4.getID())), feature4);
    mapDriver.addInput(new GeoWaveInputKey(adapterId, new ByteArray(feature5.getID())), feature5);
    mapDriver.addInput(new GeoWaveInputKey(adapterId, new ByteArray(feature6.getID())), feature6);
    mapDriver.addInput(new GeoWaveInputKey(adapterId, new ByteArray(feature7.getID())), feature7);
    mapDriver.addInput(new GeoWaveInputKey(adapterId, new ByteArray(feature8.getID())), feature8);
    final List<Pair<PartitionDataWritable, AdapterWithObjectWritable>> mapperResults = mapDriver.run();
    assertNotNull(getPartitionDataFor(mapperResults, feature1.getID(), true));
    assertNotNull(getPartitionDataFor(mapperResults, feature2.getID(), true));
    assertNotNull(getPartitionDataFor(mapperResults, feature2.getID(), true));
    assertNotNull(getPartitionDataFor(mapperResults, feature3.getID(), true));
    assertEquals(getPartitionDataFor(mapperResults, feature1.getID(), true).getCompositeKey(), getPartitionDataFor(mapperResults, feature3.getID(), true).getCompositeKey());
    assertEquals(getPartitionDataFor(mapperResults, feature6.getID(), true).getCompositeKey(), getPartitionDataFor(mapperResults, feature3.getID(), true).getCompositeKey());
    assertEquals(getPartitionDataFor(mapperResults, feature5.getID(), true).getCompositeKey(), getPartitionDataFor(mapperResults, feature7.getID(), true).getCompositeKey());
    assertEquals(getPartitionDataFor(mapperResults, feature5.getID(), true).getCompositeKey(), getPartitionDataFor(mapperResults, feature4.getID(), true).getCompositeKey());
    final List<Pair<PartitionDataWritable, List<AdapterWithObjectWritable>>> partitions = getReducerDataFromMapperInput(mapperResults);
    reduceDriver.addAll(partitions);
    reduceDriver.getConfiguration().setInt(GeoWaveConfiguratorBase.enumToConfKey(NNMapReduce.class, ClusteringParameters.Clustering.MINIMUM_SIZE), 2);
    final List<Pair<GeoWaveInputKey, ObjectWritable>> reduceResults = reduceDriver.run();
    assertEquals(2, reduceResults.size());
/*
     * assertEquals( feature3.getID(), find( reduceResults, feature1.getID()).toString());
     *
     * assertEquals( feature1.getID(), find( reduceResults, feature3.getID()).toString());
     *
     * assertEquals( feature4.getID(), find( reduceResults, feature2.getID()).toString());
     *
     * assertEquals( feature2.getID(), find( reduceResults, feature4.getID()).toString());
     */
}
Also used : AdapterWithObjectWritable(org.locationtech.geowave.analytic.AdapterWithObjectWritable) Coordinate(org.locationtech.jts.geom.Coordinate) ByteArray(org.locationtech.geowave.core.index.ByteArray) GeoWaveInputKey(org.locationtech.geowave.mapreduce.input.GeoWaveInputKey) SimpleFeature(org.opengis.feature.simple.SimpleFeature) NNMapReduce(org.locationtech.geowave.analytic.mapreduce.nn.NNMapReduce) Pair(org.apache.hadoop.mrunit.types.Pair) Test(org.junit.Test)

Aggregations

ByteArray (org.locationtech.geowave.core.index.ByteArray)114 HashMap (java.util.HashMap)26 List (java.util.List)25 Test (org.junit.Test)25 ByteBuffer (java.nio.ByteBuffer)22 ArrayList (java.util.ArrayList)22 Map (java.util.Map)20 Arrays (java.util.Arrays)19 GeoWaveRow (org.locationtech.geowave.core.store.entities.GeoWaveRow)19 SimpleFeature (org.opengis.feature.simple.SimpleFeature)17 IOException (java.io.IOException)16 Pair (org.apache.commons.lang3.tuple.Pair)16 Coordinate (org.locationtech.jts.geom.Coordinate)16 Set (java.util.Set)15 HashSet (java.util.HashSet)13 ByteArrayRange (org.locationtech.geowave.core.index.ByteArrayRange)13 Collectors (java.util.stream.Collectors)12 CloseableIterator (org.locationtech.geowave.core.store.CloseableIterator)12 Index (org.locationtech.geowave.core.store.api.Index)12 GeoWaveInputKey (org.locationtech.geowave.mapreduce.input.GeoWaveInputKey)11