Skip to Content
Mastering Geospatial Analysis with Python
book

Mastering Geospatial Analysis with Python

by Silas Toms, Paul Crickard, Eric van Rees
April 2018
Beginner to intermediate content levelBeginner to intermediate
440 pages
11h 36m
English
Packt Publishing
Content preview from Mastering Geospatial Analysis with Python

Deleting features from an existing layer

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning Geospatial Analysis with Python

Learning Geospatial Analysis with Python

Joel Lawhead

Publisher Resources

ISBN: 9781788293334Supplemental Content