| ddbs_read_table | R Documentation |
Retrieves the data from a DuckDB table, view, or Arrow view with a geometry
column, and converts it to an R sf object. This function works with
both persistent tables created by ddbs_write_table and temporary
Arrow views created by ddbs_register_table.
ddbs_read_table(conn, name, clauses = NULL, quiet = FALSE)
conn |
A |
name |
A character string of length one specifying the name of the table,
or a character string of length two specifying the schema and table
names. If |
clauses |
character, additional SQL code to modify the query from the table (e.g. "WHERE ...", "ORDER BY...") |
quiet |
A logical value. If |
an sf object
## Not run:
## load packages
library(duckspatial)
library(sf)
# create a duckdb database in memory (with spatial extension)
conn <- ddbs_create_conn(dbdir = "memory")
## create random points
random_points <- data.frame(
id = 1:5,
x = runif(5, min = -180, max = 180),
y = runif(5, min = -90, max = 90)
)
## convert to sf
sf_points <- st_as_sf(random_points, coords = c("x", "y"), crs = 4326)
## Example 1: Write and read persistent table
ddbs_write_vector(conn, sf_points, "points")
ddbs_read_table(conn, "points")
## Example 2: Register and read Arrow view (faster, temporary)
ddbs_register_vector(conn, sf_points, "points_view")
ddbs_read_table(conn, "points_view")
## disconnect from db
ddbs_stop_conn(conn)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.