Search in sources :

Example 1 with ContentFeatureCollection

use of org.geotools.data.store.ContentFeatureCollection in project polymap4-core by Polymap4.

the class PipelineReadTest method testProjection.

@Test
public void testProjection() throws IOException {
    Query query = new Query(null, Filter.INCLUDE, new String[] { "the_geom" });
    ContentFeatureCollection features = pipeDs.getFeatureSource().getFeatures(query);
    SimpleFeatureType schema = features.getSchema();
    assertEquals(1, schema.getAttributeCount());
    assertEquals(1, schema.getDescriptors().size());
    assertEquals("the_geom", schema.getAttributeDescriptors().get(0).getLocalName());
    checkAll(features, feature -> {
        assertEquals(1, feature.getProperties().size());
        assertEquals("the_geom", feature.getDefaultGeometryProperty().getName().getLocalPart());
    });
}
Also used : ContentFeatureCollection(org.geotools.data.store.ContentFeatureCollection) Query(org.geotools.data.Query) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Test(org.junit.Test)

Example 2 with ContentFeatureCollection

use of org.geotools.data.store.ContentFeatureCollection 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

ContentFeatureCollection (org.geotools.data.store.ContentFeatureCollection)2 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)2 ParameterException (com.beust.jcommander.ParameterException)1 ByteString (com.google.protobuf.ByteString)1 IOException (java.io.IOException)1 Query (org.geotools.data.Query)1 SimpleFeatureIterator (org.geotools.data.simple.SimpleFeatureIterator)1 CQLException (org.geotools.filter.text.cql2.CQLException)1 Test (org.junit.Test)1 GeoWaveGTDataStore (org.locationtech.geowave.adapter.vector.plugin.GeoWaveGTDataStore)1 GeoWavePluginConfig (org.locationtech.geowave.adapter.vector.plugin.GeoWavePluginConfig)1 GeoWavePluginException (org.locationtech.geowave.adapter.vector.plugin.GeoWavePluginException)1 StoreLoader (org.locationtech.geowave.core.store.cli.store.StoreLoader)1 FeatureAttributeProtos (org.locationtech.geowave.service.grpc.protobuf.FeatureAttributeProtos)1 FeatureProtos (org.locationtech.geowave.service.grpc.protobuf.FeatureProtos)1 SimpleFeature (org.opengis.feature.simple.SimpleFeature)1 Filter (org.opengis.filter.Filter)1