3

Is there an automated process in QGIS to add extra vertices to a polygon based on adjacent polygons vertices?

For example, this polygon has more vertices than the next one on the common boundary. I want to add more vertices on the next polygon to have the same vertices.

enter image description here

enter image description here

I tried the "Snap geometries" algorithm and it only added vertices at few places but not all. I don't want to use grass so don't suggest an external module.

0

2 Answers 2

4

You can use the Snap Geometries to Layer algorithm. Make sure you set the parameters as follows:

enter image description here

Choose the same input layer for the Input layer and Reference layer parameters.

Set the Behavior to Snap to anchor nodes (single layer only) and set a tolerance for the snapping. I usually set 1 millimeter or 1 centimeter for my data.

That's it!

Note: Because of a big optimization in such algorithm lately, and since you're dealing with a big amount of data, you should use at least QGIS v3.20.


Another option

Just for reference, if you want to do this for some geometries and without using QGIS processing, you can run the following code snippet to transfer missing vertices among features in the same layer. This will automatically fix all your layer features, but is not optimized for big amounts of data.

See the process and the result:

enter image description here

Code snippet:

# Select your layer in the layers panel before running the script
layer = iface.activeLayer()


# Preparation
index = QgsSpatialIndex(layer)  # Optimize intersection checks
edit_layer = QgsVectorLayerEditUtils(layer)
request = QgsFeatureRequest().setNoAttributes()  # Get rid of attributes
dict_features = {feature.id():feature for feature in layer.getFeatures(request)}

with edit(layer):
    for fid, feature in dict_features.items():
        bbox = feature.geometry().boundingBox()
        candidate_ids = index.intersects(bbox)

        # Get rid of intersections with itself
        candidate_features = [dict_features[candidate_id] for candidate_id in candidate_ids
                              if candidate_id != fid]

        for candidate_feature in candidate_features:
            # Add missing vertices from candidate_feature to intersecting features
            edit_layer.addTopologicalPoints(candidate_feature.geometry())
5
  • This does the job as intended, but is either irresponsive or too slow on big layers. Jun 24, 2021 at 15:29
  • Interesting. If you can share big enough sample data, I can explore where could be a bottleneck. Jun 24, 2021 at 15:43
  • curve number layer in the attachment in this issue github.com/qgis/QGIS/issues/43798 Jun 24, 2021 at 15:57
  • Just updated the answer with another solution. This one, optimized for big amounts of data and available in QGIS Processing. Jun 24, 2021 at 20:02
  • Ok I will check with options you suggested and update. Jun 25, 2021 at 0:43
2

If is does not need to be QGIS you can do the job with OpenJUMP Plus.

Source polygons:

enter image description here

enter image description here

Use the "Adjust Polygon Boundaries" tool. The tool can also fix small gaps and overlaps.

enter image description here

Processed polygons sharing the same vertices.

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.