Remove the condition
This commit is contained in:
parent
bd2a523f46
commit
a714954ce3
@ -42,7 +42,7 @@ varennes_nrcan.delete_field('comment')
|
|||||||
varennes_nrcan.layer.startEditing()
|
varennes_nrcan.layer.startEditing()
|
||||||
|
|
||||||
# Add a new field for the height
|
# 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.dataProvider().addAttributes([weighted_height])
|
||||||
varennes_nrcan.layer.updateFields()
|
varennes_nrcan.layer.updateFields()
|
||||||
|
|
||||||
@ -55,14 +55,11 @@ for feature in varennes_nrcan.layer.getFeatures():
|
|||||||
height_min = feature[height_min_idx]
|
height_min = feature[height_min_idx]
|
||||||
height_max = feature[height_max_idx]
|
height_max = feature[height_max_idx]
|
||||||
|
|
||||||
if height_min is not None and height_max is not None:
|
average_value = (2/3 * round(height_min, 3) + 1/3 * round(height_max, 3))
|
||||||
average_value = (2/3 * height_min + 1/3 * height_max)
|
|
||||||
else:
|
|
||||||
average_value = None
|
|
||||||
|
|
||||||
# Update the new field with the calculated average
|
# Update the new field with the calculated average
|
||||||
varennes_nrcan.layer.changeAttributeValue(
|
varennes_nrcan.layer.changeAttributeValue(
|
||||||
feature.id(), weighted_height_idx, average_value)
|
feature.id(), weighted_height_idx, round(average_value, 3))
|
||||||
|
|
||||||
# Commit the changes
|
# Commit the changes
|
||||||
varennes_nrcan.layer.commitChanges()
|
varennes_nrcan.layer.commitChanges()
|
||||||
|
Loading…
Reference in New Issue
Block a user