[QGIS-Developer] Get attribute of deleted feature
Catania, Luke A ERDC-RDE-GRL-VA CIV
Luke.A.Catania at erdc.dren.mil
Thu Oct 17 20:52:36 PDT 2024
I want to get the attribute (project_element_id) of a feature that I delete. I found a way to get the feature IDs, but want a specific attribute, but get error below. Assume maybe because the feature has been deleted so can't get its attributes, so how do I get it just before the feature is deleted?
project_element_id = deleted_feature[project_element_id_index]
KeyError: '7'
****************************************************************************
def delete_from_jcms_dsk_local_database(self, site_planning_layer: QgsVectorLayer):
element_type = 'FACILITY'
deleted_feature_ids = site_planning_layer.editBuffer().deletedFeatureIds()
QgsMessageLog.logMessage(f"deleted_feature_ids: {deleted_feature_ids}", "Placed Elements", Qgis.Info)
site_planning_layer_fields = site_planning_layer.fields()
project_element_id_index = site_planning_layer_fields.indexFromName("project_element_id")
QgsMessageLog.logMessage(f"project_element_id index: {project_element_id_index}", "Placed Elements", Qgis.Info)
for deleted_feature_id in deleted_feature_ids:
deleted_feature = site_planning_layer.getFeature(deleted_feature_id)
QgsMessageLog.logMessage(f"deleted_feature.hasGeometry: {deleted_feature.hasGeometry()}", "Placed Elements", Qgis.Info)
deleted_feature_attributes = site_planning_layer.getFeature(deleted_feature_id).attributes()
QgsMessageLog.logMessage(f"deleted_feature_attributes: {deleted_feature_attributes}", "Placed Elements", Qgis.Info)
project_element_id = deleted_feature[project_element_id_index]
QgsMessageLog.logMessage(f"deleting: {site_planning_layer.name()} - {project_element_id}", "Placed Elements", Qgis.Info)
Luke Catania
US Army ERDC-GRL
JCMS Site Planning Developer
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20241018/1beae09d/attachment.htm>
More information about the QGIS-Developer
mailing list