# Simplifying adjacent polygons using PostGIS?

I encountered a problem simplifying set of polygons that are adjacent. If I simplify each polygon separately with the Douglas–Peucker algorithm (which is used by many open source tools), the resulting polygons are usually not adjacent anymore. This problem exists, for example, when simplifying borders of countries/provinces.

Does anyone have a solution for it using PostGIS?

A topological vector model will provide what you need. In a non-topological storage (such as a shapefile), a single edge between geometries is stored twice. In a topological vector, the areas are stored separately from the lines, so adjustments can be made without effecting topology. I couldn't find a good diagram, so I created this simple example, where the areas A, B and C are computed from the intersections of the lines (connecting 1-4) which separate them.

This model is used by ArcInfo as coverages, in GRASS as its default vector model, and can be used in PostGIS with the experimental PostGIS Topology tool. Perhaps a simpler solution is converting your data into linework, removing the redundant segements, and then recreating your polygons after simplification.

You want to turn your polygons into lines, make those lines be simple coverage edges, simplify those edges, then build them back up into polygons again, and finally use point-in-polygon to re-join the attributes of the old polygons with the new ones.

``````CREATE TABLE rings AS SELECT (ST_DumpRings(polys)).geom AS rings FROM polytable;
CREATE TABLE simplerings AS SELECT ST_Union(rings) AS simplerings FROM rings;
CREATE TABLE newpolycollection AS SELECT ST_Polygonize(ST_Simplify(simplerings, 10.0)) AS geom FROM simplerings;
CREATE TABLE newpolysnoattributes AS SELECT (ST_Dump(geom)).geom FROM newpolycollection;
CREATE TABLE newpolytable AS SELECT new.geom, old.attr FROM newpolysnoattributes new, polytable old WHERE ST_Contains(new.geom, ST_PointOnSurface(old.polys));
``````

There are errors in the above, but the core concept is there. You can do it all in one query if you like.

As of PostGIS 3.4.0, there is a dedicated function which does exactly this:

``````ST_CoverageSimplify(geometry winset geom, float8 tolerance, boolean simplifyBoundary = true)
``````

ST_CoverageSimplify docs

PostGIS 3.4.0 Release notes