Count Distinct Values per Polygon in QGIS – Step-by-Step

countfields-attributespoint-in-polygonqgis

In QGIS I have a list of points, each with a town it's located in and a status, either 'new' or 'existing'. So something like:

ID town type
01 Alicetown new
02 Alicetown new
03 Alicetown existing
04 Bobsburgh existing
05 Bobsburgh new

I can count how many points are in each town (Alicetown: 3, Bobsburgh: 2), but I'd like to count how many new and existing points are in each (Alicetown: New: 2, Existing: 1; Bobsburgh: New: 1, Existing: 1).

I could just make a column for existing and new but I figured there has to be an easier way.

Is there a way to achieve what I'm trying to do? I've tried SQL but I don't really know enough about it to get it to do what I want.

Best Answer

Perhaps the simplest way is to use the Statistics by category tool. It creates a new table, summarising your input.

Select the fields by which to categorise, and leave Field to calculate statistics on blank to get the count only:

enter image description here

Result

enter image description here

Related Question