Search in sources :

Example 1 with GeoWaveEmptyTransaction

use of org.locationtech.geowave.adapter.vector.plugin.transaction.GeoWaveEmptyTransaction in project geowave by locationtech.

the class GeoWaveFeatureSource method getBoundsInternal.

@Override
protected ReferencedEnvelope getBoundsInternal(final Query query) throws IOException {
    double minx = -90.0, maxx = 90.0, miny = -180.0, maxy = 180.0;
    BoundingBoxValue bboxStats = null;
    if (query.getFilter().equals(Filter.INCLUDE)) {
        final StatisticsCache statsCache = new GeoWaveEmptyTransaction(components).getDataStatistics();
        bboxStats = statsCache.getFieldStatistic(BoundingBoxStatistic.STATS_TYPE, getFeatureType().getGeometryDescriptor().getLocalName());
    }
    CoordinateReferenceSystem bboxCRS = DefaultGeographicCRS.WGS84;
    if (bboxStats != null) {
        minx = bboxStats.getMinX();
        maxx = bboxStats.getMaxX();
        miny = bboxStats.getMinY();
        maxy = bboxStats.getMaxY();
        BoundingBoxStatistic statistic = (BoundingBoxStatistic) bboxStats.getStatistic();
        if (statistic.getDestinationCrs() != null) {
            bboxCRS = statistic.getDestinationCrs();
        } else {
            bboxCRS = components.getAdapter().getFeatureType().getCoordinateReferenceSystem();
        }
    } else {
        final FeatureReader<SimpleFeatureType, SimpleFeature> reader = new GeoWaveFeatureReader(query, new GeoWaveEmptyTransaction(components), components);
        if (reader.hasNext()) {
            bboxCRS = components.getCRS();
            BoundingBox featureBounds = reader.next().getBounds();
            minx = featureBounds.getMinX();
            maxx = featureBounds.getMaxX();
            miny = featureBounds.getMinY();
            maxy = featureBounds.getMaxY();
            while (reader.hasNext()) {
                featureBounds = reader.next().getBounds();
                minx = Math.min(featureBounds.getMinX(), minx);
                maxx = Math.max(featureBounds.getMaxX(), maxx);
                miny = Math.min(featureBounds.getMinY(), miny);
                maxy = Math.max(featureBounds.getMaxY(), maxy);
            }
        }
        reader.close();
    }
    ReferencedEnvelope retVal = new ReferencedEnvelope(minx, maxx, miny, maxy, bboxCRS);
    if (!bboxCRS.equals(components.getCRS())) {
        try {
            retVal = retVal.transform(components.getCRS(), true);
        } catch (FactoryException | TransformException e) {
            LOGGER.warn("Unable to transform bounding box for feature source.");
        }
    }
    return retVal;
}
Also used : BoundingBoxStatistic(org.locationtech.geowave.core.geotime.store.statistics.BoundingBoxStatistic) FactoryException(org.opengis.referencing.FactoryException) TransformException(org.opengis.referencing.operation.TransformException) BoundingBoxValue(org.locationtech.geowave.core.geotime.store.statistics.BoundingBoxStatistic.BoundingBoxValue) StatisticsCache(org.locationtech.geowave.adapter.vector.plugin.transaction.StatisticsCache) SimpleFeature(org.opengis.feature.simple.SimpleFeature) ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) GeoWaveEmptyTransaction(org.locationtech.geowave.adapter.vector.plugin.transaction.GeoWaveEmptyTransaction) BoundingBox(org.opengis.geometry.BoundingBox) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem)

Aggregations

ReferencedEnvelope (org.geotools.geometry.jts.ReferencedEnvelope)1 GeoWaveEmptyTransaction (org.locationtech.geowave.adapter.vector.plugin.transaction.GeoWaveEmptyTransaction)1 StatisticsCache (org.locationtech.geowave.adapter.vector.plugin.transaction.StatisticsCache)1 BoundingBoxStatistic (org.locationtech.geowave.core.geotime.store.statistics.BoundingBoxStatistic)1 BoundingBoxValue (org.locationtech.geowave.core.geotime.store.statistics.BoundingBoxStatistic.BoundingBoxValue)1 SimpleFeature (org.opengis.feature.simple.SimpleFeature)1 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)1 BoundingBox (org.opengis.geometry.BoundingBox)1 FactoryException (org.opengis.referencing.FactoryException)1 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)1 TransformException (org.opengis.referencing.operation.TransformException)1