Monday, October 24, 2022

QGIS unable to edit SpatiaLite database layer workaround

Recently I upgraded to QGIS 3.26 on Ubuntu 22.04 and found that I was unable to edit my existing SpatiaLite database layers, i.e. the Toggle Editing tool bar icon could not be enabled. The screenshot below illustrates the problem.

While I have not found the cause of the problem, I found a simple workaround to the issue: just create a new SpatiaLite database and import the layers from the old database. The newly imported database layers can be enabled for editing. 

 

Create a new SpatiaLite database

  1. In the Browser pane of QGIS, press the right mouse button on the SpatiaLite node.



    A pop up menu appear.

  2. Choose Create New Database.



  3. In the Name field, type in a new SpatiaLite database file name, e.g. new_rail.sqlite. Click Save.

    The database is created.


Import layers from the old SpatiaLite database to the new SpatiaLite database

  1. If the layer e.g. node from the old SpatiaLite database e.g. rail.sqlite is not displayed in QGIS, then add the layer to the map window.


  2. In the QGIS menu, select Database | DB Manager.

    The DB Manager dialog box appears.


  3. Expand the SpatiaLite Providers tree node and double click on the newly created SpatiaLite database, e.g. new_rail.sqlite.



  4. Click Import Layer/File.

    The Import vector layer dialog box appears.


  5. In the Input drop down list, choose the layer from the old database, e.g. nodes. In the Output Table field, type in a new table name, e.g. nodes. Click OK.

    The old layer is imported into the new database.

Displaying the newly imported Spatialite layer

  1. In QGIS, select Layer | Add Layer | Add SpatiaLite Layer.



  2. In the Connections drop down list, select the new SpatiaLite database, e.g. new_rail.sqlite. Click Connect.

  3. In the table list, select the new layer nodes. Click Add.

    The new nodes layer is displayed in the map window.


  4. Select the new layer nodes in the Legend pane.

    The Toggle Editing icon is enabled now.


No comments:

Post a Comment