Search in sources :

Example 36 with ParseException

use of com.vividsolutions.jts.io.ParseException in project incubator-rya by apache.

the class GeoWaveGeoIndexer method deleteStatements.

private void deleteStatements(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);
            }
        }
    }
    // remove this feature collection from the store
    if (!featureCollection.isEmpty()) {
        final Set<Identifier> featureIds = new HashSet<Identifier>();
        final FilterFactory filterFactory = CommonFactoryFinder.getFilterFactory(null);
        final Set<String> stringIds = DataUtilities.fidSet(featureCollection);
        for (final String id : stringIds) {
            featureIds.add(filterFactory.featureId(id));
        }
        final String filterString = stringIds.stream().collect(Collectors.joining("','", "'", "'"));
        Filter filter = null;
        try {
            filter = ECQL.toFilter(GEO_ID_ATTRIBUTE + " IN (" + filterString + ")", filterFactory);
        } catch (final CQLException e) {
            logger.error("Unable to generate filter for deleting the statement.", e);
        }
        featureStore.removeFeatures(filter);
    }
}
Also used : RyaStatement(org.apache.rya.api.domain.RyaStatement) Statement(org.openrdf.model.Statement) RyaStatement(org.apache.rya.api.domain.RyaStatement) SimpleFeature(org.opengis.feature.simple.SimpleFeature) FilterFactory(org.opengis.filter.FilterFactory) Identifier(org.opengis.filter.identity.Identifier) Filter(org.opengis.filter.Filter) Literal(org.openrdf.model.Literal) ParseException(com.vividsolutions.jts.io.ParseException) CQLException(org.geotools.filter.text.cql2.CQLException) DefaultFeatureCollection(org.geotools.feature.DefaultFeatureCollection) HashSet(java.util.HashSet)

Example 37 with ParseException

use of com.vividsolutions.jts.io.ParseException in project incubator-rya by apache.

the class GeoTemporalMongoDBStorageStrategy method serialize.

@Override
public DBObject serialize(final RyaStatement ryaStatement) {
    final BasicDBObjectBuilder builder = BasicDBObjectBuilder.start("_id", ryaStatement.getSubject().hashCode());
    final URI obj = ryaStatement.getObject().getDataType();
    if (obj.equals(GeoConstants.GEO_AS_WKT) || obj.equals(GeoConstants.GEO_AS_GML) || obj.equals(GeoConstants.XMLSCHEMA_OGC_GML) || obj.equals(GeoConstants.XMLSCHEMA_OGC_WKT)) {
        try {
            final Statement statement = RyaToRdfConversions.convertStatement(ryaStatement);
            final Geometry geo = GeoParseUtils.getGeometry(statement, new GmlParser());
            if (geo.getNumPoints() > 1) {
                builder.add(GEO_KEY, geoStrategy.getCorrespondingPoints(geo));
            } else {
                builder.add(GEO_KEY, geoStrategy.getDBPoint(geo));
            }
        } catch (final ParseException e) {
            LOG.error("Could not create geometry for statement " + ryaStatement, e);
            return null;
        }
    } else {
        builder.add(TIME_KEY, temporalStrategy.getTimeValue(ryaStatement.getObject().getData()));
    }
    return builder.get();
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) BasicDBObjectBuilder(com.mongodb.BasicDBObjectBuilder) Statement(org.openrdf.model.Statement) RyaStatement(org.apache.rya.api.domain.RyaStatement) GmlParser(org.apache.rya.indexing.mongodb.geo.GmlParser) ParseException(com.vividsolutions.jts.io.ParseException) URI(org.openrdf.model.URI)

Example 38 with ParseException

use of com.vividsolutions.jts.io.ParseException in project incubator-rya by apache.

the class GeoParseUtils method getLiteral.

public static Literal getLiteral(final Statement statement) throws ParseException {
    final org.openrdf.model.Value v = statement.getObject();
    if (!(v instanceof Literal)) {
        throw new ParseException("Statement does not contain Literal: " + statement.toString());
    }
    final Literal lit = (Literal) v;
    return lit;
}
Also used : Value(org.openrdf.model.Value) Literal(org.openrdf.model.Literal) ParseException(com.vividsolutions.jts.io.ParseException)

Example 39 with ParseException

use of com.vividsolutions.jts.io.ParseException in project activityinfo by bedatadriven.

the class FormResource method updateGeometry.

@POST
@Path("record/{recordId}/field/{fieldId}/geometry")
public Response updateGeometry(@PathParam("recordId") String recordId, @PathParam("fieldId") String fieldId, byte[] binaryBody) {
    // Parse the Geometry
    WKBReader reader = new WKBReader(new GeometryFactory());
    Geometry geometry;
    try {
        geometry = reader.read(binaryBody);
    } catch (ParseException e) {
        return Response.status(Response.Status.BAD_REQUEST).entity("Could not parse WKB geometry: " + e.getMessage()).build();
    }
    geometry.normalize();
    if (!geometry.isValid()) {
        return Response.status(Response.Status.BAD_REQUEST).entity(geometry.getGeometryType() + " is not valid").build();
    }
    // Check first to see if this form exists
    Optional<FormStorage> storage = backend.getStorage().getForm(formId);
    if (!storage.isPresent()) {
        return Response.status(Response.Status.NOT_FOUND).entity("Form " + formId + " does not exist.").build();
    }
    // Find the field and verify that it's a GeoArea type
    FormField field;
    try {
        field = storage.get().getFormClass().getField(ResourceId.valueOf(fieldId));
    } catch (IllegalArgumentException e) {
        return Response.status(Response.Status.NOT_FOUND).entity("Record " + recordId + " does not exist.").build();
    }
    if (!(field.getType() instanceof GeoAreaType)) {
        return Response.status(Response.Status.BAD_REQUEST).entity("Field " + fieldId + " is not a GeoArea type").build();
    }
    try {
        storage.get().updateGeometry(ResourceId.valueOf(recordId), ResourceId.valueOf(fieldId), geometry);
    } catch (Exception e) {
        LOGGER.log(Level.SEVERE, "Failed to update geometry for record " + recordId, e);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
    }
    return Response.ok().build();
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) VersionedFormStorage(org.activityinfo.store.spi.VersionedFormStorage) FormStorage(org.activityinfo.store.spi.FormStorage) GeoAreaType(org.activityinfo.model.type.geo.GeoAreaType) ParseException(com.vividsolutions.jts.io.ParseException) WKBReader(com.vividsolutions.jts.io.WKBReader) NotFoundException(com.sun.jersey.api.NotFoundException) SQLException(java.sql.SQLException) InvalidUpdateException(org.activityinfo.store.query.server.InvalidUpdateException) ParseException(com.vividsolutions.jts.io.ParseException)

Example 40 with ParseException

use of com.vividsolutions.jts.io.ParseException in project activityinfo by bedatadriven.

the class WkbGeometryProvider method getGeometries.

@Override
@Timed(name = "mapping.fetch_geometry")
public List<AdminGeo> getGeometries(int adminLevelId) {
    try {
        List<AdminGeo> list = Lists.newArrayList();
        DataInputStream in = new DataInputStream(openWkb(adminLevelId));
        WKBReader wkbReader = new WKBReader(geometryFactory);
        int count = in.readInt();
        for (int i = 0; i != count; ++i) {
            int id = in.readInt();
            LOGGER.info("Reading geometry for admin entity " + id);
            Geometry geometry = wkbReader.read(new DataInputInStream(in));
            list.add(new AdminGeo(id, geometry));
        }
        return list;
    } catch (IOException | ParseException e) {
        throw new RuntimeException(e);
    }
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) IOException(java.io.IOException) ParseException(com.vividsolutions.jts.io.ParseException) DataInputStream(java.io.DataInputStream) WKBReader(com.vividsolutions.jts.io.WKBReader) Timed(org.activityinfo.server.util.monitoring.Timed)

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