use of com.vividsolutions.jts.io.WKTReader 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.WKTReader 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.WKTReader in project teiid by teiid.
the class TestGeometry method testTransform.
@Test
public void testTransform() throws Exception {
Geometry g0 = new WKTReader().read("POINT(426418.89 4957737.37)");
Geometry g1 = GeometryTransformUtils.transform(g0, // EPSG:32632
"+proj=utm +zone=32 +datum=WGS84 +units=m +no_defs", // EPSG:4326
"+proj=longlat +datum=WGS84 +no_defs");
assertEquals("POINT (8.07013599546795 44.76924401481436)", g1.toText());
}
use of com.vividsolutions.jts.io.WKTReader in project tutorials by eugenp.
the class HibernateSpatialTest method wktToGeometry.
private Geometry wktToGeometry(String wellKnownText) throws ParseException {
WKTReader fromText = new WKTReader();
Geometry geom = null;
geom = fromText.read(wellKnownText);
return geom;
}
use of com.vividsolutions.jts.io.WKTReader in project onebusaway-application-modules by camsys.
the class EnterpriseFilteredGeocoderBase method setWktFilterPolygon.
public void setWktFilterPolygon(String wkt) throws ParseException {
WKTReader reader = new WKTReader();
_wktFilterPolygon = (Polygon) reader.read(wkt);
}
Aggregations