1

In QGIS 3.16: I have 2 non-overlapping polygon layers that I want to merge to one layer. The two layers have associated attribute tables with 13 fields in common (same variable, same field type; different names in header however) and additionally, several fields each that are unique to that layer.

What I would like to do is merge the two layers in a way that

  1. allows me to choose which common attribute fields can get collapsed to the same column (for example: merge field NUM_SITE from layer1 to field _02numsite from layer2; merge field ORGANISME from layer1 to field _04organis from layer2); and,
  2. will add all non-common attribute fields to the resulting merged table as well (with Null/empty values for the features originally lacking those attributes). And obviously,
  3. I want to keep associated geometry.

Note: since the two layers have non-overlapping features, the number of features (lines) in the resulting merged table should in principle equal the number of features in layer1 + the number of features in layer2; no features will be merged, i.e., no new information will be added to any line (other than 'Null' values in new columns).

As far as I can tell, I'm not looking for any type of table join (my attempt at 'join by attribute' seems not to include all features from both layers) but rather a type of shapefile merge that gives me options as far as attributes go. I could perhaps just rename all of the headers and that might give me what I'm hoping for, but I was looking for a more systematic way if that exists.

4
  • 1
    I recommend using legal column names (leading alpha), but otherwise this seems a simple Append operation.
    – Vince
    Commented May 4, 2021 at 12:12
  • Hi and thanks for your comment Vince; could you clarify what you mean by leading alpha? As for Append, I assume you are referring to writing code as I do not think there is a QGIS function for this? I am getting started with Python, but am definitely not competent enough to write anything yet and this seems like a common enough need that there would be a function for it.
    – pete
    Commented May 4, 2021 at 12:46
  • The dBase spec requires fieldnames to have an initial A-Z character (underscore and numeric are permitted in positions 2-10). ArcGIS has an Append, and so does QGIS (-ish) gis.stackexchange.com/questions/131041/…
    – Vince
    Commented May 4, 2021 at 13:10
  • Thanks, I was unaware of this.
    – pete
    Commented May 4, 2021 at 14:16

1 Answer 1

1
  1. Run Menu Processing / Toolbox / Merge vector layers: this gives you a new vector layer with all features from all inputs layer and with all attributes separateley, containing NULL for attributes that did not exist in the layer the feature orginiates from.

  2. Run Menu Processing / Toolbox / Aggregate: it allows you the define in detail which attributes should be combined. You can use QGIS expressions, define an aggregate fucntion (like sum for adding values) and you might even change field data type.

Screenshot: I combine two layers, poly1 with an attribute value1 and poly2 with an attribute poly2. In the Aggregate dialog, I define that if the field for poly1 is empty, the content of value2 should be taken: enter image description here

1
  • 1
    Good trick. I've never used Aggregate but now I surely will. Thanks!
    – pete
    Commented May 4, 2021 at 14:17

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.