Spatial Data Operations for Database-Backed Geometries

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) and uses DuckDB's spatial extension < https://duckdb.org/docs/stable/core_extensions/spatial/overview.html>.


dbSpatial

Lifecycle:experimental CRANstatus

{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.

Installation

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")

Usage

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]>

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("dbSpatial")

0.1.2 by Edward C. Ruiz, 4 months ago


https://github.com/dbverse-org/dbspatial-r, https://dbverse-org.github.io/dbspatial-r/


Report a bug at https://github.com/dbverse-org/dbspatial-r/issues


Browse source code at https://github.com/cran/dbSpatial


Authors: Edward C. Ruiz [aut, cre] (ORCID: , Jiaji George Chen [aut] , Ruben Dries [aut, rev]


Documentation:   PDF Manual  


GPL-3 | MIT + file LICENSE license


Imports methods, tools, DBI, duckdb, dplyr, dbplyr, terra, sf, e1071, lifecycle, crayon, checkmate, cli, rlang, glue, tidyselect, dbProject

Suggests knitr, rmarkdown, testthat


See at CRAN