diff --git a/varennes_single_processes/add_height_to_nrcan.py b/varennes_single_processes/add_height_to_nrcan.py index f72c5eb..100edb5 100644 --- a/varennes_single_processes/add_height_to_nrcan.py +++ b/varennes_single_processes/add_height_to_nrcan.py @@ -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()