Tests if geometries in x intersect geometries in y. Returns TRUE if
geometries share at least one point in common.
Arguments
- x
An
sfspatial object. Alternatively, it can be a string with the name of a table with geometry column within the DuckDB databaseconn. Data is returned from this object.- y
An
sfspatial object. Alternatively, it can be a string with the name of a table with geometry column within the DuckDB databaseconn.- conn
A connection object to a DuckDB database. If
NULL, the function runs on a temporary DuckDB database.- id_x
Character; optional name of the column in
xwhose values will be used to name the list elements. IfNULL, integer row numbers ofxare used.- id_y
Character; optional name of the column in
ywhose values will replace the integer indices returned in each element of the list.- sparse
A logical value. If
TRUE, it returns a sparse index list. IfFALSE, it returns a dense logical matrix.- quiet
A logical value. If
TRUE, suppresses any informational messages. Defaults toFALSE.
Value
A list where each element contains indices (or IDs) of geometries in y that
intersect the corresponding geometry in x. See ddbs_predicate() for details.
Details
This is a convenience wrapper around ddbs_predicate() with
predicate = "intersects".
See also
ddbs_predicate() for other spatial predicates.
Examples
## load packages
library(dplyr)
library(duckspatial)
library(sf)
## read countries data, and rivers
countries_sf <- read_sf(system.file("spatial/countries.geojson", package = "duckspatial")) |>
filter(CNTR_ID %in% c("PT", "ES", "FR", "IT"))
rivers_sf <- st_read(system.file("spatial/rivers.geojson", package = "duckspatial")) |>
st_transform(st_crs(countries_sf))
#> Reading layer `rivers' from data source
#> `/home/runner/work/_temp/Library/duckspatial/spatial/rivers.geojson'
#> using driver `GeoJSON'
#> Simple feature collection with 100 features and 1 field
#> Geometry type: LINESTRING
#> Dimension: XY
#> Bounding box: xmin: 2766878 ymin: 2222357 xmax: 3578648 ymax: 2459939
#> Projected CRS: ETRS89-extended / LAEA Europe
ddbs_intersects(countries_sf, rivers_sf, id_x = "NAME_ENGL")
#> ✔ Query successful
#> $Spain
#> [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#> [19] 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
#> [37] 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
#> [55] 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
#> [73] 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
#> [91] 91 92 93 94 95 96 97 98 99 100
#>
#> $France
#> [1] 2
#>
#> $Italy
#> integer(0)
#>
#> $Portugal
#> [1] 59 96
#>
