8

I am new to Quantum and I am digitizing polygon layers using the editing features. I would like to apply simple queries ('date > 2012/08/01'), however while the query is active I cannot edit the layer. Is this possible?

2 Answers 2

15

No, it's not possible to enable editing on filtered layers.

You can try using a rule-based renderer instead of a filter. Set the rule so that only your features of interest are displayed. Then enable editing.

4
  • Thank you for help, it did exactly what I needed it to. Rule-based rendering is a pretty useful feature.
    – Brandon G
    Commented Aug 30, 2012 at 17:20
  • Glad I could help. Please accept the answer by clicking the tick mark under the vote counter to the left if your question is answered.
    – underdark
    Commented Aug 30, 2012 at 17:55
  • is this still true on QGis 2.18 ?
    – user16542
    Commented Sep 22, 2017 at 8:00
  • @user16542 Yes it still true Commented Aug 23, 2018 at 14:27
4

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.

0

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.