use of org.locationtech.geowave.core.geotime.store.statistics.BoundingBoxStatistic in project geowave by locationtech.
the class FeatureGeometryUtils method getGeoBounds.
public static Envelope getGeoBounds(final DataStorePluginOptions dataStorePlugin, final String typeName, final String geomField) {
final DataStatisticsStore statisticsStore = dataStorePlugin.createDataStatisticsStore();
final InternalAdapterStore internalAdapterStore = dataStorePlugin.createInternalAdapterStore();
final PersistentAdapterStore adapterStore = dataStorePlugin.createAdapterStore();
final short adapterId = internalAdapterStore.getAdapterId(typeName);
final DataTypeAdapter<?> adapter = adapterStore.getAdapter(adapterId);
try (CloseableIterator<? extends Statistic<? extends StatisticValue<?>>> statIter = statisticsStore.getFieldStatistics(adapter, BoundingBoxStatistic.STATS_TYPE, geomField, null)) {
if (statIter.hasNext()) {
BoundingBoxStatistic statistic = (BoundingBoxStatistic) statIter.next();
if (statistic != null) {
BoundingBoxValue value = statisticsStore.getStatisticValue(statistic);
if (value != null) {
return value.getValue();
}
}
}
}
return null;
}
use of org.locationtech.geowave.core.geotime.store.statistics.BoundingBoxStatistic in project geowave by locationtech.
the class GeoServerIngestIT method testExamplesIngest.
@Test
public void testExamplesIngest() throws Exception {
final DataStore ds = dataStorePluginOptions.createDataStore();
final SimpleFeatureType sft = SimpleIngest.createPointFeatureType();
final Index spatialIdx = TestUtils.createWebMercatorSpatialIndex();
final Index spatialTemporalIdx = TestUtils.createWebMercatorSpatialTemporalIndex();
final GeotoolsFeatureDataAdapter fda = SimpleIngest.createDataAdapter(sft);
final List<SimpleFeature> features = getGriddedTemporalFeatures(new SimpleFeatureBuilder(sft), 8675309);
LOGGER.info(String.format("Beginning to ingest a uniform grid of %d features", features.size()));
int ingestedFeatures = 0;
final int featuresPer5Percent = features.size() / 20;
ds.addType(fda, spatialIdx, spatialTemporalIdx);
final BoundingBoxStatistic mercatorBounds = new BoundingBoxStatistic(fda.getTypeName(), sft.getGeometryDescriptor().getLocalName());
mercatorBounds.setSourceCrs(fda.getFeatureType().getGeometryDescriptor().getCoordinateReferenceSystem());
mercatorBounds.setDestinationCrs(TestUtils.CUSTOM_CRS);
mercatorBounds.setTag("MERCATOR_BOUNDS");
ds.addStatistic(mercatorBounds);
try (Writer writer = ds.createWriter(fda.getTypeName())) {
for (final SimpleFeature feat : features) {
writer.write(feat);
ingestedFeatures++;
if ((ingestedFeatures % featuresPer5Percent) == 0) {
LOGGER.info(String.format("Ingested %d percent of features", (ingestedFeatures / featuresPer5Percent) * 5));
}
}
}
final BoundingBoxValue env = ds.aggregateStatistics(StatisticQueryBuilder.newBuilder(BoundingBoxStatistic.STATS_TYPE).typeName(fda.getTypeName()).fieldName(sft.getGeometryDescriptor().getLocalName()).tag("MERCATOR_BOUNDS").build());
TestUtils.assertStatusCode("Should Create 'testomatic' Workspace", 201, geoServerServiceClient.addWorkspace("testomatic"));
storeServiceClient.addStoreReRoute(dataStorePluginOptions.getGeoWaveNamespace(), dataStorePluginOptions.getType(), dataStorePluginOptions.getGeoWaveNamespace(), dataStorePluginOptions.getOptionsAsMap());
TestUtils.assertStatusCode("Should Add " + dataStorePluginOptions.getGeoWaveNamespace() + " Datastore", 201, geoServerServiceClient.addDataStore(dataStorePluginOptions.getGeoWaveNamespace(), "testomatic", dataStorePluginOptions.getGeoWaveNamespace()));
TestUtils.assertStatusCode("Should Publish '" + ServicesTestEnvironment.TEST_STYLE_NAME_NO_DIFFERENCE + "' Style", 201, geoServerServiceClient.addStyle(ServicesTestEnvironment.TEST_SLD_NO_DIFFERENCE_FILE, ServicesTestEnvironment.TEST_STYLE_NAME_NO_DIFFERENCE));
muteLogging();
TestUtils.assertStatusCode("Should return 400, that layer was already added", 400, geoServerServiceClient.addStyle(ServicesTestEnvironment.TEST_SLD_NO_DIFFERENCE_FILE, ServicesTestEnvironment.TEST_STYLE_NAME_NO_DIFFERENCE));
unmuteLogging();
TestUtils.assertStatusCode("Should Publish '" + ServicesTestEnvironment.TEST_STYLE_NAME_MINOR_SUBSAMPLE + "' Style", 201, geoServerServiceClient.addStyle(ServicesTestEnvironment.TEST_SLD_MINOR_SUBSAMPLE_FILE, ServicesTestEnvironment.TEST_STYLE_NAME_MINOR_SUBSAMPLE));
TestUtils.assertStatusCode("Should Publish '" + ServicesTestEnvironment.TEST_STYLE_NAME_MAJOR_SUBSAMPLE + "' Style", 201, geoServerServiceClient.addStyle(ServicesTestEnvironment.TEST_SLD_MAJOR_SUBSAMPLE_FILE, ServicesTestEnvironment.TEST_STYLE_NAME_MAJOR_SUBSAMPLE));
TestUtils.assertStatusCode("Should Publish '" + ServicesTestEnvironment.TEST_STYLE_NAME_DISTRIBUTED_RENDER + "' Style", 201, geoServerServiceClient.addStyle(ServicesTestEnvironment.TEST_SLD_DISTRIBUTED_RENDER_FILE, ServicesTestEnvironment.TEST_STYLE_NAME_DISTRIBUTED_RENDER));
TestUtils.assertStatusCode("Should Publish '" + SimpleIngest.FEATURE_NAME + "' Layer", 201, geoServerServiceClient.addLayer(dataStorePluginOptions.getGeoWaveNamespace(), WORKSPACE, null, null, "point"));
if (!(ds instanceof Closeable)) {
// this is kinda hacky, but its only for the integration test - the
// problem is that GeoServer and this thread have different class
// loaders so the RocksDB "singleton" instances are not shared in
// this JVM and GeoServer currently has a lock on the datastore
// after the previous addlayer - add layer tries to lookup adapters
// while it does not have the lock and therefore fails
muteLogging();
TestUtils.assertStatusCode("Should return 400, that layer was already added", 400, geoServerServiceClient.addLayer(dataStorePluginOptions.getGeoWaveNamespace(), WORKSPACE, null, null, "point"));
unmuteLogging();
}
final BufferedImage biDirectRender = getWMSSingleTile(env.getMinX(), env.getMaxX(), env.getMinY(), env.getMaxY(), SimpleIngest.FEATURE_NAME, "point", 920, 360, null, true);
final BufferedImage ref = ImageIO.read(new File(REFERENCE_WMS_IMAGE_PATH));
// being a little lenient because of differences in O/S rendering
TestUtils.testTileAgainstReference(biDirectRender, ref, 0, 0.07);
BufferedImage biSubsamplingWithoutError = getWMSSingleTile(env.getMinX(), env.getMaxX(), env.getMinY(), env.getMaxY(), SimpleIngest.FEATURE_NAME, ServicesTestEnvironment.TEST_STYLE_NAME_NO_DIFFERENCE, 920, 360, null, false);
Assert.assertNotNull(ref);
// being a little lenient because of differences in O/S rendering
TestUtils.testTileAgainstReference(biSubsamplingWithoutError, ref, 0, 0.07);
BufferedImage biSubsamplingWithExpectedError = getWMSSingleTile(env.getMinX(), env.getMaxX(), env.getMinY(), env.getMaxY(), SimpleIngest.FEATURE_NAME, ServicesTestEnvironment.TEST_STYLE_NAME_MINOR_SUBSAMPLE, 920, 360, null, false);
TestUtils.testTileAgainstReference(biSubsamplingWithExpectedError, ref, 0.01, 0.15);
BufferedImage biSubsamplingWithLotsOfError = getWMSSingleTile(env.getMinX(), env.getMaxX(), env.getMinY(), env.getMaxY(), SimpleIngest.FEATURE_NAME, ServicesTestEnvironment.TEST_STYLE_NAME_MAJOR_SUBSAMPLE, 920, 360, null, false);
TestUtils.testTileAgainstReference(biSubsamplingWithLotsOfError, ref, 0.3, 0.4);
final BufferedImage biDistributedRendering = getWMSSingleTile(env.getMinX(), env.getMaxX(), env.getMinY(), env.getMaxY(), SimpleIngest.FEATURE_NAME, ServicesTestEnvironment.TEST_STYLE_NAME_DISTRIBUTED_RENDER, 920, 360, null, true);
TestUtils.testTileAgainstReference(biDistributedRendering, ref, 0, 0.07);
// Test subsampling with only the spatial-temporal index
ds.removeIndex(spatialIdx.getName());
ServicesTestEnvironment.getInstance().restartServices();
biSubsamplingWithoutError = getWMSSingleTile(env.getMinX(), env.getMaxX(), env.getMinY(), env.getMaxY(), SimpleIngest.FEATURE_NAME, ServicesTestEnvironment.TEST_STYLE_NAME_NO_DIFFERENCE, 920, 360, null, true);
Assert.assertNotNull(ref);
// being a little lenient because of differences in O/S rendering
TestUtils.testTileAgainstReference(biSubsamplingWithoutError, ref, 0, 0.071);
biSubsamplingWithExpectedError = getWMSSingleTile(env.getMinX(), env.getMaxX(), env.getMinY(), env.getMaxY(), SimpleIngest.FEATURE_NAME, ServicesTestEnvironment.TEST_STYLE_NAME_MINOR_SUBSAMPLE, 920, 360, null, true);
TestUtils.testTileAgainstReference(biSubsamplingWithExpectedError, ref, 0.01, 0.151);
biSubsamplingWithLotsOfError = getWMSSingleTile(env.getMinX(), env.getMaxX(), env.getMinY(), env.getMaxY(), SimpleIngest.FEATURE_NAME, ServicesTestEnvironment.TEST_STYLE_NAME_MAJOR_SUBSAMPLE, 920, 360, null, true);
TestUtils.testTileAgainstReference(biSubsamplingWithLotsOfError, ref, 0.3, 0.41);
}
use of org.locationtech.geowave.core.geotime.store.statistics.BoundingBoxStatistic in project geowave by locationtech.
the class QueryIndexHelperTest method testBBOXStatReprojection.
@Test
public void testBBOXStatReprojection() {
// create a EPSG:3785 feature (units in meters)
final SimpleFeature mercFeat = createGeoMercFeature(factory.createPoint(new Coordinate(19971868.8804, 20037508.3428)));
// convert from EPSG:3785 to EPSG:4326 (convert to degrees lon/lat)
// approximately 180.0, 85.0
final SimpleFeature defaultCRSFeat = GeometryUtils.crsTransform(mercFeat, geoType, transform);
final BoundingBoxStatistic bboxStat = new BoundingBoxStatistic(geoType.getTypeName(), geoType.getGeometryDescriptor().getLocalName(), geoMercType.getCoordinateReferenceSystem(), geoType.getCoordinateReferenceSystem());
final BoundingBoxValue bboxValue = bboxStat.createEmpty();
bboxValue.entryIngested(new FeatureDataAdapter(geoType), mercFeat);
final Coordinate coord = ((Point) defaultCRSFeat.getDefaultGeometry()).getCoordinate();
// coordinate should match reprojected feature
assertEquals(coord.x, bboxValue.getMinX(), 0.0001);
assertEquals(coord.x, bboxValue.getMaxX(), 0.0001);
assertEquals(coord.y, bboxValue.getMinY(), 0.0001);
assertEquals(coord.y, bboxValue.getMaxY(), 0.0001);
}
use of org.locationtech.geowave.core.geotime.store.statistics.BoundingBoxStatistic in project geowave by locationtech.
the class QueryIndexHelperTest method testComposeQueryWithOutTimeRange.
@Test
public void testComposeQueryWithOutTimeRange() {
final TestStatisticsCache statsCache = new TestStatisticsCache();
final BoundingBoxStatistic geoStats = new BoundingBoxStatistic("type", "geometry");
final BoundingBoxValue value = geoStats.createEmpty();
statsCache.putFieldStatistic(BoundingBoxStatistic.STATS_TYPE, "geometry", value);
final SimpleFeature firstFeature = createGeoFeature(factory.createPoint(new Coordinate(22.25, 42.25)));
FeatureDataAdapter adapter = new FeatureDataAdapter(firstFeature.getFeatureType());
value.entryIngested(adapter, firstFeature);
final SimpleFeature secondFeature = createGeoFeature(factory.createPoint(new Coordinate(27.25, 41.25)));
value.entryIngested(adapter, secondFeature);
final Envelope bounds = new Envelope(21.23, 26.23, 41.75, 43.1);
final BasicQueryByClass query = new BasicQueryByClass(QueryIndexHelper.composeConstraints(statsCache, geoType, geoTimeDescriptors, new GeometryFactory().toGeometry(bounds), null));
final List<MultiDimensionalNumericData> nd = query.getIndexConstraints(SPATIAL_INDEX);
assertEquals(21.23, nd.get(0).getDataPerDimension()[0].getMin(), 0.0001);
assertEquals(26.23, nd.get(0).getDataPerDimension()[0].getMax(), 0.0001);
assertEquals(41.75, nd.get(0).getDataPerDimension()[1].getMin(), 0.0001);
assertEquals(43.1, nd.get(0).getDataPerDimension()[1].getMax(), 0.0001);
}
use of org.locationtech.geowave.core.geotime.store.statistics.BoundingBoxStatistic in project geowave by locationtech.
the class QueryIndexHelperTest method testComposeSubsetConstraints.
@Test
public void testComposeSubsetConstraints() throws ParseException {
final TestStatisticsCache statsCache = new TestStatisticsCache();
final TimeRangeStatistic startStats = new TimeRangeStatistic("type", "start");
final TimeRangeValue startValue = startStats.createEmpty();
statsCache.putFieldStatistic(TimeRangeStatistic.STATS_TYPE, "start", startValue);
final TimeRangeStatistic endStats = new TimeRangeStatistic("type", "end");
final TimeRangeValue endValue = endStats.createEmpty();
statsCache.putFieldStatistic(TimeRangeStatistic.STATS_TYPE, "end", endValue);
final Date statsStart1 = DateUtilities.parseISO("2005-05-18T20:32:56Z");
final Date statsStart2 = DateUtilities.parseISO("2005-05-20T20:32:56Z");
final Date statsEnd1 = DateUtilities.parseISO("2005-05-21T20:32:56Z");
final Date statsEnd2 = DateUtilities.parseISO("2005-05-24T20:32:56Z");
final SimpleFeature firstRangFeature = createFeature(statsStart1, statsEnd1);
FeatureDataAdapter adapter = new FeatureDataAdapter(firstRangFeature.getFeatureType());
startValue.entryIngested(adapter, firstRangFeature);
endValue.entryIngested(adapter, firstRangFeature);
final SimpleFeature secondRangFeature = createFeature(statsStart2, statsEnd2);
startValue.entryIngested(adapter, secondRangFeature);
endValue.entryIngested(adapter, secondRangFeature);
final Date stime = DateUtilities.parseISO("2005-05-18T20:32:56Z");
final Date etime = DateUtilities.parseISO("2005-05-19T20:32:56Z");
final TemporalConstraintsSet constraintsSet = new TemporalConstraintsSet();
constraintsSet.getConstraintsForRange("start", "end").add(new TemporalRange(stime, etime));
final Constraints constraints = QueryIndexHelper.composeTimeBoundedConstraints(rangeType, rangeTimeDescriptors, constraintsSet);
final List<MultiDimensionalNumericData> nd = constraints.getIndexConstraints(SPATIAL_TEMPORAL_INDEX);
assertTrue(nd.isEmpty());
final BoundingBoxStatistic geoStats = new BoundingBoxStatistic("type", "geometry");
final BoundingBoxValue geoValue = geoStats.createEmpty();
statsCache.putFieldStatistic(BoundingBoxStatistic.STATS_TYPE, "geometry", geoValue);
final SimpleFeature firstFeature = createGeoFeature(factory.createPoint(new Coordinate(22.25, 42.25)));
geoValue.entryIngested(adapter, firstFeature);
final SimpleFeature secondFeature = createGeoFeature(factory.createPoint(new Coordinate(27.25, 41.25)));
geoValue.entryIngested(adapter, secondFeature);
final Constraints constraints1 = QueryIndexHelper.composeConstraints(statsCache, rangeType, rangeTimeDescriptors, null, constraintsSet);
final List<MultiDimensionalNumericData> nd1 = constraints1.getIndexConstraints(SPATIAL_TEMPORAL_INDEX);
assertTrue(nd1.isEmpty());
/*
* assertEquals( stime.getTime(), (long) nd1.get( 0).getDataPerDimension()[2].getMin());
* assertEquals( etime.getTime(), (long) nd1.get( 0).getDataPerDimension()[2].getMax());
*/
final TemporalConstraintsSet constraintsSet2 = new TemporalConstraintsSet();
constraintsSet2.getConstraintsForRange("start", "end").add(new TemporalRange(statsStart1, statsEnd2));
final Constraints constraints2 = QueryIndexHelper.composeTimeBoundedConstraints(rangeType, rangeTimeDescriptors, constraintsSet2);
final List<MultiDimensionalNumericData> nd2 = constraints2.getIndexConstraints(SPATIAL_TEMPORAL_INDEX);
assertTrue(nd2.isEmpty());
}
Aggregations