Socrata was acquired by Tyler Technologies in 2018 and is now the Data and Insights division of Tyler. The platform is still powered by the same software formerly known as Socrata but you will see references to Data & Insights going forward.

simplify(...)

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.

The DPR algorithm in action

simplify(...) takes two arguments:

  • The geometry to be simplified
  • The tolerance, in meters, used to simplify the segments in your geometry.

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:

https://odn.data.socrata.com/resource/h7w8-g2pa.json?$select=name, simplify(the_geom, 0.001) AS the_geom&name=Seattle

For more information on how simplification works, you should refer to the ST_Simplify PostGIS function.

Example Use Case: Generating WKT Polygons for 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:

https://odn.data.socrata.com/resource/h7w8-g2pa.csv?$select=simplify(the_geom, 0.001) AS the_geom&name=Seattle