Search in sources :

Example 1 with TemporalConstraintsProtos

use of org.locationtech.geowave.service.grpc.protobuf.TemporalConstraintsProtos 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 2 with TemporalConstraintsProtos

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

the class GeoWaveGrpcTestClient method spatialTemporalQuery.

public ArrayList<FeatureProtos> spatialTemporalQuery() throws ParseException {
    LOGGER.info("Performing Spatial Temporal Query...");
    final VectorStoreParametersProtos baseParams = VectorStoreParametersProtos.newBuilder().setStoreName(GeoWaveGrpcTestUtils.storeName).build();
    final TimeZone tz = TimeZone.getTimeZone("UTC");
    // Quoted "Z" to indicate
    final DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");
    // UTC,
    // no timezone offset
    df.setTimeZone(tz);
    final SpatialQueryParametersProtos spatialQuery = SpatialQueryParametersProtos.newBuilder().setBaseParams(baseParams).setGeometry(copyFrom(GeoWaveGrpcTestUtils.wkbSpatialQuery)).build();
    final TemporalConstraintsProtos t = TemporalConstraintsProtos.newBuilder().setStartTime(Timestamps.fromMillis(df.parse(GeoWaveGrpcTestUtils.temporalQueryStartTime).getTime())).setEndTime(Timestamps.fromMillis(df.parse(GeoWaveGrpcTestUtils.temporalQueryEndTime).getTime())).build();
    final SpatialTemporalQueryParametersProtos request = SpatialTemporalQueryParametersProtos.newBuilder().setSpatialParams(spatialQuery).addTemporalConstraints(0, t).setCompareOperation("CONTAINS").build();
    Iterator<FeatureProtos> features;
    final ArrayList<FeatureProtos> feature_list = new ArrayList<>();
    features = vectorBlockingStub.spatialTemporalQuery(request);
    // iterate over features
    while (features.hasNext()) {
        final FeatureProtos feature = features.next();
        feature_list.add(feature);
    }
    return feature_list;
}
Also used : TemporalConstraintsProtos(org.locationtech.geowave.service.grpc.protobuf.TemporalConstraintsProtos) TimeZone(java.util.TimeZone) SpatialQueryParametersProtos(org.locationtech.geowave.service.grpc.protobuf.SpatialQueryParametersProtos) SpatialTemporalQueryParametersProtos(org.locationtech.geowave.service.grpc.protobuf.SpatialTemporalQueryParametersProtos) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) FeatureProtos(org.locationtech.geowave.service.grpc.protobuf.FeatureProtos) ArrayList(java.util.ArrayList) VectorStoreParametersProtos(org.locationtech.geowave.service.grpc.protobuf.VectorStoreParametersProtos) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

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