Why a spatial join returns these rows#
A spatial join produces a pair for each relationship that satisfies its predicate. In an inner join, an observation can appear more than once or disappear from the result, depending on the districts it matches.
Three observations, three pairs#
Consider an inner Intersects join with observations on the left. Districts A and B are closed squares with non-NULL IDs, as shown in the example.
y
2 +-------+-------+-------+
| A | A and B | B |
1 Q | P | | R
| | | |
0 +-------+-------+-------+-------+--- x
0 1 2 3 4
A spans (0,0) to (2,2) and B spans (1,0) to (3,2). P is (1.5,1), Q is (0,1), and R is (4,1).
The predicted pairs are (P,A), (P,B), and (Q,A). P has two partners because it lies in the overlap, and R has none. The total of three conceals both facts.
Does the edge belong to Q’s match?#
Q is on A’s left edge, as shown below.
A
(0,2) +-------+ (2,2)
| |
(0,1) Q | Q intersects and touches A
| | Q is not strictly within A
(0,0) +-------+ A does not contain Q
The eager sjoin profile used for the pair example admits inner and left Intersects joins when both inputs share a live Session and have matching canonical active CRS declarations.
Why R counts as one row and zero districts#
Change only the join from inner to left Intersects. The join preserves R and adds (R,NULL). Grouping by observation ID gives the following result.
Observation |
|
Count of district ID |
|---|---|---|
P |
2 |
2 |
Q |
1 |
1 |
R |
1 |
0 |
For R, size counts the row preserved by the join, while a named count of district ID counts its non-NULL values. For the exact admission rules when choosing a SQL join form, see Spatial SQL and query-shape support.