In this recipe, we'll wipe out an entire attribute and all the feature fields for a vector layer.
You will need the New York City museums' shapefile used in other recipes, which you can download as a ZIP file from https://geospatialpython.googlecode.com/svn/NYC_MUSEUMS_GEO.zip.
Extract this shapefile to /qgis_data/nyc
.
This operation is straight forward. We'll load and validate the layer, use the layer's data provider to delete the attribute by index, and finally, we will update all the fields to remove the orphaned values. To do this, we need to perform the following steps:
vectorLyr = QgsVectorLayer('/qgis_data/nyc/NYC_MUSEUMS_GEO.shp', 'Museums' , "ogr") vectorLyr.isValid()
vectorLyr.dataProvider().deleteAttributes([1])
vectorLyr.updateFields()