Delete feature by index method

This commit is contained in:
Alireza Adli 2024-08-16 12:23:04 -04:00
parent e849ca568c
commit ac3c44b965

View File

@ -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)}')