1

In my script I'm trying to save some vector layer after processing it. In the rest of the script it works fine but in this section (after the if condition) I keep getting an error, no matter in which processing part I'm trying to save it. I tried to run this section in the console and it works just fine, but within the script there is something wrong and I cant find the solution. Any ideas / work arounds maybe?

Could not create layer S:\BER\GIS_Daten\Methodenentwicklung\Vogelschutzmodell\Dichtezentren_Ordner\dichtezentren_v_00_00_02\02_zwischen\220704_2204_dichtezentren\02_ergebnisse\Prüfbereiche_2\union_delete_id\Nahbereich_Kornweihe.gpkg: Creation of data source failed (OGR error: sqlite3_open(S:\BER\GIS_Daten\Methodenentwicklung\Vogelschutzmodell\Dichtezentren_Ordner\dichtezentren_v_00_00_02\02_zwischen\220704_2204_dichtezentren\02_ergebnisse\Prüfbereiche_2\union_delete_id\Nahbereich_Kornweihe.gpkg) failed: unable to open database file)

Blockquote

        if feats_count > 1: 
            
            union = processing.run("native:union", {
            'INPUT':prueflayer,
            'OVERLAY':None,
            'OVERLAY_FIELDS_PREFIX':'',
            'OUTPUT':'TEMPORARY_OUTPUT'})
            #'OUTPUT': union_art_ordner + '\\' + 'union_' + shapefileshortname})
            
            feedback.setProgressText('----------------------------------------------------------------------------------------------------------------------------------------------------------------------------')
            randompoints_union_expr=' '.join(('union',str(prueflayer),'.'))
            feedback.setProgressText(randompoints_union_expr)
            
            
            union_delete_geom = processing.run("native:deleteduplicategeometries", {
            'INPUT': union ['OUTPUT'],
            'OUTPUT':'TEMPORARY_OUTPUT'})
            #'OUTPUT': union_delete_id_art_ordner + '\\' + 'union_single_id' + shapefileshortname})

            union_single_id = processing.run("qgis:fieldcalculator", {
            'INPUT': union_delete_geom ['OUTPUT'],
            'FIELD_NAME': 'unique_id', 
            'FIELD_TYPE': 2, 
            'FIELD_LENGTH': 80, 
            'FIELD_PRECISION': 3, 
            'NEW_FIELD': True,
            'FORMULA': ' $id ', 
            'OUTPUT': union_delete_id_art_ordner + '\\' + 'union_delete_id' + '\\' + shapefileshortname})
        else:
            pass
enter code here
1
  • 1
    Please always provide error messages as formatted text rather than pictures.
    – PolyGeo
    Jul 4, 2022 at 19:23

1 Answer 1

2

The error message says that the database driver is not able to create the file it should be writing to. In my experience, this is usually caused by one of three problems:

  • Trying to write to a write protected directory
  • Trying to write to a non-exisistant directory
  • Trying to write to a file that is held open by another (or the same) process.

When I get into these problems, I am often trying to write to the simplest possible path to be sure there are no problems with the path I am writing to. If that works, it is time to go carefully through the path to make sure all parts are correct - or add in some other test earlier in the code that tries to write a file to the same directory just to check if it is working.

If you are absolutely sure the paths are correct and the directory is writeable, there is probably some locking issue. A way to find out if that is the case, is to export the data to the same directory but with a different file name.

1
  • Okay thanks a lot! It works if I save the output to another path.. Still not sure why the path I wanted to save it to is not accepted because for other outputs the path worked already. But I spent already way too much time with it and have to move on.
    – Tim
    Jul 4, 2022 at 20:23

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.