The hardware and bandwidth for this mirror is donated by dogado GmbH, the Webhosting and Full Service-Cloud Provider. Check out our Wordpress Tutorial.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]dogado.de.
This vignette demonstrates how to use the {dbSpatial} package to create a DuckDB database with spatial points and polygons starting from various data sources.
All code chunks below are evaluated only when the duckdb package is available in the check environment.
# test data
test_data = data.frame(x = 1:10, y = 1:10, id = 1:10)
# df, tbl
# specify x and y column names to cast to a point geometry
a <- dbSpatial(conn = duckdb_conn,
name = "test_points",
value = test_data,
x_colName = "x",
y_colName = "y",
overwrite = TRUE)
a
#> # Class: dbSpatial
#> # Source: SQL [?? x 4]
#> # Database: DuckDB 1.4.2 [unknown@Linux 4.18.0-553.124.1.el8_10.x86_64:R 4.5.2/:memory:]
#> x y id geom
#> <int> <int> <int> <chr>
#> 1 1 1 1 POINT (1 1)
#> 2 2 2 2 POINT (2 2)
#> 3 3 3 3 POINT (3 3)
#> 4 4 4 4 POINT (4 4)
#> 5 5 5 5 POINT (5 5)
#> 6 6 6 6 POINT (6 6)
#> 7 7 7 7 POINT (7 7)
#> 8 8 8 8 POINT (8 8)
#> 9 9 9 9 POINT (9 9)
#> 10 10 10 10 POINT (10 10)# test data
test_data = data.frame(x = 1:10, y = 1:10, id = 1:10)
# write to file
write.csv(test_data, "test_data.csv", row.names = FALSE)
# load file in db
a <- dbSpatial(conn = duckdb_conn,
name = "test_points",
value = 'test_data.csv',
x_colName = "x",
y_colName = "y",
overwrite = TRUE)
a
#> # Class: dbSpatial
#> # Source: SQL [?? x 4]
#> # Database: DuckDB 1.4.2 [unknown@Linux 4.18.0-553.124.1.el8_10.x86_64:R 4.5.2/:memory:]
#> x y id geom
#> <chr> <chr> <chr> <chr>
#> 1 1 1 1 POINT (1 1)
#> 2 2 2 2 POINT (2 2)
#> 3 3 3 3 POINT (3 3)
#> 4 4 4 4 POINT (4 4)
#> 5 5 5 5 POINT (5 5)
#> 6 6 6 6 POINT (6 6)
#> 7 7 7 7 POINT (7 7)
#> 8 8 8 8 POINT (8 8)
#> 9 9 9 9 POINT (9 9)
#> 10 10 10 10 POINT (10 10)# load terra package
library(terra)
#> terra 1.8.93
# Create a SpatVector from the data.frame
dummy_spatvector <- terra::vect(test_data, geom = c("x", "y"))
# Load SpatVector in db
dbSpatial(conn = duckdb_conn,
name = "spatVector_proxy",
value = dummy_spatvector,
overwrite = TRUE)
#> # Class: dbSpatial
#> # Source: SQL [?? x 2]
#> # Database: DuckDB 1.4.2 [unknown@Linux 4.18.0-553.124.1.el8_10.x86_64:R 4.5.2/:memory:]
#> id geom
#> <int> <chr>
#> 1 1 POINT (1 1)
#> 2 2 POINT (2 2)
#> 3 3 POINT (3 3)
#> 4 4 POINT (4 4)
#> 5 5 POINT (5 5)
#> 6 6 POINT (6 6)
#> 7 7 POINT (7 7)
#> 8 8 POINT (8 8)
#> 9 9 POINT (9 9)
#> 10 10 POINT (10 10)These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.
Health stats visible at Monitor.