| ddbs_write_table | R Documentation |
This function writes a Simple Features (SF) object into a DuckDB database as a new table. The table is created in the specified schema of the DuckDB database.
ddbs_write_table(
conn,
data,
name,
overwrite = FALSE,
temp_view = FALSE,
quiet = FALSE
)
conn |
A |
data |
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 |
overwrite |
Boolean. whether to overwrite the existing table if it exists. Defaults
to |
temp_view |
If |
quiet |
A logical value. If |
CRS Persistence: duckspatial ensures CRS metadata is retained across
sessions using two strategies: Native Spatial Storage (for DuckDB 1.5.0+
databases) and Legacy Compatibility (using column comments for older
database versions). For file-based spatial data interchange,
ddbs_write_dataset() to GeoParquet (.parquet) is recommended.
TRUE (invisibly) for successful import
## 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), # Random longitude values
y = runif(5, min = -90, max = 90) # Random latitude values
)
## convert to sf
sf_points <- st_as_sf(random_points, coords = c("x", "y"), crs = 4326)
## insert data into the database
ddbs_write_table(conn, sf_points, "points")
## read data back into R
ddbs_read_table(conn, "points")
## 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.