My question relates to a work-around that I assumed might work, instead of trying this: Count points per polygon, classify point count in original layer in QGIS as all counting attempts have either failed or returned a wrong count number.

I have a layer with polygons (buffers), each polygon has been assigned a unique ID (IDBuffer). I have a second point-layer with the column "neue_bez", in which there are three classes (Kultur, BildungHochschule, NaherholungFreizeit) and a column that assigns each point a unique ID (IDBaupoint), too.

I want to know how many points of each class are within each polygon and I need this information added to the original polygon-layer in three columns (one for each class of "neue_bez"). I know I can get the raw information from a statistic by category, selecting IDBuffer and neue_bez like so:

example of my statistic by cat

But as mentioned, I would like a column added for each of the three classes, containing the count for that class per polygon.

This far, I have already intersected the two mentioned layers, so that I now have a layer that contains both IDs (IDBuffer, IDBaupoint), as well as the column "neue_bez" and thus the three classes.

enter image description here

I have since tried the following functions in the attribut table, to create a count-column for the class "Kultur" from the column "neue_bez"- for each polygon

sum(count("neue_bez", group_by:="IDBuffer", filter:="Kultur"))

This just returns 0 for every row.

I tried

count("neue_bez", group_by:="IDBuffer")

But this just returns the overall count of points per polygon and doesn't classify them.

Lastly, another idea I had was:


Which doesn't work/is invalid, because right now I'm asking it to sum up "neue_bez", although the content is not numerical. If I created a column that just held the value "1" in each field to represent the amount of entries, could this then work, including the two expressions of group_by and filter?

Are there more elegant ways of doing this than my last idea?

  • 1
    Have you tried using overlay_intersects() with the count()-part as expression on the unprocessed polygon layer?
    – Erik
    Commented Aug 30, 2022 at 11:43
  • I have tried something similar with the overlay-function: array_length(overlay_intersects('pointlayername',$id,filter:="fieldcontainingcategory"='nameofcategory')) But the count was never right when I checked for overlapping polygons. Could you specify your approach please, if it differs from this one?
    – gruenbet
    Commented Aug 30, 2022 at 11:46
  • 1
    If the count is incorrect with this function check if both layers are in the same CRS
    – MrXsquared
    Commented Sep 3, 2022 at 11:28

1 Answer 1


Use QGIS expressions with overlay_contains() with the following pattern on your polygon layer to get the number of points from layer points with attribute Kultur that has a value of 14:

        'points',  -- replace with name of your point layer
        filter:=Kultur=14  -- replace with attribute name/value

Expression inserted as dynamic label: the large number counts how many points with attribute Kultur=14 each polygon contains: 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.