As in a
relational table join as defined in the
relational algebra, two input layers or tables are provided (hereafter
X and
Y), and the output is a table containing all of the columns of each of the inputs (or some subset thereof if selected by the user). The rows of the new table are a subset of Cross join or
Cartesian product of the two tables, all possible pairs of rows {X1-Y1, X1-Y2, X1-Y3, X2-Y1, X2-Y2, X2-Y3, X3-Y1, X3-Y2, X3-Y3, ...}. Rather than include all possible combinations, each pair is evaluated according to the given spatial predicate; those for which the predicate is true are considered "matching" and are retained, while those for which the predicate is false are discarded. For example, consider the following two tables: When the spatial join is executed, the direction of attachment must be specified, for two reasons: 1) the given spatial predicate may not be commutative, and 2) there is often a many-to-one relationship between the rows (e.g., many students are inside each school district). In the example above, a common goal would be to join the schools table to the students table (the
target table), with the relation predicate being "student.residence
within school.district." Assuming that the districts do not overlap, each student point will be in no more than one school district, so the output would have the same rows as the students table, with the corresponding school attributes attached, as: The reverse operation, in this case attaching the student information to the schools table, is not as simple because many rows must be joined to one row. Some GIS software does not allow this operation, but most implementations allow for an
aggregate join, in which aggregate summaries of the matching rows can be included, such as arrays, counts, sums, or means. For example, the result table might look like: Another option when there are multiple matches is to use some criterion to select one of the rows from the matching set, usually a spatial optimization criterion. For example, one could join the school building points (not the districts) to the student residents points by selecting the school that is
nearest to each student. Not all software implements this option directly, although in some cases it can be derived through a combination of tools. == External links ==