1

I have a vector layer which contains about ~4000 line geomtries. Between some of them are tiny gaps, sometimes just centimeters. Instead of manually adjusting the gaps I hope that there is a tool, which snaps dangling endpoints of line geometries to the closest nagling neighbor, with a specified distance.For example, as in the image, the gap between the lines is just 0.007m, but I will need to further process them and for it, I would need to close the gap between them.

Is there a tool in QGIS, with which I would be able to close those gaps by snapping endpoints within a specified distance?

It is not the first time I came across this problem and, again, end up, with not finding a solution myself.

enter image description here

1
  • 2
    I would use the GRASS v.clean tool in QGIS processing, choosing line for your input and output type, and the clean tools of break and snap. You would set a tolerance (threshold) for the snap large enough to close the gaps but small enough it doesn't distort your features. You might also try the QGIS snap geometries tool.
    – John
    Commented Jul 8 at 20:48

2 Answers 2

1

Ok so you're talking about snapping, and there are a couple of solutions. But if you want to avoid having to correct them in the first place (prevention is better then a cure after all), at the start of the project in QGIS before you start digitizing check that snapping is enabled by default go to the 'Setting' menu → 'Options' and look for the 'Digitizing' tab. Here under the section 'Snapping' you can define the parameters as needed. If it's not you that is creating the geometries maybe share this with the person who is - it'll save everybody some time in the long run. The Options Settings

Otherwise, if you need to correct existing geometries you need to basically do what John has already suggested in the comments. In the first instance try just using the 'Snap geometries to layer' tool in the processing toolbox. Snap Geometries dialog box

EDIT : I forgot to mention you can access the snapping parameters (for when you're digitizing) from a toolbar : enter image description here

11
  • I tried the 'snap to geometries'-tool, but even though the distance is specified to 1m and the gaps are generally smaller than 1m, nothing changes when I apply it. I had this problem already in the past, I remember (with other datasets). What could be problem? For example, I have a gap ot 0.5m, and it doesn't close after applying the tool. (Oh, and I don't need tipps for digitzing, as the data I'm using is way to big to manually correct all gaps).
    – i.i.k.
    Commented Jul 9 at 7:53
  • 1
    No error or warning, it just doesn't adjust the gaps, unfortunately. I tried your shown option and nothing changed. However, I managed to do it with v.clean, and will post the answer with image in a second.
    – i.i.k.
    Commented Jul 9 at 8:13
  • 1
    I tried again the snap to geometry tool (this was the third time now) and now it did work! It created a new layer where the gaps are eliminated! Odd, that it didn't work before. I think I will stick with the output from this tool. Thank you for your support!
    – i.i.k.
    Commented Jul 9 at 8:25
  • 1
    I can't recreate this problem, when I tested the 'Snap-Geometry-To-Layer' I get valid geometries out. So it's probably to do with the input data. Do you have more info on the type of geom error ? The results are usually saved to another layer 'Error' / 'Error_output'. But if you can't identify the type of geometry error i would suggest going through the following processing tools: 'Fix Geometries' / 'Remove Duplicate Vertices' / 'Remove Null Geometries'
    – lhowarth
    Commented Jul 9 at 11:43
  • 1
    Sorry, you used the topology checker not the 'check validity' tool.Try running the 'check validity' on the output layer from 'Snap-Geometry-To-Layer', it'll return a table with the specific errors.
    – lhowarth
    Commented Jul 9 at 11:52
1

UPDATE: I strongly advise to use the v.clean tool. With the tool 'Snap geometry to layer' I had the problem that it creates invalid geometries.


Easier than the v.clean tool (as described below) is the 'snap geometries to layer'-tool: To create a new layer (not to modify your objects directly), when you use the search bar, select the algorithm under 'Processing Algorithms'. Setting a snapping of 1m you specify it accordingly: enter image description here

This will create a new layer in which the gaps are eliminated.

There is aso the v.clean-tool. However, the tool looks a bit intimidating regarding all the options and parameters to be set. For me it worked to clean the gaps by setting the Input feature type to 'line', as Cleaning tool I selected 'break' and 'snap', and (this is very important) under the 'Threshold(comma separated for each tool)'-option, I set the snapping distance. So here it is 1m and as I use two tools (snap and break), I will define this here as 1 for break, and 1 for snap --> 1,1. Further you will need to set the extent to the layer ('Calculate from layer'). All other parameters I let on default.

enter image description here

The output from this tool is great, as you now only get the corrected layer but also a layer whith only the corrected lines, so can see, which lines have been corrected. This is actually pretty nice!

enter image description here

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.