7

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.

4
  • 2
    Welcome to GIS SE. As a new user, please take the Tour. Please Edit the Question to show what SQL you tried, and what the result was, , so we can recommend a fix.
    – Vince
    Dec 7, 2022 at 2:52
  • What are you expecting to achieve as the final output, a new column in existing layer, a new table, a new layer etc. ?
    – Taras
    Dec 7, 2022 at 6:10
  • I'm probably expecting a table but really, I'd be okay with any kind of output. Another comment already helped me to achieve what I was trying to do but I'd gladly learn about other methods too. Dec 7, 2022 at 15:47

2 Answers 2

9

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

1
  • Oh yea...that's what I was trying to do. I did the initially count with this tool but it never occurred to me I could just add more fields with categories :'D Thanks a lot! Dec 7, 2022 at 15:45
7

With SQL and a Virtual Layer you can try:

select town, type, count(*) pointcount, geometry
from pointlayer
group by town, type

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.