TransWikia.com

Snapping polygon layer to another layer automatically

Geographic Information Systems Asked by Shiva on January 20, 2021

I have two polygon layers in QGIS 3.4: ‘Layer A’ and ‘Layer B’. These two layers have been digitized separately. Some features in these two layers are crossing or not meeting each other in some areas which I have to fix this problem.

‘Layer A’ is an accurate layer in terms of boundary so I want all the features in ‘Layer B’ be snapped to the closest feature (point) in ‘Layer A’.

Currently I try to move and snap all the vertexes in ‘Layer B’ to ‘Layer A’ manually using digitizing tool in QGIS which is very time consuming and I might miss some of them

So my question is: How can I do this process automatically or at least semi automatic?

One Answer

There are at least two possible solutions:

1. Use Geoprocessing / Difference

A simple approach is to create a buffer around layer B - set the buffer distance high enough that all white spaces between the two layers are covered. See screenshot: Layer A: orange; Layer B: blue; buffered Layer B: red outline.

enter image description here

Now use Menu Vector / Geoprocessing Tools / Difference and set the buffer layer as input and Layer A as Overlay layer. You get a perfectly fitting version of layer B, with layer A unchanged:

enter image description here


Snap vertices of layer B to nearest vertex of layer A

For QGIS 3.16 or higher, there is another option. You can use basically the same procedure as described here:

The idea is to create two points layer, representing the vertices of the two polygon layers using Menu Vector / Geometry Tools / Extract vertices. Than "snap" the points of layer B to the closest point of layer A using the new overlay_nearest expression, see visual changelog. Create a new point layer with Menu Processing / Toolbox / Geometry by expression and this expression, based on input layer B:

array_first (
    overlay_nearest( 
        'layer_A', 
        $geometry
    )
)

Than connect the points using Menu Processing / Toolbox / Points to path` and from these path create a polygon with Menu Vector / Geometry Tools / Lines to polygons.

Answered by babel on January 20, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP