Provides database-backed spatial geometry classes and methods for
working with vector spatial data in 'DuckDB'. The package supports loading,
converting, querying, joining, and measuring spatial geometries through
familiar 'sf'-style interfaces while keeping geometry columns lazy inside
the database. It integrates with 'dbProject' to preserve database paths,
live connections, and spatial table metadata across interactive sessions.
The package follows the Simple Features framework described by Pebesma
(2018)
{dbSpatial} is a core package in the
dbverse library.
The goal of {dbSpatial} is to provide larger-than-memory spatial
operations for various spatial data sources. The package largely relies
on the DuckDB spatial
extension.
Note: Work in progress! Bugs or unexpected behavior are likely to occur. We welcome user feedback and reporting issues on the Github page.
You can install the development version of dbSpatial from Github like so:
# install.packages("pak", repos = sprintf("https://r-lib.github.io/p/pak/stable/%s/%s/%s", .Platform$pkgType, R.Version()$os, R.Version()$arch))
pak::pak("dbverse-org/dbspatial-r")
The DuckDB spatial extension can be used with wrapper functions in this
package directly (ST_*()), through dplyr verbs containing ST_*()
functions, or SQL queries to a DuckDB database connection containing
ST_*() functions.
library(dbSpatial)
# create duckdb db in memory
duckdb_conn = DBI::dbConnect(duckdb::duckdb(), ":memory:")
# test data
test_data = data.frame(x = 1:10, y = 1:10, id = 1:10)
points <- dbSpatial(conn = duckdb_conn,
name = "test_points",
value = test_data,
x_colName = "x",
y_colName = "y",
overwrite = TRUE)
points
#> # Class: dbSpatial
#> # Source: table<test_points> [10 x 4]
#> # Database: DuckDB v1.0.0 [root@Darwin 23.5.0:R 4.4.1/:memory:]
#> x y id geom
#> <int> <int> <int> <list>
#> 1 1 1 1 <raw [32]>
#> 2 2 2 2 <raw [32]>
#> 3 3 3 3 <raw [32]>
#> 4 4 4 4 <raw [32]>
#> 5 5 5 5 <raw [32]>
#> 6 6 6 6 <raw [32]>
#> 7 7 7 7 <raw [32]>
#> 8 8 8 8 <raw [32]>
#> 9 9 9 9 <raw [32]>
#> 10 10 10 10 <raw [32]>