Search in sources :

Example 1 with MaxVisitor

use of org.geotools.feature.visitor.MaxVisitor in project geowave by locationtech.

the class GeoWaveFeatureReaderTest method testMax.

@Test
public void testMax() throws IllegalArgumentException, NoSuchElementException, IOException {
    final FeatureReader<SimpleFeatureType, SimpleFeature> reader = dataStore.getFeatureReader(query, Transaction.AUTO_COMMIT);
    final MaxVisitor visitor = new MaxVisitor("start", type);
    unwrapDelegatingFeatureReader(reader).getFeatureCollection().accepts(visitor, null);
    assertTrue(visitor.getMax().equals(mtime));
}
Also used : SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) MaxVisitor(org.geotools.feature.visitor.MaxVisitor) SimpleFeature(org.opengis.feature.simple.SimpleFeature) BaseDataStoreTest(org.locationtech.geowave.adapter.vector.BaseDataStoreTest) Test(org.junit.Test)

Example 2 with MaxVisitor

use of org.geotools.feature.visitor.MaxVisitor in project incubator-rya by apache.

the class GeoWaveFeatureReaderTest method testMax.

@Test
public void testMax() throws IllegalArgumentException, NoSuchElementException, IOException {
    final FeatureReader<SimpleFeatureType, SimpleFeature> reader = dataStore.getFeatureReader(query, Transaction.AUTO_COMMIT);
    final MaxVisitor visitor = new MaxVisitor("start", type);
    unwrapDelegatingFeatureReader(reader).getFeatureCollection().accepts(visitor, null);
    assertTrue(visitor.getMax().equals(etime));
}
Also used : SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) MaxVisitor(org.geotools.feature.visitor.MaxVisitor) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Test(org.junit.Test)

Example 3 with MaxVisitor

use of org.geotools.feature.visitor.MaxVisitor in project geowave by locationtech.

the class GeoWaveGTPluginUtils method accepts.

protected static boolean accepts(final DataStatisticsStore statisticsStore, final DataTypeAdapter<?> adapter, final org.opengis.feature.FeatureVisitor visitor, final org.opengis.util.ProgressListener progress, final SimpleFeatureType featureType) throws IOException {
    if ((visitor instanceof MinVisitor)) {
        final ExtractAttributesFilter filter = new ExtractAttributesFilter();
        final MinVisitor minVisitor = (MinVisitor) visitor;
        final Collection<String> attrs = (Collection<String>) minVisitor.getExpression().accept(filter, null);
        int acceptedCount = 0;
        final Map<String, List<FieldStatistic<?>>> adapterFieldStatistics = getFieldStats(statisticsStore, adapter);
        for (final String attr : attrs) {
            if (!adapterFieldStatistics.containsKey(attr)) {
                continue;
            }
            for (final FieldStatistic<?> stat : adapterFieldStatistics.get(attr)) {
                if ((stat instanceof TimeRangeStatistic) && (stat.getBinningStrategy() == null)) {
                    final TimeRangeValue statValue = statisticsStore.getStatisticValue((TimeRangeStatistic) stat);
                    if (statValue != null) {
                        minVisitor.setValue(convertToType(attr, new Date(statValue.getMin()), featureType));
                        acceptedCount++;
                    }
                } else if (stat instanceof NumericRangeStatistic) {
                    try (CloseableIterator<NumericRangeValue> values = statisticsStore.getStatisticValues((NumericRangeStatistic) stat)) {
                        NumericRangeValue statValue = ((NumericRangeStatistic) stat).createEmpty();
                        while (values.hasNext()) {
                            statValue.merge(values.next());
                        }
                        if (statValue.isSet()) {
                            minVisitor.setValue(convertToType(attr, statValue.getMin(), featureType));
                            acceptedCount++;
                        }
                    }
                }
            }
        }
        if (acceptedCount > 0) {
            if (progress != null) {
                progress.complete();
            }
            return true;
        }
    } else if ((visitor instanceof MaxVisitor)) {
        final ExtractAttributesFilter filter = new ExtractAttributesFilter();
        final MaxVisitor maxVisitor = (MaxVisitor) visitor;
        final Collection<String> attrs = (Collection<String>) maxVisitor.getExpression().accept(filter, null);
        int acceptedCount = 0;
        final Map<String, List<FieldStatistic<?>>> adapterFieldStatistics = getFieldStats(statisticsStore, adapter);
        for (final String attr : attrs) {
            for (final FieldStatistic<?> stat : adapterFieldStatistics.get(attr)) {
                if ((stat instanceof TimeRangeStatistic) && (stat.getBinningStrategy() == null)) {
                    final TimeRangeValue statValue = statisticsStore.getStatisticValue((TimeRangeStatistic) stat);
                    if (statValue != null) {
                        maxVisitor.setValue(convertToType(attr, new Date(statValue.getMax()), featureType));
                        acceptedCount++;
                    }
                } else if (stat instanceof NumericRangeStatistic) {
                    try (CloseableIterator<NumericRangeValue> values = statisticsStore.getStatisticValues((NumericRangeStatistic) stat)) {
                        NumericRangeValue statValue = ((NumericRangeStatistic) stat).createEmpty();
                        while (values.hasNext()) {
                            statValue.merge(values.next());
                        }
                        if (statValue.isSet()) {
                            maxVisitor.setValue(convertToType(attr, statValue.getMax(), featureType));
                            acceptedCount++;
                        }
                    }
                }
            }
        }
        if (acceptedCount > 0) {
            if (progress != null) {
                progress.complete();
            }
            return true;
        }
    }
    return false;
}
Also used : CloseableIterator(org.locationtech.geowave.core.store.CloseableIterator) NumericRangeStatistic(org.locationtech.geowave.core.store.statistics.field.NumericRangeStatistic) MinVisitor(org.geotools.feature.visitor.MinVisitor) ExtractAttributesFilter(org.locationtech.geowave.core.geotime.util.ExtractAttributesFilter) Date(java.util.Date) MaxVisitor(org.geotools.feature.visitor.MaxVisitor) Collection(java.util.Collection) List(java.util.List) NumericRangeValue(org.locationtech.geowave.core.store.statistics.field.NumericRangeStatistic.NumericRangeValue) TimeRangeStatistic(org.locationtech.geowave.core.geotime.store.statistics.TimeRangeStatistic) TimeRangeValue(org.locationtech.geowave.core.geotime.store.statistics.TimeRangeStatistic.TimeRangeValue) Map(java.util.Map) FieldStatistic(org.locationtech.geowave.core.store.api.FieldStatistic)

Aggregations

MaxVisitor (org.geotools.feature.visitor.MaxVisitor)3 Test (org.junit.Test)2 SimpleFeature (org.opengis.feature.simple.SimpleFeature)2 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)2 Collection (java.util.Collection)1 Date (java.util.Date)1 List (java.util.List)1 Map (java.util.Map)1 MinVisitor (org.geotools.feature.visitor.MinVisitor)1 BaseDataStoreTest (org.locationtech.geowave.adapter.vector.BaseDataStoreTest)1 TimeRangeStatistic (org.locationtech.geowave.core.geotime.store.statistics.TimeRangeStatistic)1 TimeRangeValue (org.locationtech.geowave.core.geotime.store.statistics.TimeRangeStatistic.TimeRangeValue)1 ExtractAttributesFilter (org.locationtech.geowave.core.geotime.util.ExtractAttributesFilter)1 CloseableIterator (org.locationtech.geowave.core.store.CloseableIterator)1 FieldStatistic (org.locationtech.geowave.core.store.api.FieldStatistic)1 NumericRangeStatistic (org.locationtech.geowave.core.store.statistics.field.NumericRangeStatistic)1 NumericRangeValue (org.locationtech.geowave.core.store.statistics.field.NumericRangeStatistic.NumericRangeValue)1