use of com.vividsolutions.jts.io.ParseException in project incubator-rya by apache.
the class GeoMongoDBStorageStrategy method serialize.
@Override
public DBObject serialize(final RyaStatement ryaStatement) {
// write the statement data to the fields
try {
final Statement statement = RyaToRdfConversions.convertStatement(ryaStatement);
final Geometry geo = (new WKTReader()).read(GeoParseUtils.getWellKnownText(statement));
if (geo == null) {
LOG.error("Failed to parse geo statement: " + statement.toString());
return null;
}
final BasicDBObject base = (BasicDBObject) super.serialize(ryaStatement);
if (geo.getNumPoints() > 1) {
base.append(GEO, getCorrespondingPoints(geo));
} else {
base.append(GEO, getDBPoint(geo));
}
return base;
} catch (final ParseException e) {
LOG.error("Could not create geometry for statement " + ryaStatement, e);
return null;
}
}
use of com.vividsolutions.jts.io.ParseException in project incubator-rya by apache.
the class GeoWaveGeoIndexer 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);
// GeoWave does not support querying based on a user generated feature ID
// So, we create a separate ID attribute that it can query on.
newFeature.setAttribute(GEO_ID_ATTRIBUTE, statementId);
// 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 com.vividsolutions.jts.io.ParseException in project incubator-rya by apache.
the class GeoTemporalMongoDBStorageStrategy method getGeoObjs.
private DBObject[] getGeoObjs(final Collection<IndexingExpr> geoFilters) {
final List<DBObject> objs = new ArrayList<>();
geoFilters.forEach(filter -> {
final GeoPolicy policy = GeoPolicy.fromURI(filter.getFunction());
final WKTReader reader = new WKTReader();
final String geoStr = ((Value) filter.getArguments()[0]).stringValue();
try {
// This method is what is used in the GeoIndexer.
final Geometry geo = reader.read(geoStr);
objs.add(getGeoObject(geo, policy));
} catch (final GeoTemporalIndexException | UnsupportedOperationException | ParseException e) {
LOG.error("Unable to parse '" + geoStr + "'.", e);
}
});
return objs.toArray(new DBObject[] {});
}
use of com.vividsolutions.jts.io.ParseException in project incubator-rya by apache.
the class MongoGeoTemporalIndexer method updateEvent.
private void updateEvent(final RyaURI subject, final RyaStatement statement) throws IndexingException, ParseException {
final EventStorage eventStore = events.get();
checkState(events != null, "Must set this indexers configuration before storing statements.");
new EventUpdater(eventStore).update(subject, old -> {
final Event.Builder updated;
if (!old.isPresent()) {
updated = Event.builder().setSubject(subject);
} else {
updated = Event.builder(old.get());
}
final URI pred = statement.getObject().getDataType();
if (pred.equals(GeoConstants.GEO_AS_WKT) || pred.equals(GeoConstants.GEO_AS_GML) || pred.equals(GeoConstants.XMLSCHEMA_OGC_WKT) || pred.equals(GeoConstants.XMLSCHEMA_OGC_GML)) {
// is geo
try {
final Statement geoStatement = RyaToRdfConversions.convertStatement(statement);
final Geometry geometry = GeoParseUtils.getGeometry(geoStatement, new GmlParser());
updated.setGeometry(geometry);
} catch (final ParseException e) {
LOG.error(e.getMessage(), e);
}
} else {
// is time
final String dateTime = statement.getObject().getData();
final Matcher matcher = TemporalInstantRfc3339.PATTERN.matcher(dateTime);
if (matcher.find()) {
final TemporalInterval interval = TemporalInstantRfc3339.parseInterval(dateTime);
updated.setTemporalInterval(interval);
} else {
final TemporalInstant instant = new TemporalInstantRfc3339(DateTime.parse(dateTime));
updated.setTemporalInstant(instant);
}
}
return Optional.of(updated.build());
});
}
use of com.vividsolutions.jts.io.ParseException in project hibernate-orm by hibernate.
the class HANAExpectationsFactory method getTestPolygon.
@Override
public Polygon getTestPolygon() {
WKTReader reader = new WKTReader();
try {
Polygon polygon = (Polygon) reader.read("POLYGON((0 0, 50 0, 90 90, 100 0, 0 0))");
polygon.setSRID(getTestSrid());
return polygon;
} catch (ParseException e) {
throw new RuntimeException(e);
}
}
Aggregations