Complete the workflow
This commit is contained in:
parent
e58710e892
commit
bd2a523f46
|
@ -37,11 +37,35 @@ varennes_nrcan.delete_field('min_x')
|
||||||
varennes_nrcan.delete_field('min_y')
|
varennes_nrcan.delete_field('min_y')
|
||||||
varennes_nrcan.delete_field('max_x')
|
varennes_nrcan.delete_field('max_x')
|
||||||
varennes_nrcan.delete_field('max_y')
|
varennes_nrcan.delete_field('max_y')
|
||||||
|
varennes_nrcan.delete_field('comment')
|
||||||
|
|
||||||
|
varennes_nrcan.layer.startEditing()
|
||||||
|
|
||||||
# varennes_nrcan_duplicate.delete_field('heightmin')
|
# Add a new field for the height
|
||||||
# varennes_nrcan_duplicate.delete_field('heightmax')
|
weighted_height = QgsField('building_height', QVariant.Double)
|
||||||
# varennes_nrcan_duplicate.delete_field('elevmin')
|
varennes_nrcan.layer.dataProvider().addAttributes([weighted_height])
|
||||||
# varennes_nrcan_duplicate.delete_field('elevmax')
|
varennes_nrcan.layer.updateFields()
|
||||||
# varennes_nrcan_duplicate.delete_field('bldgarea')
|
|
||||||
# varennes_nrcan_duplicate.delete_field('comment')
|
height_min_idx = varennes_nrcan.layer.fields().indexOf('heightmin')
|
||||||
|
height_max_idx = varennes_nrcan.layer.fields().indexOf('heightmax')
|
||||||
|
weighted_height_idx = varennes_nrcan.layer.fields().indexOf('ave_height')
|
||||||
|
|
||||||
|
# Iterate through each feature and calculate the average weighted height
|
||||||
|
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
|
||||||
|
|
||||||
|
# Update the new field with the calculated average
|
||||||
|
varennes_nrcan.layer.changeAttributeValue(
|
||||||
|
feature.id(), weighted_height_idx, average_value)
|
||||||
|
|
||||||
|
# Commit the changes
|
||||||
|
varennes_nrcan.layer.commitChanges()
|
||||||
|
|
||||||
|
print('Average weighted height calculation (ave_height)'
|
||||||
|
' for buildings completed successfully!')
|
||||||
|
|
Loading…
Reference in New Issue
Block a user