0

I'm very new to QGIS and I'm learning by practice and reading both QGIS documentation and StackExchange answers. However, I think one of the main tasks has been naming the concepts correctly and look for the correct question, so I want to know which concepts are involved in this problem and how to solve it:

I want to count points by polygon, it may sound easy, the thing is that I don't have well-defined polygons, I have a categorical variable, this is a sneek peak:

Map

I have created a different layer for each categorical variable (that's why each of them have different colors).

So my question is: How do I combine all the polygons of one layer in one non-continuous polygon? The final goal is counting all the points of another layer.

For example if I want to count points in a USA map, Alaska, Hawaii and another non-contiguous territories would count as well.

I would really appreciate if you have another idea to reaching what I want. However, this is how I think I could do it for the moment.

1

Your proposed approach would work, but you run the risk of long processing times in cases where you have many polygons, as you could create extremely complex geometries. To make non-continuous polygons (called "MultiPolygons"), you can use the tool Vector Geometry > Collect Geometries and specify your category attribute in the Unique ID fields parameter.

However, in cases which I mentioned, which could involve many polygons, you could use a slightly longer but also effective solution:

  1. Make sure your point layer has a unique id field

  2. Run Vector General > Join attributes by location (summary), with your polygon layer as Input layer and the point layer as Join layer. In Fields to summarise, specify the unique id field in the point layer. In Summaries to calculate, specify count

  3. You will now have a new joined layer. Run Vector Analysis > Statistics by categories on this layer. Specify Field to calculate statistics on as [point layer id unique name]_count, and specify the polyon layer's category attribute name in Field(s) with categories.

  4. You now have a table count the number of points which coincide in each category. You can probably also see in the previous steps how you could calculate other interesting statistics, like minimum, maximum, average, etc.

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.