Skip to contents

Tests if geometries in x overlap geometries in y. Returns TRUE if geometries share some but not all points, and the intersection has the same dimension as the geometries.

Usage

ddbs_overlaps(
  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 overlap the corresponding geometry in x. See ddbs_predicate() for details.

Details

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

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"))
spain_sf <- st_read(system.file("spatial/countries.geojson", package = "duckspatial")) |> 
  filter(CNTR_ID == c("PT", "ES", "FR", "FI"))
#> Reading layer `countries' from data source 
#>   `/home/runner/work/_temp/Library/duckspatial/spatial/countries.geojson' 
#>   using driver `GeoJSON'
#> Simple feature collection with 257 features and 6 fields
#> Geometry type: POLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -178.9125 ymin: -89.9 xmax: 180 ymax: 83.65187
#> Geodetic CRS:  WGS 84
#> Warning: There was 1 warning in `stopifnot()`.
#>  In argument: `CNTR_ID == c("PT", "ES", "FR", "FI")`.
#> Caused by warning in `CNTR_ID == c("PT", "ES", "FR", "FI")`:
#> ! longer object length is not a multiple of shorter object length

ddbs_overlaps(countries_sf, countries_sf)
#>  Query successful
#> NULL