2

I'm trying to delete a virtual field from a layer attribute table. The layer source is a Spatialite database so I know that it's not straightforward to remove permanent fields, but as I understand it virtual fields are stored in the project file, not the database. I followed the answer to this question, but when I try to edit the attribute table the 'Delete field' button remains greyed out:

enter image description here

UPDATE: I've now discovered that the above happens if the layer is added using Layer->Add Layer->Add Vector Layer, but not if using ...->Add Spatialite Layer, in which case a virtual field CAN be deleted using the appropriate button. I'm a relative beginner, and I hadn't realised it was possible to add Spatialite layers in 2 different ways. However I'm still not clear if this is a bug, or actually correct behaviour, as I don't understand the difference between the two methods of adding layers (though this is probably a separate question).

  • 2
    I can confirm that's a behaviour in 2.18.10 - I guess it's because you're using a spatialite database as your input source because it seems to work fine for shapefiles. One solution that works for me is to remove the dataset from the TOC, save the project, and then re-add the dataset. This does away with the virtual field. Might be worth logging a bug ticket as I'm guessing its deactivating the delete column because its a spatialite table, without realising its looking at a virtual field? – Ed Rollason Sep 5 '17 at 21:22
  • 1
    I just did a test with QGIS 2.18.12, erasing a virtual field (spatial database) works, the icon is activated. – pigreco Sep 6 '17 at 6:43
  • @Ed Rollason - I tried your workaround (by saving layer style, removing layer in Layer Panel, saving project, re-adding layer and re-applying layer style) and it removed all the virtual fields, as you say. Handy to know (and thanks), though obviously it would be preferable to remove specific fields rather than all of them. – Libarch Sep 6 '17 at 10:38
  • Can you show the formulas used for the virtual fields? If the Households field is referenced in the Restricted Households field, you have to delete that first. – AndreJ Sep 6 '17 at 13:40
  • @AndreJ - I'd already deleted them both, as my comment above lol:) But I've recreated a single field Restricted Households with expression: CASE WHEN "delivery_point:access" IN ( 'restricted' , 'timed' ) THEN CASE WHEN "building:flats" <> NULL THEN "building:flats" WHEN "building" = 'house' THEN 1 END ELSE 0 END Even with this single virtual field the 'Delete field' button is unavailable – Libarch Sep 6 '17 at 14:36
2

I just did a test with QGIS 2.18.12, erasing a virtual field (spatial database) works, the icon is activated

enter image description here

enter image description here

  • I am also using 2.18.12 (on Windows 10 64bit). The layer source database file is dbname='D:/Rick/Documents/Maps/QGIS projects/WR 2017-18 transition/OSM_WR.osm.db' table="OSM_WR_polygons" (geometry) sql=, does this make a difference? – Libarch Sep 6 '17 at 7:48
  • probably linked to the path, avoids spaces and special characters. – pigreco Sep 6 '17 at 10:02
  • So is it a bug, or is it a requirement to avoid such characters in pathnames? – Libarch Sep 6 '17 at 10:40
  • 2
    Works for me even with blanks in folder paths. – AndreJ Sep 6 '17 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.