use of com.vividsolutions.jts.precision.GeometryPrecisionReducer 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);
}
Aggregations