Search in sources :

Example 1 with GeoWaveGTDataStore

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

the class GeoWaveGrpcVectorService method vectorQuery.

@Override
public void vectorQuery(final VectorQueryParametersProtos request, final StreamObserver<FeatureProtos> responseObserver) {
    final String storeName = request.getStoreName();
    final StoreLoader storeLoader = new StoreLoader(storeName);
    // first check to make sure the data store exists
    if (!storeLoader.loadFromConfig(GeoWaveGrpcServiceOptions.geowaveConfigFile)) {
        throw new ParameterException("Cannot find store name: " + storeLoader.getStoreName());
    }
    GeoWaveGTDataStore gtStore = null;
    try {
        gtStore = new GeoWaveGTDataStore(new GeoWavePluginConfig(storeLoader.getDataStorePlugin()));
    } catch (final IOException | GeoWavePluginException e) {
        LOGGER.error("Exception encountered instantiating GeoWaveGTDataStore", e);
        responseObserver.onError(e);
    }
    Filter filter = null;
    try {
        filter = ECQL.toFilter(request.getQuery());
    } catch (final CQLException e) {
        LOGGER.error("Exception encountered creating filter from CQL", e);
        responseObserver.onError(e);
    }
    ContentFeatureCollection featureCollection = null;
    try {
        final String typeName = request.getTypeName();
        featureCollection = gtStore.getFeatureSource(typeName).getFeatures(filter);
    } catch (final IOException | NullPointerException e) {
        LOGGER.error("Exception encountered getting feature collection", e);
        responseObserver.onError(e);
    }
    try (final SimpleFeatureIterator iterator = featureCollection.features()) {
        while (iterator.hasNext()) {
            final SimpleFeature simpleFeature = iterator.next();
            final SimpleFeatureType type = simpleFeature.getType();
            final FeatureProtos.Builder b = FeatureProtos.newBuilder();
            final FeatureAttributeProtos.Builder attBuilder = FeatureAttributeProtos.newBuilder();
            for (int i = 0; i < type.getAttributeDescriptors().size(); i++) {
                setAttributeBuilderValue(simpleFeature.getAttribute(i), attBuilder);
                b.putAttributes(type.getAttributeDescriptors().get(i).getLocalName(), attBuilder.build());
            /*
           * b.putAttributes( type.getAttributeDescriptors().get( i).getLocalName(),
           * simpleFeature.getAttribute(i) == null ? "" : simpleFeature.getAttribute(
           * i).toString());
           */
            }
            final FeatureProtos f = b.build();
            responseObserver.onNext(f);
        }
        responseObserver.onCompleted();
    } catch (final NullPointerException e) {
        LOGGER.error("Exception encountered", e);
        responseObserver.onError(e);
    }
}
Also used : GeoWavePluginConfig(org.locationtech.geowave.adapter.vector.plugin.GeoWavePluginConfig) ContentFeatureCollection(org.geotools.data.store.ContentFeatureCollection) ByteString(com.google.protobuf.ByteString) IOException(java.io.IOException) SimpleFeature(org.opengis.feature.simple.SimpleFeature) GeoWavePluginException(org.locationtech.geowave.adapter.vector.plugin.GeoWavePluginException) SimpleFeatureIterator(org.geotools.data.simple.SimpleFeatureIterator) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Filter(org.opengis.filter.Filter) GeoWaveGTDataStore(org.locationtech.geowave.adapter.vector.plugin.GeoWaveGTDataStore) FeatureProtos(org.locationtech.geowave.service.grpc.protobuf.FeatureProtos) StoreLoader(org.locationtech.geowave.core.store.cli.store.StoreLoader) ParameterException(com.beust.jcommander.ParameterException) FeatureAttributeProtos(org.locationtech.geowave.service.grpc.protobuf.FeatureAttributeProtos) CQLException(org.geotools.filter.text.cql2.CQLException)

Example 2 with GeoWaveGTDataStore

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

the class SpatialTemporalQueryIT method initSpatialTemporalTestData.

@Before
public void initSpatialTemporalTestData() throws IOException, GeoWavePluginException {
    dataStore = dataStoreOptions.createDataStore();
    SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
    builder.setName("simpletimestamp");
    builder.add("geo", Point.class);
    builder.add("timestamp", Date.class);
    timeStampAdapter = new FeatureDataAdapter(builder.buildFeatureType());
    builder = new SimpleFeatureTypeBuilder();
    builder.setName("simpletimerange");
    builder.add("geo", Point.class);
    builder.add("startTime", Date.class);
    builder.add("endTime", Date.class);
    timeRangeAdapter = new FeatureDataAdapter(builder.buildFeatureType());
    Calendar cal = getInitialDayCalendar();
    final GeometryFactory geomFactory = new GeometryFactory();
    final SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(timeStampAdapter.getFeatureType());
    final SimpleFeatureBuilder featureTimeRangeBuilder = new SimpleFeatureBuilder(timeRangeAdapter.getFeatureType());
    dataStore.addType(timeStampAdapter, YEAR_INDEX, MONTH_INDEX, DAY_INDEX);
    final Writer timeWriters = dataStore.createWriter(timeStampAdapter.getTypeName());
    // time ranges for days isn't tested so we don't have to deal with
    // ingesting into the day index, the multi-year test case (requiring
    // 1000+ partitions)
    dataStore.addType(timeRangeAdapter, YEAR_INDEX, MONTH_INDEX);
    final Writer rangeWriters = dataStore.createWriter(timeRangeAdapter.getTypeName());
    try {
        for (int day = cal.getActualMinimum(Calendar.DAY_OF_MONTH); day <= cal.getActualMaximum(Calendar.DAY_OF_MONTH); day++) {
            final double ptVal = ((((day + 1.0) - cal.getActualMinimum(Calendar.DAY_OF_MONTH)) / ((cal.getActualMaximum(Calendar.DAY_OF_MONTH) - cal.getActualMinimum(Calendar.DAY_OF_MONTH)) + 2.0)) * 2) - 1;
            cal.set(Calendar.DAY_OF_MONTH, day);
            final Point pt = geomFactory.createPoint(new Coordinate(ptVal, ptVal));
            featureBuilder.add(pt);
            featureBuilder.add(cal.getTime());
            final SimpleFeature feature = featureBuilder.buildFeature("day:" + day);
            timeWriters.write(feature);
        }
        cal = getInitialMonthCalendar();
        for (int month = cal.getActualMinimum(Calendar.MONTH); month <= cal.getActualMaximum(Calendar.MONTH); month++) {
            cal.set(Calendar.MONTH, month);
            final double ptVal = ((((month + 1.0) - cal.getActualMinimum(Calendar.MONTH)) / ((cal.getActualMaximum(Calendar.MONTH) - cal.getActualMinimum(Calendar.MONTH)) + 2.0)) * 2) - 1;
            final Point pt = geomFactory.createPoint(new Coordinate(ptVal, ptVal));
            featureBuilder.add(pt);
            featureBuilder.add(cal.getTime());
            final SimpleFeature feature = featureBuilder.buildFeature("month:" + month);
            timeWriters.write(feature);
        }
        ingestTimeRangeData(cal, rangeWriters, featureTimeRangeBuilder, cal.getActualMinimum(Calendar.MONTH), cal.getActualMaximum(Calendar.MONTH), Calendar.MONTH, "month");
        cal = getInitialYearCalendar();
        for (int year = MULTI_YEAR_MIN; year <= MULTI_YEAR_MAX; year++) {
            final double ptVal = ((((year + 1.0) - MULTI_YEAR_MIN) / ((MULTI_YEAR_MAX - MULTI_YEAR_MIN) + 2.0)) * 2) - 1;
            cal.set(Calendar.YEAR, year);
            final Point pt = geomFactory.createPoint(new Coordinate(ptVal, ptVal));
            featureBuilder.add(pt);
            featureBuilder.add(cal.getTime());
            final SimpleFeature feature = featureBuilder.buildFeature("year:" + year);
            timeWriters.write(feature);
        }
        ingestTimeRangeData(cal, rangeWriters, featureTimeRangeBuilder, MULTI_YEAR_MIN, MULTI_YEAR_MAX, Calendar.YEAR, "year");
        Point pt = geomFactory.createPoint(new Coordinate(-50, -50));
        featureBuilder.add(pt);
        featureBuilder.add(cal.getTime());
        SimpleFeature feature = featureBuilder.buildFeature("outlier1timestamp");
        timeWriters.write(feature);
        pt = geomFactory.createPoint(new Coordinate(50, 50));
        featureBuilder.add(pt);
        featureBuilder.add(cal.getTime());
        feature = featureBuilder.buildFeature("outlier2timestamp");
        timeWriters.write(feature);
        pt = geomFactory.createPoint(new Coordinate(-50, -50));
        featureTimeRangeBuilder.add(pt);
        featureTimeRangeBuilder.add(cal.getTime());
        cal.roll(Calendar.MINUTE, 5);
        featureTimeRangeBuilder.add(cal.getTime());
        feature = featureTimeRangeBuilder.buildFeature("outlier1timerange");
        rangeWriters.write(feature);
        pt = geomFactory.createPoint(new Coordinate(50, 50));
        featureTimeRangeBuilder.add(pt);
        featureTimeRangeBuilder.add(cal.getTime());
        cal.roll(Calendar.MINUTE, 5);
        featureTimeRangeBuilder.add(cal.getTime());
        feature = featureTimeRangeBuilder.buildFeature("outlier2timerange");
        rangeWriters.write(feature);
        // Ingest data for duplicate deletion, should not overlap time
        // ranges from other tests
        ingestTimeRangeDataForDuplicateDeletion(cal, rangeWriters, featureTimeRangeBuilder, DUPLICATE_DELETION_YEAR_MIN, DUPLICATE_DELETION_YEAR_MAX, Calendar.YEAR, "ranged_year");
    } finally {
        timeWriters.close();
        rangeWriters.close();
    }
    geowaveGtDataStore = new GeoWaveGTDataStore(new GeoWavePluginConfig(dataStoreOptions) {

        @Override
        public IndexQueryStrategySPI getIndexQueryStrategy() {
            return new IndexQueryStrategySPI() {

                @Override
                public boolean requiresStats() {
                    return false;
                }

                @Override
                public CloseableIterator<Index> getIndices(final DataStatisticsStore statisticsStore, final AdapterIndexMappingStore mappingStore, final QueryConstraints query, final Index[] indices, final InternalDataAdapter<?> adapter, final Map<QueryHint, Object> hints) {
                    return new CloseableIteratorWrapper<>(new Closeable() {

                        @Override
                        public void close() throws IOException {
                        }
                    }, Collections.singleton(currentGeotoolsIndex).iterator());
                }
            };
        }
    });
}
Also used : GeoWavePluginConfig(org.locationtech.geowave.adapter.vector.plugin.GeoWavePluginConfig) SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Calendar(java.util.Calendar) Closeable(java.io.Closeable) QueryConstraints(org.locationtech.geowave.core.store.query.constraints.QueryConstraints) Index(org.locationtech.geowave.core.store.api.Index) Point(org.locationtech.jts.geom.Point) IOException(java.io.IOException) AdapterIndexMappingStore(org.locationtech.geowave.core.store.adapter.AdapterIndexMappingStore) Point(org.locationtech.jts.geom.Point) SimpleFeature(org.opengis.feature.simple.SimpleFeature) IndexQueryStrategySPI(org.locationtech.geowave.adapter.vector.index.IndexQueryStrategySPI) DataStatisticsStore(org.locationtech.geowave.core.store.statistics.DataStatisticsStore) Coordinate(org.locationtech.jts.geom.Coordinate) GeoWaveGTDataStore(org.locationtech.geowave.adapter.vector.plugin.GeoWaveGTDataStore) InternalDataAdapter(org.locationtech.geowave.core.store.adapter.InternalDataAdapter) CloseableIteratorWrapper(org.locationtech.geowave.core.store.CloseableIteratorWrapper) FeatureDataAdapter(org.locationtech.geowave.adapter.vector.FeatureDataAdapter) Map(java.util.Map) Writer(org.locationtech.geowave.core.store.api.Writer) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder) Before(org.junit.Before)

Aggregations

IOException (java.io.IOException)2 GeoWaveGTDataStore (org.locationtech.geowave.adapter.vector.plugin.GeoWaveGTDataStore)2 GeoWavePluginConfig (org.locationtech.geowave.adapter.vector.plugin.GeoWavePluginConfig)2 SimpleFeature (org.opengis.feature.simple.SimpleFeature)2 ParameterException (com.beust.jcommander.ParameterException)1 ByteString (com.google.protobuf.ByteString)1 Closeable (java.io.Closeable)1 Calendar (java.util.Calendar)1 Map (java.util.Map)1 SimpleFeatureIterator (org.geotools.data.simple.SimpleFeatureIterator)1 ContentFeatureCollection (org.geotools.data.store.ContentFeatureCollection)1 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)1 SimpleFeatureTypeBuilder (org.geotools.feature.simple.SimpleFeatureTypeBuilder)1 CQLException (org.geotools.filter.text.cql2.CQLException)1 Before (org.junit.Before)1 FeatureDataAdapter (org.locationtech.geowave.adapter.vector.FeatureDataAdapter)1 IndexQueryStrategySPI (org.locationtech.geowave.adapter.vector.index.IndexQueryStrategySPI)1 GeoWavePluginException (org.locationtech.geowave.adapter.vector.plugin.GeoWavePluginException)1 CloseableIteratorWrapper (org.locationtech.geowave.core.store.CloseableIteratorWrapper)1 AdapterIndexMappingStore (org.locationtech.geowave.core.store.adapter.AdapterIndexMappingStore)1