geos
geos copied to clipboard
provide matrix version of relate pattern match
geos_relate_pattern()
is a really useful function for comparing two individual geometries. It would be great to have this same functionality made available in the _matrix()
format. If made available, it could be used to speed up neighbor matching in spdep.
Looking at queen contiguity with self included using geos_intersects_matrix()
is very fast. Rook contiguity requires a relate which the existing functions do not provide a way to harness the tree.
library(spdep)
library(geos)
x <- sf::st_as_sf(Guerry::gfrance85) |>
sf::st_geometry()
bench::mark(
spdep = include.self(poly2nb(x)),
geos = {
tree <- geos_strtree(x)
geos_intersects_matrix(x, tree)
},
check = FALSE
)
#> # A tibble: 2 × 6
#> expression min median `itr/sec` mem_alloc `gc/sec`
#> <bch:expr> <bch:tm> <bch:tm> <dbl> <bch:byt> <dbl>
#> 1 spdep 39.6ms 40.2ms 24.9 20MB 24.9
#> 2 geos 14.5ms 15.1ms 65.8 344KB 0