23
23
import org .elasticsearch .xpack .esql .expression .function .Param ;
24
24
import org .elasticsearch .xpack .esql .expression .function .scalar .EsqlScalarFunction ;
25
25
import org .elasticsearch .xpack .esql .io .stream .PlanStreamInput ;
26
- import org .locationtech .jts .io .WKTReader ;
27
- import org .locationtech .jts .io .WKTWriter ;
28
26
import org .locationtech .jts .simplify .DouglasPeuckerSimplifier ;
29
27
30
28
import java .io .IOException ;
@@ -93,20 +91,13 @@ public void writeTo(StreamOutput out) throws IOException {
93
91
out .writeNamedWriteable (tolerance );
94
92
}
95
93
96
- private static class GeoSimplifier {
97
- static WKTReader reader = new WKTReader ();
98
- static WKTWriter writer = new WKTWriter ();
99
-
100
- public static BytesRef geoSourceAndConstantTolerance (BytesRef inputGeometry , @ Fixed double inputTolerance ) {
101
- String wkt = UNSPECIFIED .wkbToWkt (inputGeometry );
102
- try {
103
- org .locationtech .jts .geom .Geometry jtsGeometry = reader .read (wkt );
104
- org .locationtech .jts .geom .Geometry simplifiedGeometry = DouglasPeuckerSimplifier .simplify (jtsGeometry , inputTolerance );
105
- String simplifiedWkt = writer .write (simplifiedGeometry );
106
- return UNSPECIFIED .wktToWkb (simplifiedWkt );
107
- } catch (Exception e ) {
108
- throw new RuntimeException (e );
109
- }
94
+ private static BytesRef geoSourceAndConstantTolerance (BytesRef inputGeometry , double inputTolerance ) {
95
+ try {
96
+ org .locationtech .jts .geom .Geometry jtsGeometry = UNSPECIFIED .wkbToJtsGeometry (inputGeometry );
97
+ org .locationtech .jts .geom .Geometry simplifiedGeometry = DouglasPeuckerSimplifier .simplify (jtsGeometry , inputTolerance );
98
+ return UNSPECIFIED .jtsGeometryToWkb (simplifiedGeometry );
99
+ } catch (Exception e ) {
100
+ throw new RuntimeException (e );
110
101
}
111
102
}
112
103
@@ -128,11 +119,11 @@ public EvalOperator.ExpressionEvaluator.Factory toEvaluator(ToEvaluator toEvalua
128
119
129
120
@ Evaluator (extraName = "NonFoldableGeoAndConstantTolerance" , warnExceptions = { IllegalArgumentException .class })
130
121
static BytesRef processNonFoldableGeoAndConstantTolerance (BytesRef inputGeometry , @ Fixed double inputTolerance ) {
131
- return GeoSimplifier . geoSourceAndConstantTolerance (inputGeometry , inputTolerance );
122
+ return geoSourceAndConstantTolerance (inputGeometry , inputTolerance );
132
123
}
133
124
134
125
@ Evaluator (extraName = "FoldableGeoAndConstantTolerance" , warnExceptions = { IllegalArgumentException .class })
135
126
static BytesRef processFoldableGeoAndConstantTolerance (@ Fixed BytesRef inputGeometry , @ Fixed double inputTolerance ) {
136
- return GeoSimplifier . geoSourceAndConstantTolerance (inputGeometry , inputTolerance );
127
+ return geoSourceAndConstantTolerance (inputGeometry , inputTolerance );
137
128
}
138
129
}
0 commit comments