In QGIS 3, I have two layers:

  • Polygon layer representing properties including an attribute on the type of property: residential, commercial, industrial, open space etc.

  • point layer representing connections to watermains

I have used the NNJoin plugin to determine the closest point for each of the properties, and this reference is now in the property layer.

For each point, I now want to sum the number of properties of each type and add this to point layer.

For example:

Point  Residential Commercial Industrial etc
 1        3           0           4
 2        7           2           5
 5000     5           5           15

I was going to export it to Excel to undertake a series of "Sum Ifs", but didn't want to take it out of GIS unless I had to.

Is there a method to achieve this in QGIS?


Assuming your point layer has 1 attribute: 'point_id' and your polygon layer has 3 attributes: 'pgon_id', 'type' and 'closest_point'

  1. Run the toolbox 'Join attributes by field value' with the inputs set as the screenshot below.

enter image description here

  1. Open field calculator on your new joined layer and create a new field "Residential" of type integer with the expression count( "type" , "point_id" , "type" = 'residential' ).
  2. Repeat step 2 for each type of property (industrial etc...) and save edits.
  3. Run the toolbox 'Delete duplicates by attribute' with the new joined layer as the input layer and point_id set as the field to match duplicates by.
  4. Delete the fields 'pgon_id', 'type' and 'closest_point' from the new layer. You will be left with an attribute table like the one below.

enter image description here

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.