Search in sources :

Example 1 with FactoryRegistryException

use of org.geotools.util.factory.FactoryRegistryException in project geowave by locationtech.

the class BasicDataTypeAdapterExample method querySpatial.

private void querySpatial() {
    try {
        // This bounding box represents approximately Europe, so only the European POIs will be
        // queried
        final String queryPolygonDefinition = "POLYGON (( " + "-10.55 35.96, " + "-10.55 71.30, " + "56.16 71.30, " + "56.16 35.96, " + "-10.55 35.96" + "))";
        final Geometry queryPolygon = new WKTReader(JTSFactoryFinder.getGeometryFactory()).read(queryPolygonDefinition);
        final QueryConstraints queryConstraints = new SpatialTemporalConstraintsBuilderImpl().spatialConstraints(queryPolygon).build();
        // Query the POI adapter
        final Query<POI> query = QueryBuilder.newBuilder(POI.class).addTypeName(adapter.getTypeName()).indexName(spatialIndex.getName()).constraints(queryConstraints).build();
        System.out.println("Executing query on POI adapter, expecting to match Roman Colosseum and Eiffel Tower...");
        try (final CloseableIterator<POI> iterator = dataStore.query(query)) {
            while (iterator.hasNext()) {
                System.out.println("Query match: " + iterator.next().getName());
            }
        }
        // Now query the annotated POI adapter
        final Query<AnnotatedPOI> annotatedQuery = QueryBuilder.newBuilder(AnnotatedPOI.class).addTypeName(annotatedAdapter.getTypeName()).indexName(spatialIndex.getName()).constraints(queryConstraints).build();
        System.out.println("Executing query on Annotated POI adapter, expecting to match Roman Colosseum and Eiffel Tower...");
        try (final CloseableIterator<AnnotatedPOI> iterator = dataStore.query(annotatedQuery)) {
            while (iterator.hasNext()) {
                System.out.println("Query match: " + iterator.next().getName());
            }
        }
    } catch (FactoryRegistryException | ParseException e) {
    }
}
Also used : QueryConstraints(org.locationtech.geowave.core.store.query.constraints.QueryConstraints) SpatialTemporalConstraintsBuilderImpl(org.locationtech.geowave.core.geotime.store.query.SpatialTemporalConstraintsBuilderImpl) WKTReader(org.locationtech.jts.io.WKTReader) Geometry(org.locationtech.jts.geom.Geometry) FactoryRegistryException(org.geotools.util.factory.FactoryRegistryException) ParseException(org.locationtech.jts.io.ParseException)

Example 2 with FactoryRegistryException

use of org.geotools.util.factory.FactoryRegistryException 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 3 with FactoryRegistryException

use of org.geotools.util.factory.FactoryRegistryException in project geowave by locationtech.

the class GeoWaveGrpcVectorService method spatialQuery.

@Override
public void spatialQuery(final SpatialQueryParametersProtos request, final StreamObserver<FeatureProtos> responseObserver) {
    final String storeName = request.getBaseParams().getStoreName();
    final StoreLoader storeLoader = new StoreLoader(storeName);
    String typeName = request.getBaseParams().getTypeName();
    String indexName = request.getBaseParams().getIndexName();
    VectorQueryBuilder bldr = VectorQueryBuilder.newBuilder();
    if (typeName.equalsIgnoreCase("")) {
        typeName = null;
    } else {
        bldr = bldr.addTypeName(typeName);
    }
    if (indexName.equalsIgnoreCase("")) {
        indexName = null;
    } else {
        bldr = bldr.indexName(indexName);
    }
    // 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();
    Geometry queryGeom = null;
    try {
        queryGeom = new WKBReader(JTSFactoryFinder.getGeometryFactory()).read(request.getGeometry().toByteArray());
    } 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(bldr.constraintsFactory().spatialTemporalConstraints().spatialConstraints(queryGeom).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) ByteString(com.google.protobuf.ByteString) WKBReader(org.locationtech.jts.io.WKBReader) SimpleFeature(org.opengis.feature.simple.SimpleFeature) 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 4 with FactoryRegistryException

use of org.geotools.util.factory.FactoryRegistryException in project geowave by locationtech.

the class CustomAdapterExample method querySpatial.

private void querySpatial() {
    // constraints when querying
    try {
        // This bounding box represents approximately Europe, so only the European POIs will be
        // queried
        final String queryPolygonDefinition = "POLYGON (( " + "-10.55 35.96, " + "-10.55 71.30, " + "56.16 71.30, " + "56.16 35.96, " + "-10.55 35.96" + "))";
        final Geometry queryPolygon = new WKTReader(JTSFactoryFinder.getGeometryFactory()).read(queryPolygonDefinition);
        final SpatialTemporalConstraintsBuilder spatialConstraintsBuilder = new SpatialTemporalConstraintsBuilderImpl();
        final Query<POI> query = QueryBuilder.newBuilder(POI.class).addTypeName(adapter.getTypeName()).indexName(spatialIndex.getName()).constraints(spatialConstraintsBuilder.spatialConstraints(queryPolygon).build()).build();
        System.out.println("Executing query, expecting to match Roman Colosseum and Eiffel Tower...");
        try (final CloseableIterator<POI> iterator = dataStore.query(query)) {
            while (iterator.hasNext()) {
                System.out.println("Query match: " + iterator.next().getName());
            }
        }
    } catch (FactoryRegistryException | ParseException e) {
    }
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) SpatialTemporalConstraintsBuilder(org.locationtech.geowave.core.geotime.store.query.api.SpatialTemporalConstraintsBuilder) FactoryRegistryException(org.geotools.util.factory.FactoryRegistryException) SpatialTemporalConstraintsBuilderImpl(org.locationtech.geowave.core.geotime.store.query.SpatialTemporalConstraintsBuilderImpl) ParseException(org.locationtech.jts.io.ParseException) WKTReader(org.locationtech.jts.io.WKTReader)

Aggregations

FactoryRegistryException (org.geotools.util.factory.FactoryRegistryException)4 Geometry (org.locationtech.jts.geom.Geometry)4 ParameterException (com.beust.jcommander.ParameterException)2 ByteString (com.google.protobuf.ByteString)2 GeoWaveGTDataStore (org.locationtech.geowave.adapter.vector.plugin.GeoWaveGTDataStore)2 SpatialTemporalConstraintsBuilderImpl (org.locationtech.geowave.core.geotime.store.query.SpatialTemporalConstraintsBuilderImpl)2 SpatialTemporalConstraintsBuilder (org.locationtech.geowave.core.geotime.store.query.api.SpatialTemporalConstraintsBuilder)2 VectorQueryBuilder (org.locationtech.geowave.core.geotime.store.query.api.VectorQueryBuilder)2 DataStore (org.locationtech.geowave.core.store.api.DataStore)2 StoreLoader (org.locationtech.geowave.core.store.cli.store.StoreLoader)2 FeatureAttributeProtos (org.locationtech.geowave.service.grpc.protobuf.FeatureAttributeProtos)2 FeatureProtos (org.locationtech.geowave.service.grpc.protobuf.FeatureProtos)2 ParseException (org.locationtech.jts.io.ParseException)2 WKBReader (org.locationtech.jts.io.WKBReader)2 WKTReader (org.locationtech.jts.io.WKTReader)2 SimpleFeature (org.opengis.feature.simple.SimpleFeature)2 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)2 QueryConstraints (org.locationtech.geowave.core.store.query.constraints.QueryConstraints)1 TemporalConstraintsProtos (org.locationtech.geowave.service.grpc.protobuf.TemporalConstraintsProtos)1