2

I have a single layer with shapes (raster cells) that represent all countries on earth (the figure below shows france). Each shape has specific attributes.

enter image description here

Is it possible to merge the shapes by their attributes? E.g. if attributes x,y and z in shape 1 are the same as attributes x,y and z in shape 2 ... then create a shape that covers the area of shape 1 and shape 2 and contains the attributes x,y,z?

Example: If I have the attribute table displayed below, I would like to merge the shapes with the ID 2 and 7 to one shape.

enter image description here

I have tens of thousands of shapes with hundreds if not thousands of different attributes. I'm afraid doing anything manually is not an option.

  • can you give some more information about your data? Which one is the 'base-layer. And what data should be merged, etc... – PieterB Jul 17 '18 at 12:23
  • Select those IDs and in digitize toolset use merge tool. – nagib Jul 17 '18 at 13:46
  • I have tens of thousands of shapes with hundreds if not thousands of different attributes. I'm afraid doing anything manually is not an option. – Jonas Jul 17 '18 at 13:49
2

The dissolve tool is what you're looking for (Vector -> Geoprocessing -> Dissolve). This merges shapes with matching attributes into single shapes within the same layer. For QGIS 2.18 you can select a list of fields to dissolve by, rather than just one field as in the past.

This is the new dialogue - you can add multiple attributes and it will dissolve the shapes with matching combinations of attributes: Dissolve tool dialogue

And this is the result - you can see how matching pairs of X/Y/Z are dissolved into single, multi-part shapes (Test is the original data):

Dissolve results


This question also has a suggestion for doing a multi-field dissolve in ogr2ogr which might be quicker as you could run that from the command line: Dissolving by two fields in QGIS?

  • I am looking for something that works for the same layer. Thanks, I'll check it out! – Jonas Jul 17 '18 at 13:04
  • But with dissolve I cannot add 'criteria', can I? I only want to dissolve those shapes that share specific attributes with one another. – Jonas Jul 17 '18 at 13:10
  • I added another figure to explain my question. – Jonas Jul 17 '18 at 13:18
  • I see what you're trying to do. How many combinations of attributes have you got that you want to merge? For example in your figure above you've got Shape 1 (000) and Shapes 2 and 7 (111). If there aren't too many could you dissolve and then do some manual processing? – Ed Rollason Jul 17 '18 at 14:24
  • 1
    Jonas - the dissolve tool does that by default. If there are no other shapes with matching attributes then they get left alone; for example in my figure above shape ID 4 is unique and is left as an undissolved shape. I think a combo of my answer and also Kurt's answer from above is what you're looking for – Ed Rollason Jul 18 '18 at 12:00
1

FIRST Do the calculations in libre-office and add a new Field MERGE: =IF(AND(B2=C2;C2=D2);1;0)

enter image description here

AFTERWARDS do a simple DISSOLVE in QGIS based on new field MERGE 1 = merge, 0 = do not merge

edit: in an english libre-office you probably need to replace ; by ,: =IF(AND(B2=C2,C2=D2),1,0)

  • Not exactly what I had in mind but I guess this would indeed work! – Jonas Jul 18 '18 at 7:21
0

You could select the desired features based upon their attributes, save them to a new shape/layer and then merge the new layers.

Or you could build a graphical model which omits the saving of a new layer, but otherwise does the same.

  • I have tens of thousands of shapes with hundreds if not thousands of different attributes. I'm afraid doing anything manually is not an option. – Jonas Jul 17 '18 at 12:11
  • 2
    Well, then run a model. Or revert to python. Problem is, that we do not know your data structure and your final goal. – Erik Jul 17 '18 at 12:31
0

I think that only a reasonable answer would be, select attribute values from both layer with expression, then save them separate and merge them. enter image description here

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.