PathSimplifier

Drops the points of a path or a ring that don't change its shape by more than a tolerance (Douglas-Peucker), so a shape with thousands of points can be drawn with far fewer when it is seen from far away. It works on the sphere: the distance of a point to the line a shape would be drawn with is its distance to the great-circle arc between the neighbours that are kept, because that is how WWK draws an edge, and plain latitude/longitude distances are wrong at high latitudes and over long edges.

The result is a list of indices into the given points (in increasing order), not new points: every point that is kept is one of the originals, so a caller can map it back to the vertex it came from.

Properties

Link copied to clipboard

Mean Earth radius, meters: the sphere the tolerance is measured on.

Functions

Link copied to clipboard
fun simplifyPath(points: List<GeoPosition>, toleranceMeters: Double): List<Int>

Indices of the points to keep of an open path, always including the first and the last. Every dropped point is within toleranceMeters of the arc between its kept neighbours. A tolerance of 0 (or less) keeps everything.

Link copied to clipboard
fun simplifyRing(points: List<GeoPosition>, toleranceMeters: Double): List<Int>

Indices of the points to keep of a closed ring (the last point is not repeated at the end: the edge from the last point back to the first is implied), at least 3 of them whenever the ring has that many. Like simplifyPath, dropped points stay within toleranceMeters of the outline that is kept. A tolerance of 0 (or less) keeps everything.