Search in sources :

Example 1 with FeatureProtos

use of org.locationtech.geowave.service.grpc.protobuf.FeatureProtos in project geowave by locationtech.

the class GeoWaveGrpcTestClient method spatialQuery.

public ArrayList<FeatureProtos> spatialQuery() throws UnsupportedEncodingException {
    LOGGER.info("Performing Spatial Query...");
    final VectorStoreParametersProtos baseParams = VectorStoreParametersProtos.newBuilder().setStoreName(GeoWaveGrpcTestUtils.storeName).setTypeName(GeoWaveGrpcTestUtils.typeName).setIndexName(GeoWaveGrpcTestUtils.indexName).build();
    final SpatialQueryParametersProtos request = SpatialQueryParametersProtos.newBuilder().setBaseParams(baseParams).setGeometry(copyFrom(GeoWaveGrpcTestUtils.wkbSpatialQuery)).build();
    Iterator<FeatureProtos> features;
    final ArrayList<FeatureProtos> feature_list = new ArrayList<>();
    features = vectorBlockingStub.spatialQuery(request);
    // iterate over features
    for (int i = 1; features.hasNext(); i++) {
        final FeatureProtos feature = features.next();
        feature_list.add(feature);
    }
    return feature_list;
}
Also used : SpatialQueryParametersProtos(org.locationtech.geowave.service.grpc.protobuf.SpatialQueryParametersProtos) FeatureProtos(org.locationtech.geowave.service.grpc.protobuf.FeatureProtos) ArrayList(java.util.ArrayList) VectorStoreParametersProtos(org.locationtech.geowave.service.grpc.protobuf.VectorStoreParametersProtos)

Example 2 with FeatureProtos

use of org.locationtech.geowave.service.grpc.protobuf.FeatureProtos in project geowave by locationtech.

the class GeoWaveGrpcTestClient method cqlQuery.

public ArrayList<FeatureProtos> cqlQuery() throws UnsupportedEncodingException {
    LOGGER.info("Performing CQL Query...");
    final VectorStoreParametersProtos baseParams = VectorStoreParametersProtos.newBuilder().setStoreName(GeoWaveGrpcTestUtils.storeName).setTypeName(GeoWaveGrpcTestUtils.typeName).setIndexName(GeoWaveGrpcTestUtils.indexName).build();
    final CQLQueryParametersProtos request = CQLQueryParametersProtos.newBuilder().setBaseParams(baseParams).setCql(GeoWaveGrpcTestUtils.cqlSpatialQuery).build();
    Iterator<FeatureProtos> features;
    final ArrayList<FeatureProtos> feature_list = new ArrayList<>();
    features = vectorBlockingStub.cqlQuery(request);
    // iterate over features
    for (int i = 1; features.hasNext(); i++) {
        final FeatureProtos feature = features.next();
        feature_list.add(feature);
    }
    return feature_list;
}
Also used : CQLQueryParametersProtos(org.locationtech.geowave.service.grpc.protobuf.CQLQueryParametersProtos) FeatureProtos(org.locationtech.geowave.service.grpc.protobuf.FeatureProtos) ArrayList(java.util.ArrayList) VectorStoreParametersProtos(org.locationtech.geowave.service.grpc.protobuf.VectorStoreParametersProtos)

Example 3 with FeatureProtos

use of org.locationtech.geowave.service.grpc.protobuf.FeatureProtos in project geowave by locationtech.

the class GeoWaveGrpcVectorService method cqlQuery.

@Override
public void cqlQuery(final CQLQueryParametersProtos request, final StreamObserver<FeatureProtos> responseObserver) {
    final String cql = request.getCql();
    final String storeName = request.getBaseParams().getStoreName();
    final StoreLoader storeLoader = new StoreLoader(storeName);
    String typeName = request.getBaseParams().getTypeName();
    String indexName = request.getBaseParams().getIndexName();
    if (typeName.equalsIgnoreCase("")) {
        typeName = null;
    }
    if (indexName.equalsIgnoreCase("")) {
        indexName = null;
    }
    // first check to make sure the data store exists
    if (!storeLoader.loadFromConfig(GeoWaveGrpcServiceOptions.geowaveConfigFile)) {
        throw new ParameterException("Cannot find store name: " + storeLoader.getStoreName());
    }
    // get a handle to the relevant stores
    final DataStore dataStore = storeLoader.createDataStore();
    VectorQueryBuilder bldr = VectorQueryBuilder.newBuilder();
    if (typeName != null) {
        bldr = bldr.addTypeName(typeName);
    }
    if (indexName != null) {
        bldr = bldr.indexName(indexName);
    }
    try (final CloseableIterator<SimpleFeature> iterator = dataStore.query(bldr.constraints(bldr.constraintsFactory().cqlConstraints(cql)).build())) {
        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());
            }
            final FeatureProtos f = b.build();
            responseObserver.onNext(f);
        }
        responseObserver.onCompleted();
    }
}
Also used : VectorQueryBuilder(org.locationtech.geowave.core.geotime.store.query.api.VectorQueryBuilder) ByteString(com.google.protobuf.ByteString) SimpleFeature(org.opengis.feature.simple.SimpleFeature) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) GeoWaveGTDataStore(org.locationtech.geowave.adapter.vector.plugin.GeoWaveGTDataStore) DataStore(org.locationtech.geowave.core.store.api.DataStore) 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)

Example 4 with FeatureProtos

use of org.locationtech.geowave.service.grpc.protobuf.FeatureProtos in project geowave by locationtech.

the class GeoWaveGrpcVectorService method spatialTemporalQuery.

@Override
public void spatialTemporalQuery(final SpatialTemporalQueryParametersProtos request, final StreamObserver<FeatureProtos> responseObserver) {
    final String storeName = request.getSpatialParams().getBaseParams().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());
    }
    final DataStore dataStore = storeLoader.createDataStore();
    VectorQueryBuilder bldr = VectorQueryBuilder.newBuilder();
    String typeName = request.getSpatialParams().getBaseParams().getTypeName();
    String indexName = request.getSpatialParams().getBaseParams().getIndexName();
    if (typeName.equalsIgnoreCase("")) {
        typeName = null;
    } else {
        bldr = bldr.addTypeName(typeName);
    }
    if (indexName.equalsIgnoreCase("")) {
        indexName = null;
    } else {
        bldr = bldr.indexName(indexName);
    }
    final int constraintCount = request.getTemporalConstraintsCount();
    SpatialTemporalConstraintsBuilder stBldr = bldr.constraintsFactory().spatialTemporalConstraints();
    for (int i = 0; i < constraintCount; i++) {
        final TemporalConstraintsProtos t = request.getTemporalConstraints(i);
        stBldr.addTimeRange(Interval.of(Instant.ofEpochMilli(Timestamps.toMillis(t.getStartTime())), Instant.ofEpochMilli(Timestamps.toMillis(t.getEndTime()))));
    }
    Geometry queryGeom = null;
    try {
        queryGeom = new WKBReader(JTSFactoryFinder.getGeometryFactory()).read(request.getSpatialParams().getGeometry().toByteArray());
        stBldr = stBldr.spatialConstraints(queryGeom);
        stBldr = stBldr.spatialConstraintsCompareOperation(CompareOperation.valueOf(request.getCompareOperation()));
    } catch (final FactoryRegistryException | org.locationtech.jts.io.ParseException e) {
        LOGGER.error("Exception encountered creating query geometry", e);
    }
    try (final CloseableIterator<SimpleFeature> iterator = dataStore.query(bldr.constraints(stBldr.build()).build())) {
        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());
            }
            final FeatureProtos f = b.build();
            responseObserver.onNext(f);
        }
        responseObserver.onCompleted();
    }
}
Also used : VectorQueryBuilder(org.locationtech.geowave.core.geotime.store.query.api.VectorQueryBuilder) SpatialTemporalConstraintsBuilder(org.locationtech.geowave.core.geotime.store.query.api.SpatialTemporalConstraintsBuilder) ByteString(com.google.protobuf.ByteString) WKBReader(org.locationtech.jts.io.WKBReader) SimpleFeature(org.opengis.feature.simple.SimpleFeature) TemporalConstraintsProtos(org.locationtech.geowave.service.grpc.protobuf.TemporalConstraintsProtos) Geometry(org.locationtech.jts.geom.Geometry) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) FactoryRegistryException(org.geotools.util.factory.FactoryRegistryException) GeoWaveGTDataStore(org.locationtech.geowave.adapter.vector.plugin.GeoWaveGTDataStore) DataStore(org.locationtech.geowave.core.store.api.DataStore) 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)

Example 5 with FeatureProtos

use of org.locationtech.geowave.service.grpc.protobuf.FeatureProtos 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)

Aggregations

FeatureProtos (org.locationtech.geowave.service.grpc.protobuf.FeatureProtos)9 ParameterException (com.beust.jcommander.ParameterException)4 ByteString (com.google.protobuf.ByteString)4 ArrayList (java.util.ArrayList)4 GeoWaveGTDataStore (org.locationtech.geowave.adapter.vector.plugin.GeoWaveGTDataStore)4 StoreLoader (org.locationtech.geowave.core.store.cli.store.StoreLoader)4 FeatureAttributeProtos (org.locationtech.geowave.service.grpc.protobuf.FeatureAttributeProtos)4 SimpleFeature (org.opengis.feature.simple.SimpleFeature)4 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)4 VectorQueryBuilder (org.locationtech.geowave.core.geotime.store.query.api.VectorQueryBuilder)3 DataStore (org.locationtech.geowave.core.store.api.DataStore)3 VectorStoreParametersProtos (org.locationtech.geowave.service.grpc.protobuf.VectorStoreParametersProtos)3 FactoryRegistryException (org.geotools.util.factory.FactoryRegistryException)2 SpatialQueryParametersProtos (org.locationtech.geowave.service.grpc.protobuf.SpatialQueryParametersProtos)2 TemporalConstraintsProtos (org.locationtech.geowave.service.grpc.protobuf.TemporalConstraintsProtos)2 Geometry (org.locationtech.jts.geom.Geometry)2 WKBReader (org.locationtech.jts.io.WKBReader)2 IOException (java.io.IOException)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1