I created a model to import different shape files coming from ARCMAP, to load them into my geopackage of my project.

The model does different things: Delete attribute (OBJECTID, SHAPE_LENGTH and SHAPE_AREA) --> Repair the geometry --> Reproject into the CRS of my project.

Everything works fine, but I have only one problem... my exported layer doesn't have a unique ID, like FID? Is it a way to have it?

If I add an attribut, and than calculate with $id, it does the job, but if I create a new feature in my exported layer, the field stays empty!! So it is not really a unique ID field!

EDIT: Here is the screenshot of my model: enter image description here

And here what I use for saving in my geopackage: enter image description here

  • Sorry: in your model, which algorithm do you use where you save the layer to the Geopackage? Save vector features to file? Not quite clear in your question.
    – Babel
    Sep 19 '21 at 11:40
  • It’s my model!?! Or I don’t understand your question? The last process I used in my model is « reproject layer ». So when I start my model, I just said that I don’t want a temporary layer, but save it in a geopackage!
    – katagena
    Sep 19 '21 at 11:59
  • I guess it's your model... I'm cnfused: you asked about a model and posted a screenshot, so I guess it's yours? What is important to know: what algorithm is it where you say "save it in a Geopackage"? Because the algorithms al have different input paramenters, so it's crucial to know where you define how and where to save your data.
    – Babel
    Sep 19 '21 at 13:23
  • In your 2nd screenshot you have "Importer donnéees ARCMAP". This does not appear in your model (1st screenshot) and this also does not correspond to any algorithm name that is available in the modeler. It's very confusing if you use manually defined names that do not correspond to the names QGIS uses: like this, it's difficult to see what you're doing.
    – Babel
    Sep 19 '21 at 13:27
  • Importer données ARCMAP is my model! I build it in graphical modeler, for which you have a screenshot, and I named it like that… that’s all!
    – katagena
    Sep 19 '21 at 13:45

When you save a layer to a new (or already existing) Geopackage, you can define the name of the field that contains the unique ID (called FID for Geopackage). When you add features, QGIS will autogenerate an incrementing number for the field defined as FID.

By default, the field containing the FID is named fid, but you can change this: see the second screenshot below.

If there is field with this name yet, QGIS will create it and fill in unique values automatically. If you enter the name of an already existing field, values in this field must be unique, otherwise you can't save the file (see here for details). You'll get an error:

Could not make temporary scratch layer permanent.
Error: Feature write errors:
Feature creation error (OGR error: failed to execute insert : UNIQUE constraint failed: temp_test4.id)
Only [X] of [Y] features written.

enter image description here

enter image description here

  • I already know that. But your screenshot is when you use the save as layer menu! As I said, I'm in "graphical modeler", and I don't have access to that! Or at least, I looking for that!
    – katagena
    Sep 19 '21 at 11:29
  • 1
    I've editing my question with some screenshots!
    – katagena
    Sep 19 '21 at 11:29

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.