Search in sources :

Example 1 with QueryOptions

use of mil.nga.giat.geowave.core.store.query.QueryOptions in project incubator-rya by apache.

the class GeoWaveGTQueryTest method executePolygonQueryTest.

@Test
public void executePolygonQueryTest() throws IOException {
    System.out.println("Constructing polygon for the area contained by [Baltimore, MD; Richmond, VA; Harrisonburg, VA].");
    final Polygon polygon = GeometryUtils.GEOMETRY_FACTORY.createPolygon(new Coordinate[] { BALTIMORE, RICHMOND, HARRISONBURG, BALTIMORE });
    System.out.println("Executing query, expecting to match ALL points...");
    final QueryOptions queryOptions = new QueryOptions(ADAPTER, INDEX);
    final SpatialQuery spatialQuery = new SpatialQuery(polygon);
    /*
         * NOTICE: In this query, the adapter is added to the query options. If
         * an index has data from more than one adapter, the data associated
         * with a specific adapter can be selected.
         */
    try (final CloseableIterator<SimpleFeature> closableIterator = dataStore.query(queryOptions, spatialQuery)) {
        int count = 0;
        while (closableIterator.hasNext()) {
            System.out.println("Query match: " + closableIterator.next().getID());
            count++;
        }
        System.out.println("executePolygonQueryTest count: " + count);
        // Should match "FedEx Field", "Washington Monument", and "White House"
        assertEquals(3, count);
    }
}
Also used : SpatialQuery(mil.nga.giat.geowave.core.geotime.store.query.SpatialQuery) Polygon(com.vividsolutions.jts.geom.Polygon) QueryOptions(mil.nga.giat.geowave.core.store.query.QueryOptions) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Test(org.junit.Test)

Example 2 with QueryOptions

use of mil.nga.giat.geowave.core.store.query.QueryOptions in project incubator-rya by apache.

the class GeoWaveGTQueryTest method executeBoundingBoxQueryTest.

@Test
public void executeBoundingBoxQueryTest() throws IOException {
    System.out.println("Constructing bounding box for the area contained by [Baltimore, MD and Richmond, VA.");
    final Geometry boundingBox = GeometryUtils.GEOMETRY_FACTORY.toGeometry(new Envelope(BALTIMORE, RICHMOND));
    System.out.println("Executing query, expecting to match ALL points...");
    final QueryOptions queryOptions = new QueryOptions(ADAPTER, INDEX);
    final SpatialQuery spatialQuery = new SpatialQuery(boundingBox);
    try (final CloseableIterator<SimpleFeature> iterator = dataStore.query(queryOptions, spatialQuery)) {
        int count = 0;
        while (iterator.hasNext()) {
            System.out.println("Query match: " + iterator.next().getID());
            count++;
        }
        System.out.println("executeBoundingBoxQueryTest count: " + count);
        // Should match "FedEx Field", "Washington Monument", and "White House"
        assertEquals(3, count);
    }
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) SpatialQuery(mil.nga.giat.geowave.core.geotime.store.query.SpatialQuery) Envelope(com.vividsolutions.jts.geom.Envelope) QueryOptions(mil.nga.giat.geowave.core.store.query.QueryOptions) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Test(org.junit.Test)

Example 3 with QueryOptions

use of mil.nga.giat.geowave.core.store.query.QueryOptions in project incubator-rya by apache.

the class GeoWaveGTQueryTest method executeCQLQueryTest.

@Test
public void executeCQLQueryTest() throws IOException, CQLException {
    System.out.println("Executing query, expecting to match two points...");
    final Filter cqlFilter = ECQL.toFilter("BBOX(geometry,-77.6167,38.6833,-76.6,38.9200) and locationName like 'W%'");
    final QueryOptions queryOptions = new QueryOptions(ADAPTER, INDEX);
    final CQLQuery cqlQuery = new CQLQuery(null, cqlFilter, ADAPTER);
    try (final CloseableIterator<SimpleFeature> iterator = dataStore.query(queryOptions, cqlQuery)) {
        int count = 0;
        while (iterator.hasNext()) {
            System.out.println("Query match: " + iterator.next().getID());
            count++;
        }
        System.out.println("executeCQLQueryTest count: " + count);
        // Should match "Washington Monument" and "White House"
        assertEquals(2, count);
    }
}
Also used : Filter(org.opengis.filter.Filter) CQLQuery(mil.nga.giat.geowave.adapter.vector.query.cql.CQLQuery) QueryOptions(mil.nga.giat.geowave.core.store.query.QueryOptions) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Test(org.junit.Test)

Example 4 with QueryOptions

use of mil.nga.giat.geowave.core.store.query.QueryOptions in project incubator-rya by apache.

the class GeoWaveGeoIndexer method getIteratorWrapper.

private CloseableIteration<Statement, QueryEvaluationException> getIteratorWrapper(final String filterString) {
    return new CloseableIteration<Statement, QueryEvaluationException>() {

        private CloseableIterator<SimpleFeature> featureIterator = null;

        CloseableIterator<SimpleFeature> getIterator() throws QueryEvaluationException {
            if (featureIterator == null) {
                Filter cqlFilter;
                try {
                    cqlFilter = ECQL.toFilter(filterString);
                } catch (final CQLException e) {
                    logger.error("Error parsing query: " + LogUtils.clean(filterString), e);
                    throw new QueryEvaluationException(e);
                }
                final CQLQuery cqlQuery = new CQLQuery(null, cqlFilter, featureDataAdapter);
                final QueryOptions queryOptions = new QueryOptions(featureDataAdapter, index);
                try {
                    featureIterator = geoWaveDataStore.query(queryOptions, cqlQuery);
                } catch (final Exception e) {
                    logger.error("Error performing query: " + filterString, e);
                    throw new QueryEvaluationException(e);
                }
            }
            return featureIterator;
        }

        @Override
        public boolean hasNext() throws QueryEvaluationException {
            return getIterator().hasNext();
        }

        @Override
        public Statement next() throws QueryEvaluationException {
            final SimpleFeature feature = getIterator().next();
            final String subjectString = feature.getAttribute(SUBJECT_ATTRIBUTE).toString();
            final String predicateString = feature.getAttribute(PREDICATE_ATTRIBUTE).toString();
            final String objectString = feature.getAttribute(OBJECT_ATTRIBUTE).toString();
            final Object context = feature.getAttribute(CONTEXT_ATTRIBUTE);
            final String contextString = context != null ? context.toString() : "";
            final Statement statement = StatementSerializer.readStatement(subjectString, predicateString, objectString, contextString);
            return statement;
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException("Remove not implemented");
        }

        @Override
        public void close() throws QueryEvaluationException {
            try {
                getIterator().close();
            } catch (final IOException e) {
                throw new QueryEvaluationException(e);
            }
        }
    };
}
Also used : CloseableIterator(mil.nga.giat.geowave.core.store.CloseableIterator) RyaStatement(org.apache.rya.api.domain.RyaStatement) Statement(org.openrdf.model.Statement) CQLQuery(mil.nga.giat.geowave.adapter.vector.query.cql.CQLQuery) IOException(java.io.IOException) QueryOptions(mil.nga.giat.geowave.core.store.query.QueryOptions) SimpleFeature(org.opengis.feature.simple.SimpleFeature) GeoWavePluginException(mil.nga.giat.geowave.adapter.vector.plugin.GeoWavePluginException) ParseException(com.vividsolutions.jts.io.ParseException) SchemaException(org.geotools.feature.SchemaException) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) CQLException(org.geotools.filter.text.cql2.CQLException) IOException(java.io.IOException) CloseableIteration(info.aduna.iteration.CloseableIteration) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) Filter(org.opengis.filter.Filter) CQLException(org.geotools.filter.text.cql2.CQLException)

Aggregations

QueryOptions (mil.nga.giat.geowave.core.store.query.QueryOptions)4 SimpleFeature (org.opengis.feature.simple.SimpleFeature)4 Test (org.junit.Test)3 CQLQuery (mil.nga.giat.geowave.adapter.vector.query.cql.CQLQuery)2 SpatialQuery (mil.nga.giat.geowave.core.geotime.store.query.SpatialQuery)2 Filter (org.opengis.filter.Filter)2 Envelope (com.vividsolutions.jts.geom.Envelope)1 Geometry (com.vividsolutions.jts.geom.Geometry)1 Polygon (com.vividsolutions.jts.geom.Polygon)1 ParseException (com.vividsolutions.jts.io.ParseException)1 CloseableIteration (info.aduna.iteration.CloseableIteration)1 IOException (java.io.IOException)1 GeoWavePluginException (mil.nga.giat.geowave.adapter.vector.plugin.GeoWavePluginException)1 CloseableIterator (mil.nga.giat.geowave.core.store.CloseableIterator)1 RyaStatement (org.apache.rya.api.domain.RyaStatement)1 SchemaException (org.geotools.feature.SchemaException)1 CQLException (org.geotools.filter.text.cql2.CQLException)1 Statement (org.openrdf.model.Statement)1 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)1