QGIS Aggregate Function using Contains

  • Software: QGIS 3.20
  • OS: Any
  • Updated: August 2021

In this example I have some data which are points (Parks) and I want to pull the an attribute from a polygon layer (Parcels) into the data – BUT I don’t want to do a spatial join. In this case we are going to use the aggregate function in field calculator. The Aggregate function allows you to pull data from another layer into your current layer without having to run a processing tool.

We have points and polygons.

Edit the point layer and open the field calculator

From there you want to create a new field that will hold the tax_map_no in the point layer. I will call that field parcel and and make it a text string.

The aggregate expression will look like the following:

 layer:= 'parcels',
 expression:= "tax_map_no",
 concatenator:=', ',
 filter:=contains($geometry, geometry(@parent))

That little bit of code is doing the following: It’s using the parcel layer and return the values held in “tax_map_no”. In case there is more than one value (there won’t be in this case) use a comma as a delimiter. The filter section specifies to make sure the point features ($geometry) reside within the geometry of the Parcels (@parent)

At the end you have a new field in your point layer that has the value from the polygon.

Want QGIS Training? Need help with a project? Give us a shout at info at northrivergeographic.com