Search in sources :

Example 1 with RangeDecomposition

use of org.locationtech.geowave.core.index.sfc.RangeDecomposition in project geowave by locationtech.

the class HilbertSFCTest method testDecomposeQuery_2DSpatialOneIndexFilter.

@Test
public void testDecomposeQuery_2DSpatialOneIndexFilter() {
    final int LATITUDE_BITS = 31;
    final int LONGITUDE_BITS = 31;
    final SFCDimensionDefinition[] SPATIAL_DIMENSIONS = new SFCDimensionDefinition[] { new SFCDimensionDefinition(new LongitudeDefinition(), LONGITUDE_BITS), new SFCDimensionDefinition(new LatitudeDefinition(), LATITUDE_BITS) };
    final SpaceFillingCurve hilbertSFC = SFCFactory.createSpaceFillingCurve(SPATIAL_DIMENSIONS, SFCType.HILBERT);
    // Create a IndexRange object using the x axis
    final NumericRange rangeX = new NumericRange(55, 57);
    // Create a IndexRange object using the y axis
    final NumericRange rangeY = new NumericRange(25, 27);
    final BasicNumericDataset spatialQuery = new BasicNumericDataset(new NumericData[] { rangeX, rangeY });
    final RangeDecomposition rangeDecomposition = hilbertSFC.decomposeRange(spatialQuery, true, 1);
    Assert.assertEquals(1, rangeDecomposition.getRanges().length);
}
Also used : NumericRange(org.locationtech.geowave.core.index.numeric.NumericRange) LatitudeDefinition(org.locationtech.geowave.core.geotime.index.dimension.LatitudeDefinition) BasicNumericDataset(org.locationtech.geowave.core.index.numeric.BasicNumericDataset) SFCDimensionDefinition(org.locationtech.geowave.core.index.sfc.SFCDimensionDefinition) SpaceFillingCurve(org.locationtech.geowave.core.index.sfc.SpaceFillingCurve) RangeDecomposition(org.locationtech.geowave.core.index.sfc.RangeDecomposition) LongitudeDefinition(org.locationtech.geowave.core.geotime.index.dimension.LongitudeDefinition) Test(org.junit.Test)

Example 2 with RangeDecomposition

use of org.locationtech.geowave.core.index.sfc.RangeDecomposition in project geowave by locationtech.

the class HilbertSFCTest method testDecomposeQuery_2DSpatialTwentyIndexFilters.

@Test
public void testDecomposeQuery_2DSpatialTwentyIndexFilters() {
    final int LATITUDE_BITS = 31;
    final int LONGITUDE_BITS = 31;
    final SFCDimensionDefinition[] SPATIAL_DIMENSIONS = new SFCDimensionDefinition[] { new SFCDimensionDefinition(new LongitudeDefinition(), LONGITUDE_BITS), new SFCDimensionDefinition(new LatitudeDefinition(), LATITUDE_BITS) };
    final SpaceFillingCurve hilbertSFC = SFCFactory.createSpaceFillingCurve(SPATIAL_DIMENSIONS, SFCType.HILBERT);
    // Create a IndexRange object using the x axis
    final NumericRange rangeX = new NumericRange(10, 57);
    // Create a IndexRange object using the y axis
    final NumericRange rangeY = new NumericRange(25, 50);
    final BasicNumericDataset spatialQuery = new BasicNumericDataset(new NumericData[] { rangeX, rangeY });
    final RangeDecomposition rangeDecomposition = hilbertSFC.decomposeRange(spatialQuery, true, 20);
    Assert.assertEquals(20, rangeDecomposition.getRanges().length);
}
Also used : NumericRange(org.locationtech.geowave.core.index.numeric.NumericRange) LatitudeDefinition(org.locationtech.geowave.core.geotime.index.dimension.LatitudeDefinition) BasicNumericDataset(org.locationtech.geowave.core.index.numeric.BasicNumericDataset) SFCDimensionDefinition(org.locationtech.geowave.core.index.sfc.SFCDimensionDefinition) SpaceFillingCurve(org.locationtech.geowave.core.index.sfc.SpaceFillingCurve) RangeDecomposition(org.locationtech.geowave.core.index.sfc.RangeDecomposition) LongitudeDefinition(org.locationtech.geowave.core.geotime.index.dimension.LongitudeDefinition) Test(org.junit.Test)

Example 3 with RangeDecomposition

use of org.locationtech.geowave.core.index.sfc.RangeDecomposition in project geowave by locationtech.

the class PrimitiveHilbertSFCTest method testSpatialGetIdAndQueryDecomposition62BitsTotal.

@Test
public void testSpatialGetIdAndQueryDecomposition62BitsTotal() {
    final SFCDimensionDefinition[] sfcDimensions = new SFCDimensionDefinition[SPATIAL_DIMENSIONS.length];
    int totalPrecision = 0;
    final List<Integer> bitsPerDimension = new ArrayList<>();
    for (int d = 0; d < SPATIAL_DIMENSIONS.length; d++) {
        final int bitsOfPrecision = 31;
        sfcDimensions[d] = new SFCDimensionDefinition(SPATIAL_DIMENSIONS[d], bitsOfPrecision);
        bitsPerDimension.add(bitsOfPrecision);
        totalPrecision += 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[] { 45d, 45d };
    final Double[] testValues2 = new Double[] { 0d, 0d };
    final Double[] testValues3 = new Double[] { -1.235456, -67.9213546 };
    final Double[] testValues4 = new Double[] { -61.2354561024897435868943753568436598645436, 42.921354693742875894356895549054690704378590896 };
    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));
    final NumericRange rangeLongitude1 = new NumericRange(0, 1);
    final NumericRange rangeLatitude1 = new NumericRange(0, 1);
    final NumericRange rangeLongitude2 = new NumericRange(-21.324967549, 28.4285637846834432543);
    final NumericRange rangeLatitude2 = new NumericRange(-43.7894445665435346547657867847657654, 32.3254325834896543657895436543543659);
    final NumericRange rangeLongitude3 = new NumericRange(-10, 0);
    final NumericRange rangeLatitude3 = new NumericRange(-10, 0);
    final NumericRange rangeLongitude4 = new NumericRange(-Double.MIN_VALUE, 0);
    final NumericRange rangeLatitude4 = new NumericRange(0, Double.MIN_VALUE);
    final RangeDecomposition expectedResult1 = expectedResultOperations.decomposeRange(new NumericData[] { rangeLongitude1, rangeLatitude1 }, compactHilbertCurve, sfcDimensions, totalPrecision, Integer.MAX_VALUE, true, true);
    final RangeDecomposition testResult1 = testOperations.decomposeRange(new NumericData[] { rangeLongitude1, rangeLatitude1 }, compactHilbertCurve, sfcDimensions, totalPrecision, Integer.MAX_VALUE, true, true);
    Assert.assertTrue(expectedResult1.getRanges().length == testResult1.getRanges().length);
    for (int i = 0; i < expectedResult1.getRanges().length; i++) {
        Assert.assertTrue(expectedResult1.getRanges()[i].equals(testResult1.getRanges()[i]));
    }
    final RangeDecomposition expectedResult2 = expectedResultOperations.decomposeRange(new NumericData[] { rangeLongitude2, rangeLatitude2 }, compactHilbertCurve, sfcDimensions, totalPrecision, Integer.MAX_VALUE, true, true);
    final RangeDecomposition testResult2 = testOperations.decomposeRange(new NumericData[] { rangeLongitude2, rangeLatitude2 }, compactHilbertCurve, sfcDimensions, totalPrecision, Integer.MAX_VALUE, true, true);
    Assert.assertTrue(expectedResult2.getRanges().length == testResult2.getRanges().length);
    for (int i = 0; i < expectedResult2.getRanges().length; i++) {
        Assert.assertTrue(expectedResult2.getRanges()[i].equals(testResult2.getRanges()[i]));
    }
    final RangeDecomposition expectedResult3 = expectedResultOperations.decomposeRange(new NumericData[] { rangeLongitude3, rangeLatitude3 }, compactHilbertCurve, sfcDimensions, totalPrecision, Integer.MAX_VALUE, true, false);
    final RangeDecomposition testResult3 = testOperations.decomposeRange(new NumericData[] { rangeLongitude3, rangeLatitude3 }, compactHilbertCurve, sfcDimensions, totalPrecision, Integer.MAX_VALUE, true, false);
    Assert.assertTrue(expectedResult3.getRanges().length == testResult3.getRanges().length);
    for (int i = 0; i < expectedResult3.getRanges().length; i++) {
        Assert.assertTrue(expectedResult3.getRanges()[i].equals(testResult3.getRanges()[i]));
    }
    final RangeDecomposition expectedResult4 = expectedResultOperations.decomposeRange(new NumericData[] { rangeLongitude4, rangeLatitude4 }, compactHilbertCurve, sfcDimensions, totalPrecision, Integer.MAX_VALUE, true, false);
    final RangeDecomposition testResult4 = testOperations.decomposeRange(new NumericData[] { rangeLongitude4, rangeLatitude4 }, compactHilbertCurve, sfcDimensions, totalPrecision, Integer.MAX_VALUE, true, false);
    Assert.assertTrue(expectedResult4.getRanges().length == testResult4.getRanges().length);
    for (int i = 0; i < expectedResult4.getRanges().length; i++) {
        Assert.assertTrue(expectedResult4.getRanges()[i].equals(testResult4.getRanges()[i]));
    }
}
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) NumericRange(org.locationtech.geowave.core.index.numeric.NumericRange) PrimitiveHilbertSFCOperations(org.locationtech.geowave.core.index.sfc.hilbert.PrimitiveHilbertSFCOperations) MultiDimensionalSpec(com.google.uzaygezen.core.MultiDimensionalSpec) RangeDecomposition(org.locationtech.geowave.core.index.sfc.RangeDecomposition) Test(org.junit.Test)

Example 4 with RangeDecomposition

use of org.locationtech.geowave.core.index.sfc.RangeDecomposition in project geowave by locationtech.

the class BinnedSFCUtils method getQueryRanges.

public static List<SinglePartitionQueryRanges> getQueryRanges(final List<BinnedNumericDataset> binnedQueries, final SpaceFillingCurve sfc, final int maxRanges, final Byte tier) {
    final List<SinglePartitionQueryRanges> queryRanges = new ArrayList<>();
    int maxRangeDecompositionPerBin = maxRanges;
    if ((maxRanges > 1) && (binnedQueries.size() > 1)) {
        maxRangeDecompositionPerBin = (int) Math.ceil((double) maxRanges / (double) binnedQueries.size());
    }
    for (final BinnedNumericDataset binnedQuery : binnedQueries) {
        final RangeDecomposition rangeDecomp = sfc.decomposeRange(binnedQuery, true, maxRangeDecompositionPerBin);
        final byte[] tierAndBinId = tier != null ? ByteArrayUtils.combineArrays(new byte[] { tier // we're assuming tiers only go to 127 (the max byte
        // value)
        }, binnedQuery.getBinId()) : binnedQuery.getBinId();
        queryRanges.add(new SinglePartitionQueryRanges(tierAndBinId, Arrays.asList(rangeDecomp.getRanges())));
    }
    return queryRanges;
}
Also used : BinnedNumericDataset(org.locationtech.geowave.core.index.numeric.BinnedNumericDataset) SinglePartitionQueryRanges(org.locationtech.geowave.core.index.SinglePartitionQueryRanges) ArrayList(java.util.ArrayList) RangeDecomposition(org.locationtech.geowave.core.index.sfc.RangeDecomposition)

Example 5 with RangeDecomposition

use of org.locationtech.geowave.core.index.sfc.RangeDecomposition in project geowave by locationtech.

the class UnboundedHilbertSFCOperations method decomposeRange.

@Override
public RangeDecomposition decomposeRange(final NumericData[] rangePerDimension, final CompactHilbertCurve compactHilbertCurve, final SFCDimensionDefinition[] dimensionDefinitions, final int totalPrecision, final int maxFilteredIndexedRanges, final boolean removeVacuum, final boolean overInclusiveOnEdge) {
    // List of query range minimum
    // and
    // maximum
    // values
    final List<BigInteger> minRangeList = new ArrayList<>();
    final List<BigInteger> maxRangeList = new ArrayList<>();
    final BigIntegerContent zero = new BigIntegerContent(BigInteger.valueOf(0L));
    final List<BigIntegerRange> region = new ArrayList<>(dimensionDefinitions.length);
    for (int d = 0; d < dimensionDefinitions.length; d++) {
        final BigInteger normalizedMin = normalizeDimension(dimensionDefinitions[d], rangePerDimension[d].getMin(), binsPerDimension[d], true, overInclusiveOnEdge);
        BigInteger normalizedMax = normalizeDimension(dimensionDefinitions[d], rangePerDimension[d].getMax(), binsPerDimension[d], false, overInclusiveOnEdge);
        if (normalizedMin.compareTo(normalizedMax) > 0) {
            // if they're both equal, which is possible because we treat max
            // as exclusive, set bin max to bin min (ie. treat it as
            // inclusive in this case)
            normalizedMax = normalizedMin;
        }
        minRangeList.add(normalizedMin);
        maxRangeList.add(normalizedMax);
        region.add(BigIntegerRange.of(normalizedMin, normalizedMax.add(BigInteger.ONE)));
    }
    final BigInteger minQuadSize = getMinimumQuadSize(minRangeList, maxRangeList);
    final RegionInspector<BigIntegerRange, BigIntegerContent> regionInspector = SimpleRegionInspector.create(ImmutableList.of(region), new BigIntegerContent(minQuadSize), Functions.<BigIntegerRange>identity(), BigIntegerRangeHome.INSTANCE, zero);
    final PlainFilterCombiner<BigIntegerRange, BigInteger, BigIntegerContent, BigIntegerRange> intervalCombiner = new PlainFilterCombiner<>(BigIntegerRange.of(0, 1));
    final QueryBuilder<BigIntegerRange, BigIntegerRange> queryBuilder = BacktrackingQueryBuilder.create(regionInspector, intervalCombiner, maxFilteredIndexedRanges, removeVacuum, BigIntegerRangeHome.INSTANCE, zero);
    synchronized (compactHilbertCurve) {
        compactHilbertCurve.accept(new ZoomingSpaceVisitorAdapter(compactHilbertCurve, queryBuilder));
    }
    // com.google.uzaygezen.core.Query<LongRange, LongRange> hilbertQuery =
    // queryBuilder.get();
    final List<FilteredIndexRange<BigIntegerRange, BigIntegerRange>> hilbertRanges = queryBuilder.get().getFilteredIndexRanges();
    final ByteArrayRange[] sfcRanges = new ByteArrayRange[hilbertRanges.size()];
    final int expectedByteCount = (int) Math.ceil(totalPrecision / 8.0);
    if (expectedByteCount <= 0) {
        // special case for no precision
        return new RangeDecomposition(new ByteArrayRange[] { new ByteArrayRange(new byte[0], new byte[0]) });
    }
    for (int i = 0; i < hilbertRanges.size(); i++) {
        final FilteredIndexRange<BigIntegerRange, BigIntegerRange> range = hilbertRanges.get(i);
        // sanity check that values fit within the expected range
        // it seems that uzaygezen can produce a value at 2^totalPrecision
        // rather than 2^totalPrecision - 1
        final BigInteger startValue = clamp(minHilbertValue, maxHilbertValue, range.getIndexRange().getStart());
        final BigInteger endValue = clamp(minHilbertValue, maxHilbertValue, range.getIndexRange().getEnd().subtract(BigInteger.ONE));
        // make sure its padded if necessary
        final byte[] start = HilbertSFC.fitExpectedByteCount(expectedByteCount, startValue.toByteArray());
        // make sure its padded if necessary
        final byte[] end = HilbertSFC.fitExpectedByteCount(expectedByteCount, endValue.toByteArray());
        sfcRanges[i] = new ByteArrayRange(start, end);
    }
    final RangeDecomposition rangeDecomposition = new RangeDecomposition(sfcRanges);
    return rangeDecomposition;
}
Also used : BigIntegerRange(com.google.uzaygezen.core.ranges.BigIntegerRange) FilteredIndexRange(com.google.uzaygezen.core.FilteredIndexRange) ArrayList(java.util.ArrayList) ZoomingSpaceVisitorAdapter(com.google.uzaygezen.core.ZoomingSpaceVisitorAdapter) ByteArrayRange(org.locationtech.geowave.core.index.ByteArrayRange) PlainFilterCombiner(com.google.uzaygezen.core.PlainFilterCombiner) BigIntegerContent(com.google.uzaygezen.core.BigIntegerContent) BigInteger(java.math.BigInteger) RangeDecomposition(org.locationtech.geowave.core.index.sfc.RangeDecomposition)

Aggregations

RangeDecomposition (org.locationtech.geowave.core.index.sfc.RangeDecomposition)9 ArrayList (java.util.ArrayList)6 ByteArrayRange (org.locationtech.geowave.core.index.ByteArrayRange)5 Test (org.junit.Test)3 NumericRange (org.locationtech.geowave.core.index.numeric.NumericRange)3 SFCDimensionDefinition (org.locationtech.geowave.core.index.sfc.SFCDimensionDefinition)3 FilteredIndexRange (com.google.uzaygezen.core.FilteredIndexRange)2 PlainFilterCombiner (com.google.uzaygezen.core.PlainFilterCombiner)2 ZoomingSpaceVisitorAdapter (com.google.uzaygezen.core.ZoomingSpaceVisitorAdapter)2 LatitudeDefinition (org.locationtech.geowave.core.geotime.index.dimension.LatitudeDefinition)2 LongitudeDefinition (org.locationtech.geowave.core.geotime.index.dimension.LongitudeDefinition)2 BasicNumericDataset (org.locationtech.geowave.core.index.numeric.BasicNumericDataset)2 SpaceFillingCurve (org.locationtech.geowave.core.index.sfc.SpaceFillingCurve)2 BigIntegerContent (com.google.uzaygezen.core.BigIntegerContent)1 CompactHilbertCurve (com.google.uzaygezen.core.CompactHilbertCurve)1 LongContent (com.google.uzaygezen.core.LongContent)1 MultiDimensionalSpec (com.google.uzaygezen.core.MultiDimensionalSpec)1 BigIntegerRange (com.google.uzaygezen.core.ranges.BigIntegerRange)1 LongRange (com.google.uzaygezen.core.ranges.LongRange)1 BigInteger (java.math.BigInteger)1