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