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