Remove the condition

This commit is contained in:
Alireza Adli 2024-08-27 13:39:56 -04:00
parent bd2a523f46
commit a714954ce3

View File

@ -42,7 +42,7 @@ varennes_nrcan.delete_field('comment')
varennes_nrcan.layer.startEditing()
# Add a new field for the height
weighted_height = QgsField('building_height', QVariant.Double)
weighted_height = QgsField('ave_height', QVariant.Double)
varennes_nrcan.layer.dataProvider().addAttributes([weighted_height])
varennes_nrcan.layer.updateFields()
@ -55,14 +55,11 @@ for feature in varennes_nrcan.layer.getFeatures():
height_min = feature[height_min_idx]
height_max = feature[height_max_idx]
if height_min is not None and height_max is not None:
average_value = (2/3 * height_min + 1/3 * height_max)
else:
average_value = None
average_value = (2/3 * round(height_min, 3) + 1/3 * round(height_max, 3))
# Update the new field with the calculated average
varennes_nrcan.layer.changeAttributeValue(
feature.id(), weighted_height_idx, average_value)
feature.id(), weighted_height_idx, round(average_value, 3))
# Commit the changes
varennes_nrcan.layer.commitChanges()