simplify(...)
Reduces the number of vertices in a line or polygon
Works with the following datatypes:
This function works with 2.1 endpoint(s). What does this mean? »
The simplify(...)
function reduces the number of vertices in a line or polygon using the Ramer–Douglas–Peucker algorithm. This is useful for approximation or for reducing the total size of a geospatial dataset.
simplify(...)
takes two arguments:
Be careful specifying a tolerance value that is too high, as you can actually simplify a geometry until it actually disappears. For a safer simplification method, try simplify_preserve_topology(...)
, which prevents the algorithm from oversimplification. For example, while simplify(...)
will potentially collapse a circle until it disappears, simplify_preserve_topology(...)
will at worst result in a triangle.
For example, to get a simplified version of the polygon for the City of Seattle from the Tiger LINE “Places” dataset:
For more information on how simplification works, you should refer to the ST_Simplify
PostGIS function.
within_polygon(...)
One handy use of simplify(...)
is to generate simplified polygons that work with our within_polygon(...)
function. To use within_polygon(...)
, you need to generate a string in Well Known Text, a text markup language for representing geometries, and that string also needs to be fit within the limit of a URL string, which can be as short as 2000 characters for some HTTP client libraries.
Fortunately, our CSV output type already encodes polygons in WKT, and you can use simplify(...)
with our CSV output. So, if you wanted to fetch a simplified version of the Seattle city boundary to feed into another SoQL query, you could use a call similar to the one above, but change the output type to get you CSV and WKT: