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;
}
Aggregations