Counting number of distinct areas in cell using QGIS

africacountoverlapping-featurespolygonqgis

On the figure below, I have:

  • a shapefile of cells of 0.5×0.5 degrees around the African continent
  • a shapefile of different regions in Africa

enter image description here

I would like to count the number of separate regions which pass through out each cell (see the second picture for an example). In the selected cell, there are three separations (three regions).

Hence, in the final output, I would like to assign a three to that cell. I would like to do it with every cell of my grid.

My version of QGIS is 3.20.1.

enter image description here

Second problem: when I try to do the suggestion of @BERA

I do what @BERA suggested (look the screenshot). "polygons" is my grid cell and border_tribes is the shapefile with the regions. However, I do not obtain the results. In fact, in every cell I obtain a value of 1 for each grid cell. In the second image, I attach another screen shot of the kind of results I obtain. The number should be 3 but it appears 1.

enter image description here

enter image description here

Third problem: when I try to do @BERA suggested in the comments as a possible solution to problem 2

When I change "borders_tribes" by grid, I obtain a result of 8 in each cell. I attach a picture of what I am doing and an example of the problem.

enter image description here

enter image description here

Best Answer

An alternative using Processing tools:

Search for "Join Attributes By Location (Summary)" in the processing toolbox. Choose the following settings:

  • Base Layer: Your Grid Layer
  • Join Layer: Your Regions Layer
  • Geometric Predicate: Intersects
  • Fields to summarise: A unique key of your Regions layer
  • Summaries to calculate: Count and/or Unique

Run it. Output is a copy of your grid layer containing the count and/or unique count of intersections with your regions layer.

enter image description here

Example result:

enter image description here

In case you cannot find the processing toolbox, go to View -> Panels and enable Processing Toolbox. Then type the name of the processing tool into the search box:

enter image description here