# Simplify geometries but keep them contiguous [duplicate]

I have several detailed contiguous areas. I need to turn each one into KML, but when I do so, the end result is too large (in terms of memory). Using PostGIS I need to simplify these geometries but keep them contiguous.

I have tried calling `ST_SimplifyPreserveTopology` with a `GEOMETRYCOLLECTION` created by `ST_Collect`, but the areas are no longer contiguous.

Previously I think I have succeeded in simplifying areas while at the same time keeping shared borders in line with each other by using desktop applications. However, I am looking for a way to do the same using PostGIS.

You can simplify your polygons using two ways:

• Without topology support: just transform polygones to lines, simplify, rebuild the polygons and reattach attributes with Point in Polygon. You will find a first recipe on the PostGIS wiki

• With topology support. There is another recipe available on the PostGIS wiki. IMO, it's the recommended way.

In both case, for simplifying, you can choose the `ST_Simplify` and `ST_SimplifyPreserveTopology` functions based on Douglas-Peucker algorithm or the `ST_SimplifyVW` function based on the Visvalingam-Whyatt algorithm if you use PostGIS 2.2+.

You can use ST_SnapToGrid(geom,0.01) to align all your vertices to a grid with a certain precision (0.01 in the example). There is the risk of losing small geometries or creating complex geometries though, so find out first how much precision your data needs in the first place. Also, it assumes the vertices of adjacent faces are at exactly the same location.

I have posted another solution on my blog at www.spheraware.com/blog/post/late-tessellate. This approach is still a work in progress but it has been effective for me. You simplify first and then fix the alignment problems. It's much faster than the "disassemble-simplify-reassemble" recipe and there is no need to create a topology or additional tables.

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