I have a vector layer with 50 columns/fields. I have been trying to find a way of selecting 6 columns of particular interest (by name or index) and then creating a new layer from that selection, such that my new layer only has those 6 columns within it. I am hoping to achieve this with PyQGIS
At present, the only way I've solved this is to create a copy of the layer and then, following the documentation, delete attributes I don't want to keep from that copied layer. Seems very clunky. I would prefer a method that does this by selection rather than deletion
caps = layer.dataProvider().capabilities() if caps & QgsVectorDataProvider.DeleteAttributes: res = layer.dataProvider().deleteAttributes([43,42]) layer.updateFields()
Is there a more elegant way of doing this?