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