Class GeometrySimplifier<T extends Geometry>

java.lang.Object
org.elasticsearch.geometry.simplify.GeometrySimplifier<T>
Direct Known Subclasses:
GeometrySimplifier.GeometryCollections, GeometrySimplifier.Identity, GeometrySimplifier.LinearRingSimplifier, GeometrySimplifier.LineSimplifier, GeometrySimplifier.MultiPolygonSimplifier, GeometrySimplifier.PolygonSimplifier

public abstract class GeometrySimplifier<T extends Geometry> extends Object
The geometry simplifier can simplify any geometry, and does so by internally making use of the StreamingGeometrySimplifier, to minimize memory usages. When simplifying a complex geometry, for example a Polygon with holes, with the simplification threshold k=1000, the memory usage should be:
  • Original complete geometry (in this example, one shell and several holes)
  • Internal memory for simplifying the shell is O(k), so an array of 1000 objects containing x, y and an estimated error.
  • Internal memory for simplifying each hole, which is a scaled down k based on the relative size of the hole. For example, if the shell is 100k points, and a hole is 1k points, we will scale the hole k to just 10 points.
  • The finally simplified geometry, which occupies a similar amount of memory to the simplification algorithm, in other words O(k)
This approach of limiting the algorithms to some deterministic linear function of the simplification threshold k is used for all complex geometries, even GeometryCollection.

Note, however, that no attempt is made to prevent invalid geometries from forming. For example, when simplifying a polygon, the removal of points can cause lines to cross, creating invalid polygons. Any usage of this algorithm needs to consider that possibility. If the simplification is only required for visualization, and the visualization code is tolerant of line crossings, this is not an issue. But if you need valid simplified geometries, do additional validation on the final results before using them.

If the incoming data is a stream of points, or x and y coordinates, it is even more memory efficient to directly use the StreamingGeometrySimplifier which will only maintain the single array of length k, and produce a final geometry of O(k) at the end, so the total size of the original geometry is not a factor.