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
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.
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.
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.
Best Answer
An alternative using Processing tools:
Search for "Join Attributes By Location (Summary)" in the processing toolbox. Choose the following settings:
Grid Layer
Regions Layer
Intersects
unique key
of your Regions layerCount
and/orUnique
Run it. Output is a copy of your grid layer containing the count and/or unique count of intersections with your regions layer.
Example result:
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: