Skip to contents

Tests if geometries in x are disjoint from geometries in y. Returns TRUE if geometries have no points in common.

Usage

ddbs_disjoint(
  x,
  y,
  conn = NULL,
  id_x = NULL,
  id_y = NULL,
  sparse = TRUE,
  quiet = FALSE
)

Arguments

x

An sf spatial object. Alternatively, it can be a string with the name of a table with geometry column within the DuckDB database conn. Data is returned from this object.

y

An sf spatial object. Alternatively, it can be a string with the name of a table with geometry column within the DuckDB database conn.

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 x whose values will be used to name the list elements. If NULL, integer row numbers of x are used.

id_y

Character; optional name of the column in y whose 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. If FALSE, it returns a dense logical matrix.

quiet

A logical value. If TRUE, suppresses any informational messages. Defaults to FALSE.

Value

A list where each element contains indices (or IDs) of geometries in y that are disjoint from the corresponding geometry in x. See ddbs_predicate() for details.

Details

This is a convenience wrapper around ddbs_predicate() with predicate = "disjoint".

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_disjoint(countries_sf, rivers_sf, id_x = "NAME_ENGL")
#>  Query successful
#> $Spain
#> integer(0)
#> 
#> $France
#>  [1]   1   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20
#> [20]  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39
#> [39]  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58
#> [58]  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77
#> [77]  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96
#> [96]  97  98  99 100
#> 
#> $Italy
#>   [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
#> 
#> $Portugal
#>  [1]   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19
#> [20]  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38
#> [39]  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57
#> [58]  58  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77
#> [77]  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  97
#> [96]  98  99 100
#>