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