Search in sources :

Example 96 with SimpleFeature

use of org.opengis.feature.simple.SimpleFeature in project incubator-rya by apache.

the class GeoMesaGeoIndexer method storeStatements.

@Override
public void storeStatements(final Collection<RyaStatement> ryaStatements) throws IOException {
    // create a feature collection
    final DefaultFeatureCollection featureCollection = new DefaultFeatureCollection();
    for (final RyaStatement ryaStatement : ryaStatements) {
        final Statement statement = RyaToRdfConversions.convertStatement(ryaStatement);
        // if the predicate list is empty, accept all predicates.
        // Otherwise, make sure the predicate is on the "valid" list
        final boolean isValidPredicate = validPredicates.isEmpty() || validPredicates.contains(statement.getPredicate());
        if (isValidPredicate && (statement.getObject() instanceof Literal)) {
            try {
                final SimpleFeature feature = createFeature(featureType, statement);
                featureCollection.add(feature);
            } catch (final ParseException e) {
                logger.warn("Error getting geo from statement: " + statement.toString(), e);
            }
        }
    }
    // write this feature collection to the store
    if (!featureCollection.isEmpty()) {
        featureStore.addFeatures(featureCollection);
    }
}
Also used : RyaStatement(org.apache.rya.api.domain.RyaStatement) Statement(org.openrdf.model.Statement) Literal(org.openrdf.model.Literal) RyaStatement(org.apache.rya.api.domain.RyaStatement) ParseException(com.vividsolutions.jts.io.ParseException) DefaultFeatureCollection(org.geotools.feature.DefaultFeatureCollection) SimpleFeature(org.opengis.feature.simple.SimpleFeature)

Example 97 with SimpleFeature

use of org.opengis.feature.simple.SimpleFeature in project incubator-rya by apache.

the class GeoMesaGeoIndexer method createFeature.

private static SimpleFeature createFeature(final SimpleFeatureType featureType, final Statement statement) throws ParseException {
    final String subject = StatementSerializer.writeSubject(statement);
    final String predicate = StatementSerializer.writePredicate(statement);
    final String object = StatementSerializer.writeObject(statement);
    final String context = StatementSerializer.writeContext(statement);
    // create the feature
    final Object[] noValues = {};
    // create the hash
    final String statementId = Md5Hash.md5Base64(StatementSerializer.writeStatement(statement));
    final SimpleFeature newFeature = SimpleFeatureBuilder.build(featureType, noValues, statementId);
    // write the statement data to the fields
    final Geometry geom = GeoParseUtils.getGeometry(statement, new GmlParser());
    if (geom == null || geom.isEmpty() || !geom.isValid()) {
        throw new ParseException("Could not create geometry for statement " + statement);
    }
    newFeature.setDefaultGeometry(geom);
    newFeature.setAttribute(SUBJECT_ATTRIBUTE, subject);
    newFeature.setAttribute(PREDICATE_ATTRIBUTE, predicate);
    newFeature.setAttribute(OBJECT_ATTRIBUTE, object);
    newFeature.setAttribute(CONTEXT_ATTRIBUTE, context);
    // preserve the ID that we created for this feature
    // (set the hint to FALSE to have GeoTools generate IDs)
    newFeature.getUserData().put(Hints.USE_PROVIDED_FID, java.lang.Boolean.TRUE);
    return newFeature;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) ParseException(com.vividsolutions.jts.io.ParseException) SimpleFeature(org.opengis.feature.simple.SimpleFeature)

Example 98 with SimpleFeature

use of org.opengis.feature.simple.SimpleFeature in project incubator-rya by apache.

the class GeoMesaGeoIndexer method getIteratorWrapper.

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

        private FeatureIterator<SimpleFeature> featureIterator = null;

        FeatureIterator<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 Query query = new Query(featureType.getTypeName(), cqlFilter);
                try {
                    featureIterator = featureSource.getFeatures(query).features();
                } catch (final IOException e) {
                    logger.error("Error performing query: " + LogUtils.clean(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 String contextString = feature.getAttribute(CONTEXT_ATTRIBUTE).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 {
            getIterator().close();
        }
    };
}
Also used : CloseableIteration(info.aduna.iteration.CloseableIteration) FeatureIterator(org.geotools.feature.FeatureIterator) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) Query(org.geotools.data.Query) NearQuery(org.apache.rya.indexing.accumulo.geo.GeoTupleSet.GeoSearchFunctionFactory.NearQuery) Filter(org.opengis.filter.Filter) RyaStatement(org.apache.rya.api.domain.RyaStatement) Statement(org.openrdf.model.Statement) CQLException(org.geotools.filter.text.cql2.CQLException) IOException(java.io.IOException) SimpleFeature(org.opengis.feature.simple.SimpleFeature)

Example 99 with SimpleFeature

use of org.opengis.feature.simple.SimpleFeature in project incubator-rya by apache.

the class GeoWaveFeatureReaderTest method testBBOX.

@Test
public void testBBOX() throws IllegalArgumentException, NoSuchElementException, IOException {
    final FilterFactoryImpl factory = new FilterFactoryImpl();
    final Query query = new Query("GeoWaveFeatureReaderTest", factory.bbox("", -180, -90, 180, 90, "EPSG:4326"), new String[] { "geometry", "pid" });
    final FeatureReader<SimpleFeatureType, SimpleFeature> reader = dataStore.getFeatureReader(query, Transaction.AUTO_COMMIT);
    int count = 0;
    while (reader.hasNext()) {
        final SimpleFeature feature = reader.next();
        assertTrue(fids.contains(feature.getID()));
        count++;
    }
    assertTrue(count > 0);
}
Also used : Query(org.geotools.data.Query) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Test(org.junit.Test)

Example 100 with SimpleFeature

use of org.opengis.feature.simple.SimpleFeature in project incubator-rya by apache.

the class GeoWaveFeatureReaderTest method testMin.

@Test
public void testMin() throws IllegalArgumentException, NoSuchElementException, IOException {
    final FeatureReader<SimpleFeatureType, SimpleFeature> reader = dataStore.getFeatureReader(query, Transaction.AUTO_COMMIT);
    final MinVisitor visitor = new MinVisitor("start", type);
    unwrapDelegatingFeatureReader(reader).getFeatureCollection().accepts(visitor, null);
    assertTrue(visitor.getMin().equals(stime));
}
Also used : SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) MinVisitor(org.geotools.feature.visitor.MinVisitor) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Test(org.junit.Test)

Aggregations

SimpleFeature (org.opengis.feature.simple.SimpleFeature)147 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)73 Test (org.junit.Test)45 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)35 IOException (java.io.IOException)34 ArrayList (java.util.ArrayList)26 SimpleFeatureIterator (org.geotools.data.simple.SimpleFeatureIterator)25 Geometry (com.vividsolutions.jts.geom.Geometry)23 Coordinate (com.vividsolutions.jts.geom.Coordinate)22 SimpleFeatureCollection (org.geotools.data.simple.SimpleFeatureCollection)20 File (java.io.File)19 HashMap (java.util.HashMap)18 Query (org.geotools.data.Query)18 RevFeature (org.locationtech.geogig.api.RevFeature)17 DefaultTransaction (org.geotools.data.DefaultTransaction)16 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)16 Optional (com.google.common.base.Optional)15 SimpleFeatureSource (org.geotools.data.simple.SimpleFeatureSource)15 Filter (org.opengis.filter.Filter)15 Transaction (org.geotools.data.Transaction)14