Search in sources :

Example 1 with GeometryPrecisionReducer

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;
}
Also used : GeometryPrecisionReducer(org.locationtech.jts.precision.GeometryPrecisionReducer) Point(org.locationtech.jts.geom.Point) MultiPoint(org.locationtech.jts.geom.MultiPoint)

Example 2 with GeometryPrecisionReducer

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());
}
Also used : WKTWriter(org.locationtech.jts.io.WKTWriter) FunctionExecutionException(org.teiid.api.exception.query.FunctionExecutionException) GeometryPrecisionReducer(org.locationtech.jts.precision.GeometryPrecisionReducer) StringReader(java.io.StringReader) ParseException(org.locationtech.jts.io.ParseException) WKTReader(org.locationtech.jts.io.WKTReader)

Aggregations

GeometryPrecisionReducer (org.locationtech.jts.precision.GeometryPrecisionReducer)2 StringReader (java.io.StringReader)1 MultiPoint (org.locationtech.jts.geom.MultiPoint)1 Point (org.locationtech.jts.geom.Point)1 ParseException (org.locationtech.jts.io.ParseException)1 WKTReader (org.locationtech.jts.io.WKTReader)1 WKTWriter (org.locationtech.jts.io.WKTWriter)1 FunctionExecutionException (org.teiid.api.exception.query.FunctionExecutionException)1