Skip to main content
1 of 5
rudivonstaden
  • 5.4k
  • 4
  • 27
  • 43

The situation may have changed as far as this question is concerned. If you add a layer from a database connection, you can edit the layer while a filter is applied. This works with SpatiaLite and PostGIS, and I assume that it also works with Oracle and MSSQL connections. If this is the main functionality you need, though, SpatiaLite is easiest to work with as it is a file-based database and well supported in QGIS.

Step 1

If you have an existing layer you want to have editable while filtering, you can save the layer as a SpatiaLite database by right-clicking on the layer and choosing 'Save As...'. In the dialog that opens, set the Format as 'SpatiaLite', and choose a filename and location for the file.

Save as Spatialite

Note that it's best not to select 'Add saved file to map' as it would add it as a regular file layer rather than as a database connection, and you wouldn't be able to filter it that way.

Step 2

In the menu, click Layer > Add SpatiaLite Layer. Click the 'New' button, and then browse to your SpatiaLite file (the extension will be .sqlite). Then click the 'Connect' button to create a link to the database. Select the table name, then click the Add button to add it as a layer to QGIS.

Add SpatiaLite tables

Step 3

You can then set a filter on the layer by right-clicking, and selecting 'Filter...' from the context menu. Apply your filter using the Query Builder.

Set filter

Step 4

With the filter active, you can now edit the layer using the canvas or the attribute table.

Apply edits

Note that you will not be able to change the filter while the layer is in edit mode, but you can turn off edit mode, change the filter, and then turn editing on again. You can also add additional layers to your project and keep them all in the same SpatiaLite database as separate tables.

rudivonstaden
  • 5.4k
  • 4
  • 27
  • 43