# 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.

• re: your last point: surely if you convert the polygons to lines, then simplify those lines, you'll still end up with the same problem. Only this time you'll have lines not aligning with each other. Dec 10, 2020 at 13:29
• Tutorial: trac.osgeo.org/postgis/wiki/… Dec 27, 2020 at 9:36

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.

• I'm finding that I can't `ST_SIMPLIFY` a `ST_UNION`'d set of LINESTRINGS (ie. I can simplify a complex multilinestring) Dec 11, 2020 at 1:31
• @TheoF im trying to work with similar approach, but is not working for me, and just appear few geometries... did you got the results expected? Dec 1, 2021 at 15:25

To avoid this problem, you should model your data using topological constraints. http://mapshaper.org/ does it.

You need to tessellate. In the old ARC/INFO theory of creating geometry, two adjacent geometries is created by one polyline and shared this polyline. Therefore when you generalized, it generalized both borders because it referenced the same polyline.