Search in sources :

Example 1 with BasicDimensionDefinition

use of org.locationtech.geowave.core.index.dimension.BasicDimensionDefinition in project geowave by locationtech.

the class PrimitiveHilbertSFCTest method testGetId48BitsPerDimension.

@Test
public void testGetId48BitsPerDimension() {
    final SFCDimensionDefinition[] sfcDimensions = new SFCDimensionDefinition[20];
    final List<Integer> bitsPerDimension = new ArrayList<>();
    for (int d = 0; d < sfcDimensions.length; d++) {
        final int bitsOfPrecision = 48;
        sfcDimensions[d] = new SFCDimensionDefinition(new BasicDimensionDefinition(0, 1), bitsOfPrecision);
        bitsPerDimension.add(bitsOfPrecision);
    }
    final CompactHilbertCurve compactHilbertCurve = new CompactHilbertCurve(new MultiDimensionalSpec(bitsPerDimension));
    final PrimitiveHilbertSFCOperations testOperations = new PrimitiveHilbertSFCOperations();
    // assume the unbounded SFC is the true results, regardless they should
    // both produce the same results
    final UnboundedHilbertSFCOperations expectedResultOperations = new UnboundedHilbertSFCOperations();
    testOperations.init(sfcDimensions);
    expectedResultOperations.init(sfcDimensions);
    final Double[] testValues1 = new Double[20];
    Arrays.fill(testValues1, Double.MIN_VALUE);
    final Double[] testValues2 = new Double[20];
    Arrays.fill(testValues2, 0d);
    final Double[] testValues3 = new Double[20];
    Arrays.fill(testValues3, 1d);
    final Double[] testValues4 = new Double[] { 0.2354561024897435868943753568436598645436, 0.921354693742875894657658678436546547657867869789780790890789356895549054690704378590896, 0.84754363905364783265784365843, 0.7896543436756437856046562640234, 0.3216819204957436913249032618969653, 0.327219038596576238101046563945864390685476054, 0.12189368934632894658343655436546754754665875784375308678932689368432, 0.000327489326493291328326493457437584375043, 0.3486563289543, 0.96896758943758, 0.98999897899879789789789789789789789789689, 0.1275785478325478265925864359, 0.124334325346554654, 0.1234565, 0.9876543, 0.76634328932, 0.64352843, 0.5432342321, 0.457686789, 0.2046543435 };
    Assert.assertArrayEquals(expectedResultOperations.convertToHilbert(testValues1, compactHilbertCurve, sfcDimensions), testOperations.convertToHilbert(testValues1, compactHilbertCurve, sfcDimensions));
    Assert.assertArrayEquals(expectedResultOperations.convertToHilbert(testValues2, compactHilbertCurve, sfcDimensions), testOperations.convertToHilbert(testValues2, compactHilbertCurve, sfcDimensions));
    Assert.assertArrayEquals(expectedResultOperations.convertToHilbert(testValues3, compactHilbertCurve, sfcDimensions), testOperations.convertToHilbert(testValues3, compactHilbertCurve, sfcDimensions));
    Assert.assertArrayEquals(expectedResultOperations.convertToHilbert(testValues4, compactHilbertCurve, sfcDimensions), testOperations.convertToHilbert(testValues4, compactHilbertCurve, sfcDimensions));
}
Also used : UnboundedHilbertSFCOperations(org.locationtech.geowave.core.index.sfc.hilbert.UnboundedHilbertSFCOperations) SFCDimensionDefinition(org.locationtech.geowave.core.index.sfc.SFCDimensionDefinition) ArrayList(java.util.ArrayList) CompactHilbertCurve(com.google.uzaygezen.core.CompactHilbertCurve) PrimitiveHilbertSFCOperations(org.locationtech.geowave.core.index.sfc.hilbert.PrimitiveHilbertSFCOperations) MultiDimensionalSpec(com.google.uzaygezen.core.MultiDimensionalSpec) BasicDimensionDefinition(org.locationtech.geowave.core.index.dimension.BasicDimensionDefinition) Test(org.junit.Test)

Example 2 with BasicDimensionDefinition

use of org.locationtech.geowave.core.index.dimension.BasicDimensionDefinition in project geowave by locationtech.

the class BasicNumericDimensionField method fromBinary.

@Override
public void fromBinary(final byte[] bytes) {
    final ByteBuffer buf = ByteBuffer.wrap(bytes);
    final int fieldNameLength = VarintUtils.readUnsignedInt(buf);
    final byte[] strBytes = ByteArrayUtils.safeRead(buf, fieldNameLength);
    fieldName = StringUtils.stringFromBinary(strBytes);
    final int classNameLength = VarintUtils.readUnsignedInt(buf);
    final byte[] classBytes = ByteArrayUtils.safeRead(buf, classNameLength);
    final String className = StringUtils.stringFromBinary(classBytes);
    try {
        myClass = (Class<T>) Class.forName(className);
    } catch (final ClassNotFoundException e) {
        LOGGER.warn("Unable to read class", e);
    }
    final int restLength = bytes.length - VarintUtils.unsignedIntByteLength(fieldNameLength) - fieldNameLength - VarintUtils.unsignedIntByteLength(classNameLength) - classNameLength;
    if (restLength > 0) {
        final byte[] rest = ByteArrayUtils.safeRead(buf, restLength);
        baseDefinition = new BasicDimensionDefinition();
        baseDefinition.fromBinary(rest);
    } else {
        baseDefinition = null;
    }
}
Also used : BasicDimensionDefinition(org.locationtech.geowave.core.index.dimension.BasicDimensionDefinition) ByteBuffer(java.nio.ByteBuffer) IndexDimensionHint(org.locationtech.geowave.core.index.IndexDimensionHint)

Aggregations

BasicDimensionDefinition (org.locationtech.geowave.core.index.dimension.BasicDimensionDefinition)2 CompactHilbertCurve (com.google.uzaygezen.core.CompactHilbertCurve)1 MultiDimensionalSpec (com.google.uzaygezen.core.MultiDimensionalSpec)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 IndexDimensionHint (org.locationtech.geowave.core.index.IndexDimensionHint)1 SFCDimensionDefinition (org.locationtech.geowave.core.index.sfc.SFCDimensionDefinition)1 PrimitiveHilbertSFCOperations (org.locationtech.geowave.core.index.sfc.hilbert.PrimitiveHilbertSFCOperations)1 UnboundedHilbertSFCOperations (org.locationtech.geowave.core.index.sfc.hilbert.UnboundedHilbertSFCOperations)1