I have joined temperature values from the point layer to intersecting polygons but I have few polygons (yellow in the image) that don't contain any point data.

Can I somehow get average temperature values from adjacent polygons or get temperature value from the nearest data point? Now the temperature values in these polygons have NULL values because of lack of data points.

enter image description here


You can use QGIS expressions with the new overlay_nearest function, availble since QGIS 3.16 and the array_mean() function, available since QGIS 3.18.

If you already have an attribute in the polygon layer (lets say with fieldname values), than applying this epxression on the polygon layer with field calculator will get you the mean value of the neighboring feature's values field. The limit:=10 defines from how many polygons (in the order of the distance to the current feature) you take the values to calculate the mean. You can change this. Setting it to 5 means that only the value of the five nearest polygons is taken into consideration.

array_mean (


If you replace overlay_nearest with overlay_touches, you only get the polygons that border on (touch) your polygon.

If you replace @layer on the third line with 'points' (the name of your point layer), you can use the same expression to refer to the nearest 10 (or 5 or whatever) points. Further options include defining a maximum distance up to which points should be consideres - just add ,max_distance:= 120 after the limit condition.

Screenshot: the field calculator calculates a value of 18 (see the preview at the bottom), based on the 10 nearest polygons. The lines (created with an expression based on this one) are a visualization helping to understand from which values the mean is calculated: the ten nearest polygons. array_mean () returns the mean value of the values attribute of these ten features:

enter image description here

  • Thank you! I got this to work. I have 10 municipalities (polygons) that have this same problem in about 50 attribute fields. Do you know if it's possible to do this operation for multiple fields simultaneously? Apr 7 '21 at 12:43
  • 1
    You can use menu Processing / Tollbox / Field calculator and than select batch mode. However, for each field created, a separate putput (file) will be generated... You could than join it back to your original layer. However, there might be better solutions around. Maybe ask this as another question here.
    – Babel
    Apr 7 '21 at 12:55

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.