3

I have two vector point GeoJSON layers) showing supermarkets in 2 adjacent cities. I would like to combine them in one way or another (by merging them or adding the feature of one to the other). Their fields are all the same. But the merge fails because of the failure of unique constraint, I think it is due to their fid which has some common values (fid from feature #3 of city 1 is 3 for instance, and this is the same for city 2, so it creates a conflict). I can't delete the fid field either to solve the issue. Is there any way to solve this issue?

Link towards files

(by the way the "merge vector layers" appears to be successful but once you want to make the file permanent it doesn't work as the constraint of having unique identifiers for each feature is not satisfied)

Vince
  • 20,017
  • 15
  • 45
  • 64
Philippe Morgan
  • 633
  • 4
  • 11
  • 1
    Is it possible to share the data? – Cushen Aug 01 '22 at 06:05
  • 3
    Refactor fields and rename the fid field in one layer then merge – BERA Aug 01 '22 at 06:12
  • I did this (before with rename and this time with refactor) but it creates a new field instead of replacing the old fid (feature id) one. I guess this is due to this field being considered as a "master" field with constrains (unique id in this case) – Philippe Morgan Aug 01 '22 at 07:38
  • See here how to solve the unique constraint failed error: https://gis.stackexchange.com/a/400741/88814 - using your data, merge vector layers, then create another fid like fid2 (solution 2) does the job. – Babel Mar 26 '24 at 08:21

1 Answers1

4

I recently had a similar issue, this is what worked fro me:

  • Select all features from Layer 2 > Edit > Copy Features [Ctrl+C]
  • Toggle Editing on Layer 1 > Edit > Paste Features [Ctrl+V] > Stop Editing (Save Changes)
Cushen
  • 2,928
  • 13
  • 15
  • Thank you it did it for me! I still shared the file as others might have other solutions/additional takes on it but this works well and fast so that's great. – Philippe Morgan Aug 01 '22 at 07:49
  • It's weird I did it again for another layer and at first could not save the changes, but after redoing it a second time it was fine. – Philippe Morgan Aug 01 '22 at 07:56