use of com.vividsolutions.jts.io.WKBReader in project teiid by teiid.
the class GeometryUtils method getGeometry.
public static Geometry getGeometry(InputStream is1, Integer srid, boolean allowEwkb) throws FunctionExecutionException {
try {
WKBReader reader = new WKBReader();
Geometry jtsGeom = reader.read(new InputStreamInStream(is1));
if (!allowEwkb && (jtsGeom.getSRID() != GeometryType.UNKNOWN_SRID || (jtsGeom.getCoordinate() != null && !Double.isNaN(jtsGeom.getCoordinate().z)))) {
// $NON-NLS-1$
throw new FunctionExecutionException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31160, "EWKB"));
}
if (srid != null) {
jtsGeom.setSRID(srid);
}
return jtsGeom;
} catch (ParseException e) {
throw new FunctionExecutionException(e);
} catch (IOException e) {
throw new FunctionExecutionException(e);
} finally {
if (is1 != null) {
try {
is1.close();
} catch (IOException e) {
}
}
}
}
use of com.vividsolutions.jts.io.WKBReader 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.WKBReader 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