use of com.vividsolutions.jts.io.ParseException in project alliance by codice.
the class NitfGmtiTransformer method transformTargetLocation.
private void transformTargetLocation(Metacard metacard) {
String locationString = formatTargetLocation(metacard);
try {
LOGGER.debug("Formatted Target Location(s) = {}", locationString);
if (locationString != null) {
// validate the wkt
WKTReader wktReader = new WKTReader(geometryFactory);
Geometry geometry = wktReader.read(locationString);
LOGGER.debug("Setting the metacard attribute [{}, {}]", Core.LOCATION, geometry.toText());
IndexedMtirpbAttribute.INDEXED_TARGET_LOCATION_ATTRIBUTE.getAttributeDescriptors().forEach(descriptor -> setMetacardAttribute(metacard, descriptor.getName(), geometry.toText()));
}
} catch (ParseException e) {
LOGGER.debug(e.getMessage(), e);
}
}
use of com.vividsolutions.jts.io.ParseException in project alliance by codice.
the class ResultDAGConverter method addSpatialGeoRefBoxAttribute.
private static void addSpatialGeoRefBoxAttribute(DirectedAcyclicGraph<Node, Edge> graph, Metacard metacard, ORB orb, List<String> resultAttributes, List<String> addedAttributes, String attribute, Node coverageNode) {
if (shouldAdd(buildAttr(attribute, NsiliConstants.SPATIAL_GEOGRAPHIC_REF_BOX), resultAttributes)) {
Attribute geoAttr = metacard.getAttribute(Core.LOCATION);
if (geoAttr != null) {
String wktGeo = String.valueOf(geoAttr.getValue());
try {
Geometry boundingGeo = WKTUtil.getWKTBoundingRectangle(wktGeo);
Rectangle rect = NsiliGeomUtil.getRectangle(boundingGeo);
addGeomAttribute(graph, coverageNode, NsiliConstants.SPATIAL_GEOGRAPHIC_REF_BOX, rect, orb);
addedAttributes.add(buildAttr(attribute, NsiliConstants.SPATIAL_GEOGRAPHIC_REF_BOX));
} catch (ParseException pe) {
LOGGER.debug("Unable to parse WKT for bounding box: {}", wktGeo, pe);
}
}
}
}
use of com.vividsolutions.jts.io.ParseException in project teiid by teiid.
the class GeometryUtils method snapToGrid.
public static GeometryType snapToGrid(GeometryType geom, double size) throws FunctionExecutionException {
if (size == 0) {
return geom;
}
Geometry g1 = getGeometry(geom);
PrecisionModel precisionModel = new PrecisionModel(1 / size);
GeometryPrecisionReducer reducer = new GeometryPrecisionReducer(precisionModel);
reducer.setPointwise(true);
reducer.setChangePrecisionModel(true);
Geometry result = reducer.reduce(g1);
// since the wkb writer doesn't consider precision, we have to first write/read through wkt
WKTWriter writer = new WKTWriter();
String val = writer.write(result);
WKTReader reader = new WKTReader(GEOMETRY_FACTORY);
try {
result = reader.read(new StringReader(val));
} catch (ParseException e) {
throw new FunctionExecutionException(e);
}
result.setSRID(geom.getSrid());
return getGeometryType(result);
}
use of com.vividsolutions.jts.io.ParseException in project teiid by teiid.
the class GeometryUtils method geometryFromClob.
public static GeometryType geometryFromClob(ClobType wkt, Integer srid, boolean allowEwkt) throws FunctionExecutionException {
Reader r = null;
try {
WKTReader reader = new WKTReader(GEOMETRY_FACTORY);
r = wkt.getCharacterStream();
if (allowEwkt) {
PushbackReader pbr = new PushbackReader(r, 1);
r = pbr;
char[] expected = new char[] { 's', 'r', 'i', 'd', '=' };
int expectedIndex = 0;
StringBuilder sridBuffer = null;
for (int i = 0; i < 100000; i++) {
int charRead = pbr.read();
if (charRead == -1) {
break;
}
if (expectedIndex == expected.length) {
// parse srid
if (sridBuffer == null) {
sridBuffer = new StringBuilder(4);
}
if (charRead == ';') {
if (sridBuffer.length() == 0) {
pbr.unread(charRead);
}
break;
}
sridBuffer.append((char) charRead);
continue;
}
if (expectedIndex == 0 && Character.isWhitespace(charRead)) {
continue;
}
if (expected[expectedIndex] != Character.toLowerCase(charRead)) {
pbr.unread(charRead);
break;
}
expectedIndex++;
}
if (sridBuffer != null) {
srid = Integer.parseInt(sridBuffer.toString());
}
}
Geometry jtsGeometry = reader.read(r);
if (jtsGeometry == null) {
// for some reason io and parse exceptions are caught in their logic if they occur on the first word, then null is returned
throw new FunctionExecutionException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31203));
}
if (!allowEwkt && (jtsGeometry.getSRID() != GeometryType.UNKNOWN_SRID || (jtsGeometry.getCoordinate() != null && !Double.isNaN(jtsGeometry.getCoordinate().z)))) {
// $NON-NLS-1$
throw new FunctionExecutionException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31160, "EWKT"));
}
if (srid == null) {
srid = jtsGeometry.getSRID();
}
return getGeometryType(jtsGeometry, srid);
} catch (ParseException e) {
throw new FunctionExecutionException(e);
} catch (SQLException e) {
throw new FunctionExecutionException(e);
} catch (IOException e) {
throw new FunctionExecutionException(e);
} finally {
if (r != null) {
try {
r.close();
} catch (IOException e) {
}
}
}
}
use of com.vividsolutions.jts.io.ParseException in project tests by datanucleus.
the class JtsGeometryMappingTest method testUserDataMappingWithObject.
public void testUserDataMappingWithObject() throws SQLException, ParseException {
if (!runTestsForDatastore()) {
return;
}
Point point = (Point) wktReader.read("POINT(10 10)");
point.setSRID(-1);
Object userData = new Object();
point.setUserData(userData);
SamplePoint samplePoint;
EntityManager em = emf.createEntityManager();
EntityTransaction tx = em.getTransaction();
try {
tx.begin();
samplePoint = new SamplePoint(11001, "UserDataWithObject", point);
em.persist(samplePoint);
tx.commit();
fail("Persisted spatial field with non-serializable user-data but should have failed");
} catch (Exception e) {
// Expected : should fail since Object is not Serializable
} finally {
if (tx.isActive()) {
tx.rollback();
}
em.close();
}
}
Aggregations