Update 2018-05-11: in QGIS 2.18 and 3.0, this is done much more easily (no need to set up a mapset).
- Open the v.clean tool in the Processing toolbox.
- Select 'snap' as the cleaning tool.
- Set the
v.in.ogr
tolerance as per the instructions below (250 in the example).
- Run the tool, and you'll get two new layers - one 'errors' and one 'cleaned'.
Experiment for the right amount of snapping to use - see notes at the end.
You can use a number of GRASS tools to do the job. Just adding the data to a mapset in GRASS using v.in.ogr.qgis
may be all you need to do. Using QGIS and GRASS:
Overview:
- Open QGIS and make sure the GRASS plugin is turned on (
Plugins|Manage...
) and visible (View|Toolbars|GRASS
).
- Add the layer to QGIS.
- Create a mapset in GRASS.
- Import the layer into GRASS using an appropriate snapping threshold.
- Export your data (right-click and save-as from QGIS) back to a format you need.
In detail:
Add your layer that needs gaps / overlaps cleaned up (this is a UTM layer in metres):
There are some 'bad' areas that fit your description here (overlaps / gaps):
Select the button on the GRASS toolbar to create a new GRASS mapset:
You can just use a temporary folder and temporary location name ...
...and finally a mapset:
Import your layer from QGIS with the "Open GRASS tools" button then browsing to the tool:
Select your layer, then click 'advanced' and select an appropriate snapping threshold (in this case, 250m - depends on what your data look like!):
Results - original in gray, newly snapped layer in maroon:
NOTE:
- Small gaps and overlaps get fixed without modifying shapes too much, but the larger the 'snap' the more distortion you may see.
- The result is a topologically 'clean' geometry, following all of GRASS's rules (read up on that!).
- There are a LOT of tools (v.clean for one) that can do all kinds of cleaning and fixing.