5

I am using QGIS, and I have a shapefile that has 23 different land classifications. I have another file that lists coyote observations as points. I would like to find out how many coyote observations are found within each of the 23 categories.

I can create a separate shapefile for each land type and then run "count points in polygon" for each one but does QGIS provide an alternative approach?

Taras
  • 32,823
  • 4
  • 66
  • 137
DanG
  • 617
  • 5
  • 15
  • In ArcGIS Pro or ArcMap I would do Intersect followed by Summary Statistics (using land type to group by) so you could look for tools in QGIS with similar names. – PolyGeo Dec 15 '20 at 04:49
  • 2
    This Group Stats plugin in this answer may be helpful: https://gis.stackexchange.com/a/43042/8104 – Aaron Dec 15 '20 at 05:20

3 Answers3

7

You can use the algorithm "Join attributes by location (Summary)".

For my example, I have two layers : points (your coyotes), polygons (your areas).

enter image description here

Run the algorithm Join attributes by location (Summary) with the following configuration :

enter image description here

As a result, you get a layer with multiple statistics (which you can filter when running the algorithm), the one you are interested in is the count.

enter image description here

Taras
  • 32,823
  • 4
  • 66
  • 137
Vincent Bré
  • 4,090
  • 7
  • 23
  • The points are all within the same polygon (the metro area), so I was trying to do this without creating separate polygons for each land classification. – DanG Dec 15 '20 at 15:08
  • You don't have 23 features in your land layer? – Vincent Bré Dec 15 '20 at 15:09
  • I'm not sure what you mean. There is one large polygon representing the metro area. This polygon's attribute table has a column called "Land Use," in which there are 23 types of land use. But there is only one polygon filled with points. It looks like your solution would work if I had separate polygons representing each land use type. – DanG Dec 15 '20 at 15:17
  • Before using my algorithm, try using multipart to singlepart algorithm and dissolve them thanks to your classification field. Once you have 23 polygons you will be able to use my algorithm. – Vincent Bré Dec 15 '20 at 15:27
6

There is a possibility of using a "Virtual Layer" through Layer > Add Layer > Add/Edit Virtual Layer...

Let's assume there are two layers, a point layer called 'points' and a polygon layer called 'polygons', see the image below.

input

With the following query, it is possible to find out how many coyote observations are found within each of the categories.

SELECT
    poly.*,
    COUNT(*) AS "numpois"
FROM
    "polygons" AS poly
JOIN
    "points" AS poi
    ON st_within(poi.geometry, poly.geometry)
GROUP BY
    poly."id"

The output point layer with its attribute table will look like

output1

Mind, that if some fields have to be concatenated then apply the GROUP_CONCAT() function. So, the new query will look like

SELECT
    poly.*,
    COUNT(*) AS "numpois",
    GROUP_CONCAT(poi."Coyote") AS Coyotes
FROM
    "polygons" AS poly
JOIN
    "points" AS poi
    ON st_within(poi.geometry, poly.geometry)
GROUP BY
    poly."id"

And the output

output2

Taras
  • 32,823
  • 4
  • 66
  • 137
0

I believe this question was answered but just thought I would provide an alternative - the "Point Sampling Tool" plugin in QGIS is helpful in doing exactly what you describe.

Recommend checking it out and then importing the file to R or Excel for further analysis.

Taras
  • 32,823
  • 4
  • 66
  • 137