5

In the advanced digitizing toolbar, QGIS has these 3 tools: Split Features, Split Parts, and Merge Features. Is there a tool or equivalent algorithm for the logical fourth one: "Merge Parts"?

This would have the opposite effect of Split Parts, which takes one part of a multipart feature and splits it into two adjoining parts of the same feature. Conversely, "Merge Parts" would take two (or more) adjoining parts of the same feature and make them a single part of that feature. It would not affect the singlepart/multipart status of the feature (or the layer as a whole).

In the image below there are two multipolygon features, which I realize I should have called Feature A and Feature B (rather than Polygon A and Polygon B). Feature A has 2 parts, and Feature B has 4 parts; note that parts 1 and 2 in Feature B share a common boundary. I've selected Feature B, and I'd like to execute a tool to join parts 1 and 2 into a single part, as shown in the "after" section. Feature B would then still be a multipolygon, but would have only 3 parts instead of 4. enter image description here

The closest I can find is the "merge lines" algorithm; however this would not work with multipolygon features. It also merges all connected parts of a line feature, instead of just selected ones. (Is it even possible to select individual parts?) Is there anything else I'm missing?

  • I should add, there is an easy and fairly obvious workaround, which is to use the Multiparts to Singleparts tool (which makes a new, separate feature out of each part of a multipart feature) and then use Merge Features to re-combine the resulting features (with any adjoining ones being merged into a single part). My question is really whether there is any existing tool that does this by design. – Nathan Jan 11 at 17:52
  • Could you draw a sketch about what such merge parts operation would do to support your literal explanation? – user30184 Jan 11 at 18:03
  • 1
    @MrXsquared: "Merge selected features" requires selecting at least 2 features, which then get merged into one feature. "Merge parts" would perform an operation on only a single feature. "Dissolve" likewise requires combining separate features, not parts of a single feature. And your clarification is correct, I am not trying to do that. I am merging parts of multipolygons, that share a boundary, into a single part of the same multipolygon. – Nathan Jan 12 at 2:24
  • 1
    @user30184, I'll see if I can come up with a sketch, but in the meantime, here's an easy way to picture what I'm asking: 1) Select a feature 2) With the Split Parts tool, draw a line through the selected feature 3) You now have separate, adjoining parts of the feature 4) Select "Undo" I'm looking for a tool that does just steps 3-4, without needing steps 1-2. – Nathan Jan 12 at 2:28
  • 1
    @Nathan, Contiguous parts are considered a topological error and can be linked with the Fix geometries tool. In my case (QGIS 3.4.3), Split Parts produces always invalid geomeries and I just don't use it. – Gabriel De Luca Jan 12 at 9:05
2

Is there a tool or equivalent algorithm for the logical fourth one: "Merge Parts"?

No, there isn't.

The adjacent parts of a multipolygon are considered a topological error and must be linked with the Fix geometries tool.

Is it even possible to select individual parts?

No, it isn't.

You can select features, not individual parts.

Is there anything else I'm missing?

I don't know. But you can refer to parts of collections with the geometry_n() function in expressions.

For example, you can create a new feature (in a separate layer) with the Geometry by expression tool, that contains the combination of two parts (or more if the function is nested) of a feature or of several, of any layer. If the parts are adjacent, they will form a single part in the new feature.

To create a feature formed by parts 1 and 2, of the feature_ID 0, of the 'multipolygons' layer:

combine( 
    geometry_n( geometry( get_feature_by_id( 'multipolygons', 0)), 1), 
    geometry_n( geometry( get_feature_by_id( 'multipolygons', 0)), 2)
    )  

Note than the Geometry by expression tool copies the table from the input layer. If the input layer have more than one features, more than one features will be created, but only one will have a valid geometry with that expression.


UPDATE:

About the WKT of the Multipolygon provided in the comments (https://pastebin.com/1ibYDzR5), I can't seem a line shared by both parts.

When loading the feature in QGIS, it can be seen (with an appropriate zoom level), that the parts are not adjacent.

Upper:
upper

Lower:
lower

Be sure to snapping when digitizing and editing (here is the manual). Otherwise, you can not merge those parts as they are in any way.

  • That there is no Merge Parts tool does seem to be the correct answer, thanks! However, it does not seem to be correct that "Fix geometries" will merge parts. I'm unable to reproduce that. – Nathan Jan 14 at 3:50
  • @Nathan, If Fix Geometries tool does not merge them, it is because they are not adjacent, or they are not parts of the same feature. If they are adjacent but are not parts of the same feature, but they are in the same layer, the Dissolve tool should also merge them. If they are adjacent but are parts of different features of different layers, the combine() function should merge them. If nothing merge them, they are not adjacent. – Gabriel De Luca Jan 14 at 4:20
  • @Nathan, check your original geometries. It's evident that they have a topological error. If you don't find the error in them, share them and we'll try to look for it together. – Gabriel De Luca Jan 14 at 16:24
  • It's only evident that the fixed geometries have a topological error; the original ones were created with snapping enabled, as you suggest, so they should not. (If they do, it's the result of some further error that's beyond the scope of my question.) Since this data only exists for illustrative purposes, I'd have to re-create it if we wish to explore further. – Nathan Jan 14 at 16:42

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

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