Create a dbSpatial object from an sf or terra object.
Arguments
- rSpatial
sforterraobject.- conn
A
DBIConnectionobject, as returned byDBI::dbConnect.- name
a character stringwith the unquoted DBMS table name, e.g. "table_name"- overwrite
logical. Overwrite existing table. default = FALSE.- ...
Additional arguments to be passed
Details
Writes out the rSpatial object to temporary .parquet file and
computes the VIEW in the database with the specified name and the geometry
column as geom.
See also
Other dbSpatial:
dbSpatial,
show(),
st_as_sf.dbSpatial(),
vect,dbSpatial-method
Examples
coordinates <- data.frame(x = c(100, 200, 300), y = c(500, 600, 700))
attributes <- data.frame(id = 1:3, name = c("A", "B", "C"))
# Combine the coordinates and attributes
dummy_data <- cbind(coordinates, attributes)
# Create a SpatVector from the data.frame
dummy_spatvector <- terra::vect(dummy_data, geom = c("x", "y"))
# Set db connection
duckdb_conn = DBI::dbConnect(duckdb::duckdb(), ":memory:")
dbSpatial <- as_dbSpatial(rSpatial = dummy_spatvector,
conn = duckdb_conn,
name = "dummy_spatvector",
overwrite = TRUE)
dbSpatial
#> # Class: dbSpatial
#> # Source: table<dummy_spatvector> [?? x 3]
#> # Database: DuckDB 1.4.0 [unknown@Linux 6.11.0-1018-azure:R 4.5.1/:memory:]
#> id name geom
#> <int> <chr> <list>
#> 1 1 A <raw [32]>
#> 2 2 B <raw [32]>
#> 3 3 C <raw [32]>