Search in sources :

Example 11 with ParseException

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;
    }
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) BasicDBObject(com.mongodb.BasicDBObject) Statement(org.openrdf.model.Statement) RyaStatement(org.apache.rya.api.domain.RyaStatement) ParseException(com.vividsolutions.jts.io.ParseException) WKTReader(com.vividsolutions.jts.io.WKTReader)

Example 12 with ParseException

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;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) ParseException(com.vividsolutions.jts.io.ParseException) SimpleFeature(org.opengis.feature.simple.SimpleFeature)

Example 13 with ParseException

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[] {});
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) GeoPolicy(org.apache.rya.indexing.geotemporal.GeoTemporalIndexer.GeoPolicy) GeoTemporalIndexException(org.apache.rya.indexing.geotemporal.GeoTemporalIndexException) ArrayList(java.util.ArrayList) Value(org.openrdf.model.Value) ParseException(com.vividsolutions.jts.io.ParseException) WKTReader(com.vividsolutions.jts.io.WKTReader) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject)

Example 14 with ParseException

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());
    });
}
Also used : Matcher(java.util.regex.Matcher) Statement(org.openrdf.model.Statement) RyaStatement(org.apache.rya.api.domain.RyaStatement) TemporalInstantRfc3339(org.apache.rya.indexing.TemporalInstantRfc3339) GmlParser(org.apache.rya.indexing.mongodb.geo.GmlParser) TemporalInstant(org.apache.rya.indexing.TemporalInstant) URI(org.openrdf.model.URI) RyaURI(org.apache.rya.api.domain.RyaURI) Geometry(com.vividsolutions.jts.geom.Geometry) Event(org.apache.rya.indexing.geotemporal.model.Event) ParseException(com.vividsolutions.jts.io.ParseException) TemporalInterval(org.apache.rya.indexing.TemporalInterval) EventStorage(org.apache.rya.indexing.geotemporal.storage.EventStorage)

Example 15 with ParseException

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);
    }
}
Also used : ParseException(com.vividsolutions.jts.io.ParseException) WKTReader(com.vividsolutions.jts.io.WKTReader) Polygon(com.vividsolutions.jts.geom.Polygon)

Aggregations

ParseException (com.vividsolutions.jts.io.ParseException)64 Geometry (com.vividsolutions.jts.geom.Geometry)28 WKTReader (com.vividsolutions.jts.io.WKTReader)21 ConverterException (ch.ehi.ili2db.converter.ConverterException)17 RyaStatement (org.apache.rya.api.domain.RyaStatement)7 SimpleFeature (org.opengis.feature.simple.SimpleFeature)7 Statement (org.openrdf.model.Statement)7 Wkb2iox (ch.interlis.iox_j.wkb.Wkb2iox)6 IsValidOp (com.vividsolutions.jts.operation.valid.IsValidOp)6 ServiceException (eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException)6 IoxException (ch.interlis.iox.IoxException)5 MapLayer (au.org.emii.portal.menu.MapLayer)4 WKBReader (com.vividsolutions.jts.io.WKBReader)4 IOException (java.io.IOException)4 Literal (org.openrdf.model.Literal)4 Coordinate (com.vividsolutions.jts.geom.Coordinate)3 Point (com.vividsolutions.jts.geom.Point)3 Polygon (com.vividsolutions.jts.geom.Polygon)3 WKTWriter (com.vividsolutions.jts.io.WKTWriter)3 SQLException (java.sql.SQLException)3