2

I have a vector layer of Voronoi polygons. This layer has three columns -longitude, latitude, Z-value. enter image description here

I need to cut polygons by mask of administrative area and then I need to calculate average-weighted Z-value (AWZ) for every administrative area with use of formula:

AWZ = SUM(Z-value*Square_of_polygon_inside_area)/SUM(Square_of_polygon_inside_area)

How should I solve this problem?

1

I am interested in knowing the theory that develops the calculation of the average of weighted elevation by the square of the areas. If you could share it in the comments I would appreciate it.


  • Make sure that both layers contain singlepart features (Multipart to singleparts) and valid geometries (Fix geometries). Also, make sure that both layers are defined in the same CRS (Reproject Layer).

  • Populate a field (Using Field Calculator) in both attribute tables with the feature's identifier ($id expression).

  • Perform the union (Union) between both layers.

  • Select by Value (Select Features by Value) the resulting features in the Union layer that have null value (is missing operator) for any of the identification columns, and delete them (Deleting Selected Features).

  • Calculate the square of the area, for each feature.

    • If you are working with a projected coordinate system, you can calculate the square of the planimetric area with the expression: (area($geometry))^2.
    • If you are working with a geographic coordinate system instead (or if you just want to use the ellipsoidal area), you can select the appropriate ellipsoid in the project properties (General Properties) and calculate the square of the ellipsoidal area of each feature wth the expression: ($area)^2.
  • Calculate the weigthed average for the elevation.

There are some ways to do that. All of them implies to use the SUM agreggate function. The simplest way seems to me populate a new field in the administrative layer with the following expression:

aggregate( 
  'Union', 
  'sum', 
  "area" * "z", 
  "id_2" = attribute( @parent, 'id'))
/
aggregate(
  'Union', 
  'sum', 
  "area",
  "id_2" = attribute( @parent, 'id'))

Where 'Union' is the name of the joined by the aggregate function layer (the Union layer in this case), 'sum' is the aggregate to calculate, "area" is the name of the field of the squared area calculated in the joined layer, "z" is the name of the field of the elevations in the joined layer, and "id_2" = attribute( @parent, 'id') is the filter by matching values between the id_2 field of the joined layer with the value of the id field for each feature of the source layer (the administrative layer in this case).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.