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_preserve_topology(...)

simplify_preserve_topology(...)

Reduces the number of vertices in a line or polygon, preserving topology

Works with the following datatypes:

This function works with 2.1 endpoint(s). What does this mean? »

Similar to simplify(...), the simplify_preserve_topology(...) 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

Unlike simplify(...), this function will not over-simplify geometries.

simplify_preserve_topology(...) takes two arguments:

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

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_preserve_topology(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_preserve_topology(...) 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_preserve_topology(...) 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_preserve_topology(the_geom, 0.001) AS the_geom&name=Seattle