April 2018
Beginner to intermediate
440 pages
11h 36m
English
Deleting features can be done in a single line of code following the format as shown:
LayerName.dataProvider().deleteFeatures([list of id])
In the previous code, you use deleteFeatures() and the id of the layer. The id is the feature.id(). It is a number held internally and not in a user assigned attribute. To get the id of a specific feature you can iterate through them as you learned earlier in this chapter. The following code shows you how to delete the feature we created in the previous section:
for x in scf.getFeatures(): if x["ID"]==311: scf.dataProvider().deleteFeatures([x.id()])
The previous code iterates through the features in the layer looking for the one with the ID of 311. When it finds ...