From ac3c44b9657f659a540ab847caedd6bbe3f738ba Mon Sep 17 00:00:00 2001 From: Alireza Adli Date: Fri, 16 Aug 2024 12:23:04 -0400 Subject: [PATCH] Delete feature by index method --- scrub_layer_class.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/scrub_layer_class.py b/scrub_layer_class.py index 06fa23c..5d39578 100644 --- a/scrub_layer_class.py +++ b/scrub_layer_class.py @@ -194,6 +194,16 @@ class ScrubLayer: # Update layer fields self.layer.updateFields() + def delete_record_by_index(self, record_index): + self.layer.startEditing() + + if self.layer.deleteFeature(record_index): + print(f"Feature with ID {record_index} has been successfully removed.") + else: + print(f"Failed to remove feature with ID {record_index}.") + + self.layer.commitChanges() + def conditional_delete_record(self, field_name, operator, condition): request = QgsFeatureRequest().setFilterExpression( f'{field_name} {operator} {str(condition)}')