Skip to contents

Each function compares every row of x against every row of y and returns the row numbers of y for which the named DE-9IM relationship holds. This is the sparse form of the pairwise predicates in ga_intersects(), and the shape ga_join() needs.

Usage

ga_sparse_intersects(x, y)

ga_sparse_contains(x, y)

ga_sparse_contains_properly(x, y)

ga_sparse_within(x, y)

ga_sparse_covers(x, y)

ga_sparse_covered_by(x, y)

ga_sparse_touches(x, y)

ga_sparse_crosses(x, y)

ga_sparse_overlaps(x, y)

ga_sparse_equals_topo(x, y)

Arguments

x

a GeoArrow geometry array

y

a GeoArrow geometry array

Value

a list array of 1 based row numbers into y, the same length as x

Details

The comparison is not the full cross product. y is indexed in a packed Hilbert R-tree and only the rows whose bounding box overlaps are relate tested, so the cost scales with the number of candidates rather than with length(x) * length(y).

A row of x that matches nothing gives a zero length element, not a null. A null or empty geometry in x gives a null element, and one in y is never returned.

ga_disjoint() has no sparse form. Disjointness is the one relationship a bounding box cannot narrow, so the answer is almost every row of y and the result is denser than the input.

References

Relate

Examples

nc <- as.data.frame(read_shapefile(
  system.file("shape/nc.shp", package = "sf")
))

# which counties each county touches
nbrs <- as.vector(ga_sparse_touches(nc$geometry, nc$geometry))
nbrs[[1]]
#> [1]  2 18 19

# how many neighbours each has
summary(lengths(nbrs))
#>    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
#>     2.0     4.0     5.0     4.9     6.0     9.0