Search in sources :

Example 1 with NumericData

use of org.locationtech.geowave.core.index.numeric.NumericData in project geowave by locationtech.

the class NumericFieldConstraints method generateNumericData.

private static void generateNumericData(final List<MultiDimensionalIndexData<Double>> results, final int currentDimension, final List<DimensionConstraints<Double>> dimensions, final NumericData[] current) {
    if (currentDimension == dimensions.size()) {
        results.add(new BasicNumericDataset(current));
        return;
    }
    final DimensionConstraints<Double> dimension = dimensions.get(currentDimension);
    final List<FilterRange<Double>> ranges = dimension.getRanges();
    for (int i = 0; i < ranges.size(); i++) {
        final NumericData[] copy = Arrays.copyOf(current, current.length + 1);
        final FilterRange<Double> range = ranges.get(i);
        final Double start = toStartRangeValue(range.getStart());
        final Double end = toEndRangeValue(range.getEnd());
        if (start.equals(end) && range.isStartInclusive() && range.isEndInclusive()) {
            copy[copy.length - 1] = new NumericValue(start);
        } else {
            copy[copy.length - 1] = new NumericRange(toStartRangeValue(range.getStart()), toEndRangeValue(range.getEnd()), range.isStartInclusive(), range.isEndInclusive());
        }
        generateNumericData(results, currentDimension + 1, dimensions, copy);
    }
}
Also used : NumericRange(org.locationtech.geowave.core.index.numeric.NumericRange) BasicNumericDataset(org.locationtech.geowave.core.index.numeric.BasicNumericDataset) NumericData(org.locationtech.geowave.core.index.numeric.NumericData) FilterRange(org.locationtech.geowave.core.store.query.filter.expression.FilterRange) NumericValue(org.locationtech.geowave.core.index.numeric.NumericValue)

Example 2 with NumericData

use of org.locationtech.geowave.core.index.numeric.NumericData in project geowave by locationtech.

the class SpatialQueryFilter method stripGeometry.

private static StrippedGeometry stripGeometry(final MultiDimensionalNumericData query, final NumericDimensionField<?>[] orderedConstrainedDimensionDefinitions, final NumericDimensionField<?>[] unconstrainedDimensionDefinitions) {
    final Set<String> geometryFieldNames = new HashSet<>();
    final List<NumericData> numericDataPerDimension = new ArrayList<>();
    final List<NumericDimensionField<?>> fields = new ArrayList<>();
    final NumericData[] data = query.getDataPerDimension();
    for (int d = 0; d < orderedConstrainedDimensionDefinitions.length; d++) {
        // the field ID for later filtering
        if (isSpatial(orderedConstrainedDimensionDefinitions[d])) {
            geometryFieldNames.add(orderedConstrainedDimensionDefinitions[d].getFieldName());
        } else {
            numericDataPerDimension.add(data[d]);
            fields.add(orderedConstrainedDimensionDefinitions[d]);
        }
    }
    // results)
    for (int d = 0; d < unconstrainedDimensionDefinitions.length; d++) {
        if (isSpatial(unconstrainedDimensionDefinitions[d])) {
            geometryFieldNames.add(unconstrainedDimensionDefinitions[d].getFieldName());
        }
    }
    return new StrippedGeometry(new BasicNumericDataset(numericDataPerDimension.toArray(new NumericData[numericDataPerDimension.size()])), fields.toArray(new NumericDimensionField<?>[fields.size()]), geometryFieldNames);
}
Also used : NumericDimensionField(org.locationtech.geowave.core.store.dimension.NumericDimensionField) BasicNumericDataset(org.locationtech.geowave.core.index.numeric.BasicNumericDataset) NumericData(org.locationtech.geowave.core.index.numeric.NumericData) MultiDimensionalNumericData(org.locationtech.geowave.core.index.numeric.MultiDimensionalNumericData) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 3 with NumericData

use of org.locationtech.geowave.core.index.numeric.NumericData in project geowave by locationtech.

the class TieredSFCIndexStrategyTest method testPredefinedSpatialEntries.

@Test
public void testPredefinedSpatialEntries() throws Exception {
    final NumericIndexStrategy strategy = TieredSFCIndexFactory.createDefinedPrecisionTieredStrategy(new NumericDimensionDefinition[] { new LongitudeDefinition(), new LatitudeDefinition(true) }, new int[][] { DEFINED_BITS_OF_PRECISION.clone(), DEFINED_BITS_OF_PRECISION.clone() }, SFCType.HILBERT);
    for (int sfcIndex = 0; sfcIndex < DEFINED_BITS_OF_PRECISION.length; sfcIndex++) {
        final NumericData[] dataPerDimension = new NumericData[2];
        final double precision = 360 / Math.pow(2, DEFINED_BITS_OF_PRECISION[sfcIndex]);
        if (precision > 180) {
            dataPerDimension[0] = new NumericRange(-180, 180);
            dataPerDimension[1] = new NumericRange(-90, 90);
        } else {
            dataPerDimension[0] = new NumericRange(0, precision);
            dataPerDimension[1] = new NumericRange(-precision, 0);
        }
        final MultiDimensionalNumericData indexedData = new BasicNumericDataset(dataPerDimension);
        final InsertionIds ids = strategy.getInsertionIds(indexedData);
        final NumericData[] queryRangePerDimension = new NumericData[2];
        queryRangePerDimension[0] = new NumericRange(dataPerDimension[0].getMin() + QUERY_RANGE_EPSILON, dataPerDimension[0].getMax() - QUERY_RANGE_EPSILON);
        queryRangePerDimension[1] = new NumericRange(dataPerDimension[1].getMin() + QUERY_RANGE_EPSILON, dataPerDimension[1].getMax() - QUERY_RANGE_EPSILON);
        final MultiDimensionalNumericData queryData = new BasicNumericDataset(queryRangePerDimension);
        final QueryRanges queryRanges = strategy.getQueryRanges(queryData);
        final Set<Byte> queryRangeTiers = new HashSet<>();
        boolean rangeAtTierFound = false;
        for (final ByteArrayRange range : queryRanges.getCompositeQueryRanges()) {
            final byte tier = range.getStart()[0];
            queryRangeTiers.add(range.getStart()[0]);
            if (tier == DEFINED_BITS_OF_PRECISION[sfcIndex]) {
                if (rangeAtTierFound) {
                    throw new Exception("multiple ranges were found unexpectedly for tier " + tier);
                }
                assertArrayEquals("this range is an exact fit, so it should have exactly one value for tier " + DEFINED_BITS_OF_PRECISION[sfcIndex], range.getStart(), range.getEnd());
                rangeAtTierFound = true;
            }
        }
        if (!rangeAtTierFound) {
            throw new Exception("no ranges were found at the expected exact fit tier " + DEFINED_BITS_OF_PRECISION[sfcIndex]);
        }
        // of precision
        if ((ids.getCompositeInsertionIds().get(0)[0] == 0) || ((sfcIndex == (DEFINED_BITS_OF_PRECISION.length - 1)) || (DEFINED_BITS_OF_PRECISION[sfcIndex + 1] != (DEFINED_BITS_OF_PRECISION[sfcIndex] + 1)))) {
            assertEquals("Insertion ID expected to be exact match at tier " + DEFINED_BITS_OF_PRECISION[sfcIndex], DEFINED_BITS_OF_PRECISION[sfcIndex], ids.getCompositeInsertionIds().get(0)[0]);
            assertEquals("Insertion ID size expected to be 1 at tier " + DEFINED_BITS_OF_PRECISION[sfcIndex], 1, ids.getCompositeInsertionIds().size());
        } else {
            assertEquals("Insertion ID expected to be duplicated at tier " + DEFINED_BITS_OF_PRECISION[sfcIndex + 1], DEFINED_BITS_OF_PRECISION[sfcIndex + 1], ids.getCompositeInsertionIds().get(0)[0]);
            // if the precision is within the bounds of longitude but not
            // within latitude we will end up with 2 (rectangular
            // decomposition)
            // otherwise we will get a square decomposition of 4 ids
            final int expectedIds = (precision > 90) && (precision <= 180) ? 2 : 4;
            assertEquals("Insertion ID size expected to be " + expectedIds + " at tier " + DEFINED_BITS_OF_PRECISION[sfcIndex + 1], expectedIds, ids.getCompositeInsertionIds().size());
        }
    }
}
Also used : LatitudeDefinition(org.locationtech.geowave.core.geotime.index.dimension.LatitudeDefinition) MultiDimensionalNumericData(org.locationtech.geowave.core.index.numeric.MultiDimensionalNumericData) QueryRanges(org.locationtech.geowave.core.index.QueryRanges) BasicNumericDataset(org.locationtech.geowave.core.index.numeric.BasicNumericDataset) NumericData(org.locationtech.geowave.core.index.numeric.NumericData) MultiDimensionalNumericData(org.locationtech.geowave.core.index.numeric.MultiDimensionalNumericData) ByteArrayRange(org.locationtech.geowave.core.index.ByteArrayRange) ParseException(java.text.ParseException) NumericRange(org.locationtech.geowave.core.index.numeric.NumericRange) InsertionIds(org.locationtech.geowave.core.index.InsertionIds) NumericIndexStrategy(org.locationtech.geowave.core.index.NumericIndexStrategy) LongitudeDefinition(org.locationtech.geowave.core.geotime.index.dimension.LongitudeDefinition) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with NumericData

use of org.locationtech.geowave.core.index.numeric.NumericData in project geowave by locationtech.

the class GeometryUtils method basicConstraintsFromPoint.

/**
 * This utility method will convert a JTS envelope to that can be used in a GeoWave query.
 *
 * @return Constraints as a mapping of NumericData objects representing ranges for a latitude
 *         dimension and a longitude dimension
 */
public static ConstraintSet basicConstraintsFromPoint(final double latitudeDegrees, final double longitudeDegrees) {
    // Create a NumericData object using the x axis
    final NumericData latitude = new NumericValue(latitudeDegrees);
    // Create a NumericData object using the y axis
    final NumericData longitude = new NumericValue(longitudeDegrees);
    final Map<Class<? extends NumericDimensionDefinition>, ConstraintData> constraintsPerDimension = new HashMap<>();
    // Create and return a new IndexRange array with an x and y axis
    // range
    constraintsPerDimension.put(LongitudeDefinition.class, new ConstraintData(longitude, false));
    constraintsPerDimension.put(LatitudeDefinition.class, new ConstraintData(latitude, false));
    return new ConstraintSet(constraintsPerDimension);
}
Also used : ConstraintData(org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintData) HashMap(java.util.HashMap) NumericDimensionDefinition(org.locationtech.geowave.core.index.dimension.NumericDimensionDefinition) MultiDimensionalNumericData(org.locationtech.geowave.core.index.numeric.MultiDimensionalNumericData) NumericData(org.locationtech.geowave.core.index.numeric.NumericData) ConstraintsByClass(org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintsByClass) NumericValue(org.locationtech.geowave.core.index.numeric.NumericValue) ConstraintSet(org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintSet)

Example 5 with NumericData

use of org.locationtech.geowave.core.index.numeric.NumericData in project geowave by locationtech.

the class TieredSFCIndexStrategyTest method testRegions.

@Test
public void testRegions() throws ParseException {
    final Calendar cal = Calendar.getInstance();
    final Calendar calEnd = Calendar.getInstance();
    final SimpleDateFormat format = new SimpleDateFormat("MM-dd-yyyy HH:mm:ss");
    cal.setTime(format.parse("03-03-1999 11:01:01"));
    calEnd.setTime(format.parse("03-03-1999 11:05:01"));
    final NumericData[] dataPerDimension1 = new NumericData[SPATIAL_TEMPORAL_DIMENSIONS.length];
    dataPerDimension1[0] = new NumericRange(45.170, 45.173);
    dataPerDimension1[1] = new NumericRange(50.190, 50.192);
    dataPerDimension1[2] = new NumericRange(cal.getTimeInMillis(), calEnd.getTimeInMillis());
    final int year = cal.get(Calendar.YEAR);
    cal.set(Calendar.DAY_OF_YEAR, 1);
    final NumericData[] dataPerDimension2 = new NumericData[SPATIAL_TEMPORAL_DIMENSIONS.length];
    dataPerDimension2[0] = new NumericRange(45, 50);
    dataPerDimension2[1] = new NumericRange(45, 50);
    dataPerDimension2[2] = new NumericRange(cal.getTimeInMillis(), calEnd.getTimeInMillis());
    cal.set(Calendar.YEAR, year - 1);
    calEnd.set(Calendar.YEAR, year - 1);
    final NumericData[] dataPerDimension3 = new NumericData[SPATIAL_TEMPORAL_DIMENSIONS.length];
    dataPerDimension3[0] = new NumericRange(45.1701, 45.1703);
    dataPerDimension3[1] = new NumericRange(50.1901, 50.1902);
    dataPerDimension3[2] = new NumericRange(cal.getTimeInMillis(), calEnd.getTimeInMillis());
    MultiDimensionalNumericData indexedData = new BasicNumericDataset(dataPerDimension1);
    final NumericIndexStrategy strategy = TieredSFCIndexFactory.createEqualIntervalPrecisionTieredStrategy(SPATIAL_TEMPORAL_DIMENSIONS, new int[] { 20, 20, 20 }, SFCType.HILBERT, 4);
    final InsertionIds ids1 = strategy.getInsertionIds(indexedData);
    assertEquals(1, ids1.getCompositeInsertionIds().size());
    assertEquals(10, ids1.getCompositeInsertionIds().get(0).length);
    // different bin bin
    indexedData = new BasicNumericDataset(dataPerDimension2);
    final InsertionIds ids2 = strategy.getInsertionIds(indexedData);
    assertEquals(1, ids2.getCompositeInsertionIds().size());
    // different tier
    assertFalse(compare(ids1.getCompositeInsertionIds().get(0), ids2.getCompositeInsertionIds().get(0), 1));
    // same time
    assertTrue(compare(ids1.getCompositeInsertionIds().get(0), ids2.getCompositeInsertionIds().get(0), 1, 5));
    // different bin
    indexedData = new BasicNumericDataset(dataPerDimension3);
    final List<byte[]> ids3 = strategy.getInsertionIds(indexedData).getCompositeInsertionIds();
    assertEquals(1, ids3.size());
    assertFalse(compare(ids1.getCompositeInsertionIds().get(0), ids3.get(0), 1, 5));
}
Also used : NumericRange(org.locationtech.geowave.core.index.numeric.NumericRange) MultiDimensionalNumericData(org.locationtech.geowave.core.index.numeric.MultiDimensionalNumericData) BasicNumericDataset(org.locationtech.geowave.core.index.numeric.BasicNumericDataset) InsertionIds(org.locationtech.geowave.core.index.InsertionIds) Calendar(java.util.Calendar) NumericData(org.locationtech.geowave.core.index.numeric.NumericData) MultiDimensionalNumericData(org.locationtech.geowave.core.index.numeric.MultiDimensionalNumericData) SimpleDateFormat(java.text.SimpleDateFormat) NumericIndexStrategy(org.locationtech.geowave.core.index.NumericIndexStrategy) Test(org.junit.Test)

Aggregations

NumericData (org.locationtech.geowave.core.index.numeric.NumericData)18 BasicNumericDataset (org.locationtech.geowave.core.index.numeric.BasicNumericDataset)16 MultiDimensionalNumericData (org.locationtech.geowave.core.index.numeric.MultiDimensionalNumericData)15 NumericRange (org.locationtech.geowave.core.index.numeric.NumericRange)10 Test (org.junit.Test)9 NumericValue (org.locationtech.geowave.core.index.numeric.NumericValue)6 InsertionIds (org.locationtech.geowave.core.index.InsertionIds)5 NumericIndexStrategy (org.locationtech.geowave.core.index.NumericIndexStrategy)5 NumericDimensionField (org.locationtech.geowave.core.store.dimension.NumericDimensionField)5 ArrayList (java.util.ArrayList)4 ConstraintData (org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintData)4 ConstraintSet (org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintSet)4 ConstraintsByClass (org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintsByClass)4 HashMap (java.util.HashMap)3 Index (org.locationtech.geowave.core.store.api.Index)3 BasicQueryByClass (org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass)3 ByteBuffer (java.nio.ByteBuffer)2 Calendar (java.util.Calendar)2 HashSet (java.util.HashSet)2 LatitudeDefinition (org.locationtech.geowave.core.geotime.index.dimension.LatitudeDefinition)2