8

I have a series of points with various fields in the attribute table, including a car_id. I also have several polygons in which some of these points are located.

enter image description here

I want to count how many unique car_id's occur in each polygon. For example, if there are multiple points in a polygon where car_id = 25, the car_id = 25 should be counted once. The car_id count for a polygon using the sample data below should be 4.

car_id = 25 car_id = 25 car_id = 25 car_id = 22 car_id = 22 car_id = 23 car_id = 24 

What is the best approach to achieve this? Or is there an appropriate QGIS tool available in QGIS 3 to do this?

I know that in QGIS 2.x the tool 'Count Unique Points In Polygon' would have worked. However this tool is not available anymore in QGIS 3.10.

1
  • have you had a look at v.vect.stats and count points in polygon? If so, how do they not suit your needs? Commented Feb 10, 2020 at 15:43

2 Answers 2

11

Count Points In Polygon tool in QGIS 3 counts the unique values, too. But first you have to select 'Class Field' parameter which is used to specify a unique field name.

enter image description here

8

You can run a SQL query in QGIS/database/DB Manager, something like the following :

SELECT polygon_id, COUNT (DISTINCT car_id) FROM point_layer, polygon_layer where st_intersects(point.geometry, polygon.geometry) group by polygon_id 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.