5

I am trying to remove vertices inside a polygon area which do not form an outside boundary to the polygon. Example picture below with the vertices to be removed in red markings.

Deleting the vertices manually with the editing tool is not an option since there are 1000s of these in my dataset.

Is there an effective way to get rid of these vertices in QGIS, so only the polygon boundary is left?

enter image description here

1
  • 3
    If a slight loss of precision is acceptable you may buffer your polygon by a very slight amount (like 0.1 m), it should fix most of the wrong vertices
    – J.R
    Sep 30, 2022 at 13:35

3 Answers 3

5

To identify the vertices to delete, check the interior angle at each vertex and where this angle is very high (near to 360 degrees), you can delete the vertex.

To measure the interior anlge, I use this solution. You can now use QGIS expressions with the expression below an re-draw the polygon, but exluding the vertices with interior angle larger than let's say 350 degrees (you can change this value on line 3 of the expression to fit your needs).

I would advice to first use the expression with Geometry Generator to see the result and when satisfied, create the output as actual geometry (new layer) with Geomtry by Expression - see here for the differences between both options. The expression remains the same.

Blue: initial polygon, four vertices deleted, resulting in the new polygon with red outline - visualized here with Geometry generator: enter image description here

Changing the angle to 180, you get another result that deletes all "bays" of the polygon: enter image description here

Use this expression:

with_variable(
    'angle',
    350,  -- change this value to fit your needs
    make_polygon(
        make_line(
            point_n($geometry,1),
            array_filter(
                array_foreach(
                    generate_series (2,  num_points( $geometry)-1),
                    if (
                        with_variable (
                            'vertex',
                            @element,
                            with_variable (
                                'azimuth1',
                                degrees (
                                    azimuth(
                                        point_n($geometry,@vertex-1),
                                        point_n($geometry,@vertex)
                                    )
                                ),
                                with_variable (
                                    'azimuth2',
                                    degrees (
                                        azimuth(
                                            point_n($geometry,@vertex),
                                            point_n($geometry,@vertex+1)
                                        )
                                    ),
                                    case
                                    when (@azimuth1 > @azimuth2) and (@azimuth1 > @azimuth2+180) then 540-@azimuth1+@azimuth2
                                    when (@azimuth1 > @azimuth2) then 180-@azimuth1+@azimuth2
                                    when (@azimuth1 < @azimuth2) and (@azimuth1+180>@azimuth2) then 180 + @azimuth2-@azimuth1
                                    when (@azimuth1 < @azimuth2) then @azimuth2-@azimuth1-180 
                                end
                                )
                            )
                        ) < @angle,
                        point_n($geometry,@element),
                        'delete'
                    )
                ),
                @element is not 'delete'
            )
        )
    )
)
1
  • Thanks for your thought out solution. I could replicate it with new geometries (like in your example) but not with the original dataset. However I am sticking to the buffer with 0.001 m solution for now. Thanks!
    – gishelp
    Oct 4, 2022 at 14:12
4

If the vertices immediately before and after the ones that are within the polygon are coincident, the solution could be running the Processing > Vector geometry > Fix geometries tool from the Processing Toolbox (Ctrl+Alt+T).

2
  • 2
    Thanks for replying. Check geometry says all geometries are valid and therefore Fix geometries does return the original geometry with the vertices inside still existing.
    – gishelp
    Sep 30, 2022 at 12:51
  • Yes, I don't see how fix geometries could help here...
    – Babel
    Oct 1, 2022 at 15:10
1

Try these geoprocessing tools:

  • Snap geometries to layer and snap the layer to itself
  • Buffer with 0 distance
  • Snap points to grid
1
  • I can't see how this should work... can you elaborate on that idea?
    – Babel
    Oct 1, 2022 at 15:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.