SHAPELY_SIMPLIFY

Simplifies an input WKT geometry using the Douglas–Peucker algorithm with a user-specified tolerance.

The tolerance controls maximum allowed geometric displacement; larger values usually reduce vertex count more aggressively.

Informally, the simplified geometry G' satisfies a bounded deviation from G under the chosen tolerance \varepsilon.

This implementation preserves topology to reduce invalid geometry artifacts during simplification.

Excel Usage

=SHAPELY_SIMPLIFY(geometry, tolerance)
  • geometry (str, required): Input geometry (WKT).
  • tolerance (float, required): All points in the simplified object will be within the tolerance distance of the original geometry.

Returns (dict): Excel Entity representing the simplified geometry.

Example 1: Simplify a line

Inputs:

geometry tolerance
LINESTRING (0 0, 1 0.1, 2 0) 0.2

Excel formula:

=SHAPELY_SIMPLIFY("LINESTRING (0 0, 1 0.1, 2 0)", 0.2)

Expected output:

{"type":"String","basicValue":"LINESTRING (0 0, 2 0)","properties":{"WKT":{"type":"String","basicValue":"LINESTRING (0 0, 2 0)"}}}

Example 2: Simplify a polyline

Inputs:

geometry tolerance
LINESTRING (0 0, 1 0.2, 2 0.1, 3 0) 0.15

Excel formula:

=SHAPELY_SIMPLIFY("LINESTRING (0 0, 1 0.2, 2 0.1, 3 0)", 0.15)

Expected output:

{"type":"String","basicValue":"LINESTRING (0 0, 1 0.2, 3 0)","properties":{"WKT":{"type":"String","basicValue":"LINESTRING (0 0, 1 0.2, 3 0)"}}}

Example 3: Simplify a polygon

Inputs:

geometry tolerance
POLYGON ((0 0, 2 0, 2 1, 1.2 1.2, 2 2, 0 2, 0 0)) 0.3

Excel formula:

=SHAPELY_SIMPLIFY("POLYGON ((0 0, 2 0, 2 1, 1.2 1.2, 2 2, 0 2, 0 0))", 0.3)

Expected output:

{"type":"String","basicValue":"POLYGON ((0 0, 2 0, 2 1, 1.2 1.2, 2 2, 0 2, 0 0))","properties":{"WKT":{"type":"String","basicValue":"POLYGON ((0 0, 2 0, 2 1, 1.2 1.2, 2 2, 0 2, 0 0))"}}}

Example 4: Simplify a multipoint geometry

Inputs:

geometry tolerance
MULTIPOINT (0 0, 1 1, 2 2) 0.5

Excel formula:

=SHAPELY_SIMPLIFY("MULTIPOINT (0 0, 1 1, 2 2)", 0.5)

Expected output:

{"type":"String","basicValue":"MULTIPOINT ((0 0), (1 1), (2 2))","properties":{"WKT":{"type":"String","basicValue":"MULTIPOINT ((0 0), (1 1), (2 2))"}}}

Python Code

from shapely import wkt

def shapely_simplify(geometry, tolerance):
    """
    Returns a simplified representation of the geometric object.

    See: https://shapely.readthedocs.io/en/stable/reference/shapely.simplify.html

    This example function is provided as-is without any representation of accuracy.

    Args:
        geometry (str): Input geometry (WKT).
        tolerance (float): All points in the simplified object will be within the tolerance distance of the original geometry.

    Returns:
        dict: Excel Entity representing the simplified geometry.
    """
    try:
        if not geometry:
            return "Error: Geometry required"

        geom = wkt.loads(geometry)
        simplified = geom.simplify(tolerance, preserve_topology=True)
        wkt_str = simplified.wkt

        return {
            "type": "String",
            "basicValue": wkt_str,
            "properties": {
              "WKT": {"type": "String", "basicValue": wkt_str}
            }
        }
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

Input geometry (WKT).
All points in the simplified object will be within the tolerance distance of the original geometry.