use of org.locationtech.jts.precision.GeometryPrecisionReducer in project dotwebstack-framework by dotwebstack.
the class TypeEnforcer method enforcePoint.
private Point enforcePoint(Geometry geometry) {
GeometryPrecisionReducer precisionReducer = Optional.ofNullable(precisionReducers.get(geometry.getSRID())).orElse(defaultPrecisionReducer);
var point = (Point) precisionReducer.reduce(geometry.getCentroid());
point.setSRID(geometry.getSRID());
return point;
}
use of org.locationtech.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);
}
return getGeometryType(result, geom.getSrid());
}
Aggregations