<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
mso-ligatures:standardcontextual;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="#0563C1" vlink="#954F72" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal">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?<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">project_element_id = deleted_feature[project_element_id_index]<br>
KeyError: '7'<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">****************************************************************************<o:p></o:p></p>
<p class="MsoNormal">def delete_from_jcms_dsk_local_database(self, site_planning_layer: QgsVectorLayer):<o:p></o:p></p>
<p class="MsoNormal"> element_type = 'FACILITY'<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal"> deleted_feature_ids = site_planning_layer.editBuffer().deletedFeatureIds()<o:p></o:p></p>
<p class="MsoNormal"> QgsMessageLog.logMessage(f"deleted_feature_ids: {deleted_feature_ids}", "Placed Elements", Qgis.Info)<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"> site_planning_layer_fields = site_planning_layer.fields()<o:p></o:p></p>
<p class="MsoNormal"> project_element_id_index = site_planning_layer_fields.indexFromName("project_element_id")<o:p></o:p></p>
<p class="MsoNormal"> QgsMessageLog.logMessage(f"project_element_id index: {project_element_id_index}", "Placed Elements", Qgis.Info)<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"> for deleted_feature_id in deleted_feature_ids:<o:p></o:p></p>
<p class="MsoNormal"> deleted_feature = site_planning_layer.getFeature(deleted_feature_id)<o:p></o:p></p>
<p class="MsoNormal"> QgsMessageLog.logMessage(f"deleted_feature.hasGeometry: {deleted_feature.hasGeometry()}", "Placed Elements", Qgis.Info)<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"> deleted_feature_attributes = site_planning_layer.getFeature(deleted_feature_id).attributes()<o:p></o:p></p>
<p class="MsoNormal"> QgsMessageLog.logMessage(f"deleted_feature_attributes: {deleted_feature_attributes}", "Placed Elements", Qgis.Info)<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal"> project_element_id = deleted_feature[project_element_id_index]<o:p></o:p></p>
<p class="MsoNormal"> QgsMessageLog.logMessage(f"deleting: {site_planning_layer.name()} - {project_element_id}", "Placed Elements", Qgis.Info)<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Luke Catania<o:p></o:p></p>
<p class="MsoNormal">US Army ERDC-GRL<o:p></o:p></p>
<p class="MsoNormal">JCMS Site Planning Developer<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>