A thin wrapper around duckdb::duckdb_register()
that creates a virtual
table, then selects the geometry column to DuckDB.'s GEOMETRY type in the
returned dbplyr
representation. Mostly useful for join and spatial
operations within DuckDB. No data is copied.
Arguments
- conn
A DuckDB connection, created by
dbConnect()
.- name
The name for the virtual table that is registered or unregistered
- sf_obj
sf object to be registered to duckdb
- geom_only
if TRUE, only the geometry column is registered. Always FALSE for sfc or sfg objects
- overwrite
Should an existing registration be overwritten?
- ...
additional arguments passed to duckdb_register
Details
Behind the scenes, this function creates an initial view (name
_init) with
the geometry stored as text via sf::st_as_text
. It then creates the view
name
which replaces the geometry column with DuckDB's internal geometry
type.
Examples
if (FALSE) { # interactive()
library(sf)
con <- stage_conn()
sf_obj <- st_sf(a = 3, geometry = st_sfc(st_point(1:2)))
sf_as_dbplyr(con, "test", sf_obj)
DBI::dbDisconnect(con)
}