Skip to main content
5 of 5
replaced http://gis.stackexchange.com/ with https://gis.stackexchange.com/

Currently you can't edit a Shapefile layer while it is filtered. However, if you add a database layer, 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. In many ways it's as easy to work with as a Shapefile (see Advantages of using spatialite over shapefile?).

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 edit it while filtered. For the same reason, dragging and dropping a SpatiaLite file into your QGIS workspace will add the file to your project, but it won't be editable while a filter is applied.

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.

These instructions should work for QGIS 2.0 and up, but may not work for earlier versions.

rudivonstaden
  • 5.4k
  • 4
  • 27
  • 43