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(" ", ""));
}
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);
}
}
}
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;
}
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());
}
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());
*/
}
Aggregations