I have 2 shapefiles that cover a similar region, a river catchment and a hex-grid of surface water bodies within the catchment. The catchment has subcatchments, and I'm trying to link the hex-grids that overlay each sub-catchment in a column in the attribute table.
Using the geometry expressions in the Field Calculator in QGIS 3.28.4 LTR, I have got an expression that covers hexes that lie within (overlay_within
), but I also want to include the hexes that Overlap (Overlap
) in the expression.
I've been using the QGIS Documentation to understand the expression I want to write (Select By Location and 'Overlay_' geometry expressions), but my results only show the ones within, the ones that cross, or the ones that intersect, not only the first two that I want.
I want the expression to list in the hex-grid attribute table that Circle 1 AND Circle 2 are spatially connected to the Orange Box. Circles 3 and 4 would be spatially connected to Box 2.
At the moment I only have 2 separate expressions
array_to_string(overlay_within('Box',Box_ID))
which returns
Circle ID | Connected to Box_ID |
---|---|
1 | Box 1 |
2 | NULL |
3 | NULL |
4 | Box 2 |
I can't have NULL values for shared-overlapping circles (hexes), because then they won't be factored in at all for later spatial operations.
array_to_string(overlay_intersects('Box',Box_ID))
which returns
Circle ID | Connected to Box_ID |
---|---|
1 | Box 1 |
2 | [Box 1, Box 3] |
3 | [Box 1, Box 2] |
4 | Box 2 |
I can't have arrays or multiple spatial relations for one Circle (Hex) because that will cause issues later down the line.
overlap
I found I couldn't use because I couldn't get it to include only the Box_ID attribute, just the entirre shapefile name (i.e. All the Circles are connected to 'Boxes.shp').
What I want is just overlay_within
and overlap
(or intersect
minus touch
) that produces this result below with
Circle ID | Connected to Box_ID |
---|---|
1 | Box 1 |
2 | Box 1 |
3 | Box 2 |
4 | Box 2 |
How would I construct the expression for what I'm specifying, or is this a multiple and separate expression operation?
overlay_within
.array_to_string(overlay_intersects('Box_Layer', Box_ID, centroid($geometry)))
and while it does check out, it only returns a Null values for all features. Similar results witharray_to_string(overlay_contains('Box_Layer', Box_ID, centroid($geometry)))