# Simplifying adjacent polygons on subset of vertices only

We have many adjacent polygons which are very complex and we need to simplify only some portions of them.

There are no gaps nor overlaps between any two adjacent polygons.

What we'd like to do is to select a subset of the vertices delimiting two adjacent polygons together, and then simplify only this subset, while maintaining no gaps or overlaps between two adjacent resulting polygons: Is it possible to achieve that in QGIS for instance (or any other tool)?

We've looked into some options to simplify adjacent polygons, but can't find a way to do that on only a subset of the polygons.

• An interesting question. Jun 9, 2020 at 12:07
• Do you want to use just QGIS or could you imagine to try some other open source GIS software? Jun 9, 2020 at 13:21
• @user30184 plaftorm agnostic Jun 9, 2020 at 13:39
• Did you check the topojson format? You can convert your data to topojson using the geo2topo from the topojson-server node app. Then, using a json parser (inside python, R, ir your favorite languaje), identify the arcs shared by your target polygons and simplify them, keeping only the nodes you want. See github.com/topojson/topojson-server and github.com/topojson/topojson-specification Jun 11, 2020 at 4:21

I hope that I understood your question correctly.

Let's assume there one layer `"polygons"` with its corresponding attribute table accordingly, see image below. And of course there are some gaps or overlaps. Below I am suggesting a step-by-step process of how to simplify only the subset of polygons, while maintaining no gaps or overlaps between two adjacent resulting polygons.

Step 1. Divide your original layer into "good" and "bad" features. I used `'Extract by expression'`, e.g. `"id" IN (2,3)` and `"id" NOT IN (2,3)`. However, you can use any other available technique to separate your features. Step 2. Converting polygons into lines with `'Polygons to lines'`. Step 3. Applying `'Line intersections'` where lines intersect themself. In addition exploit `'Delete duplicate geometries'`. Step 4. Proceed further with `'Points to path'`. Step 5. Apply `'Dissolve'` to your "bad" features. Step 6. Use `'Delete holes'` Step 7. Here work with `'Split with lines'` between the result of Step 6 and Step 4. Step 8. Because of the inconsistent attributes evoked on the previous steps some extra paces on how to achieve correct attributes are required. I will probably extract geocentroids from the result of the Step 7, then apply `'Join attributes by location'` and afterwards a basic `'Join'` between polygons with correct geometries and points with correct attributes.

Step 9. Merging "good" features with the result of Step 8 via `'Merge vector layers'`. And of course some basic attributes adjustment is a plus. If you need straight lines for the step Step 4. then there are a couple of more steps have to be applied.

Step 4.1. Dissolve your paths with `'Dissolve'`.

Step 4.2. Attaining a straight line by means of a `"Virtual Layer"` through `Layer > Add Layer > Add/Edit Virtual Layer...` apply this query

``````SELECT setsrid(make_line(start_point(geometry), end_point(geometry)), #put your srid here)
FROM "Paths"
`````` There are might be better options with lines simplification algorithms, did not check that yet.

P.S. IMHO this algorithm is better to implement in a Graphical Modeler.

References:

The job can be done with OpenJUMP but the method is generic and any software can be used. What matters is that the software must be able to create a planar graph and build polygons from closed areas between linestrings. Create planar graph. You need only the edges.  From the planar graph select the lines that you want to simplify.  When you are satisfied with the simplification build polygons from the graph.  As a final step you must copy the attributes from the source layer into new polygons with spatial join.

Unfortunately real World polygon datasets usually have poor topology. Common borders do not match but there are small gaps and overlaps. It may be faster to digitize a few borders manually than to fix the source data so that it can be converted into lines and back to polygons without errors.

Clarification - if you do not have an `"id"` field in your table, create it and use it to identify the right and left (upper and lower) adjacent polygons.

1. One of the ways to solve this problem is as follows. My initial situation is depicted in the figure below: 1. Run the script (CTE), which I think is appropriate for your case of geodata processing, setting your table name and field name, for example "id"
``````WITH tbla as (SELECT id, ((ST_Dump(geom)).geom) geom
FROM <table_name>
),

tblb as (SELECT a.id, ((ST_Dump(ST_Difference(ST_ExteriorRing(a.geom), ST_ExteriorRing(b.geom)))).geom) geom
FROM tbla a
LEFT JOIN tbla b ON ST_Intersects(a.geom, b.geom) AND a.id < b.id
),

tblc as (SELECT id, ST_MakePolygon(ST_AddPoint(geom, ST_StartPoint(geom))) geom
FROM tblb
),

tbld as (SELECT a.id, ((ST_Dump(ST_Difference(ST_ExteriorRing(a.geom), ST_ExteriorRing(b.geom)))).geom) geom
FROM tbla a
LEFT JOIN tbla b ON ST_Intersects(a.geom, b.geom) AND a.id > b.id
),

tble as (SELECT id, ST_MakePolygon(ST_AddPoint(geom, ST_StartPoint(geom))) geom
FROM tbld
)

SELECT *
FROM tblc
UNION
SELECT *
FROM tble;
``````
1. Check your result, my result is shown in the figure below Translated with www.DeepL.com/Translator (free version)