if (FALSE) {
# load packages
library(duckspatial)
library(sf)
# create points data
n <- 10
points_sf <- data.frame(
id = 1:n,
x = runif(n, min = -180, max = 180),
y = runif(n, min = -90, max = 90)
) |>
sf::st_as_sf(coords = c("x", "y"), crs = 4326)
# option 1: passing sf objects
output1 <- duckspatial::ddbs_distance(
x = points_sf,
y = points_sf,
dist_type = "haversine"
)
head(output1)
## option 2: passing the names of tables in a duckdb db and output as sf
# creates a duckdb
conn <- duckspatial::ddbs_create_conn()
# write sf to duckdb
ddbs_write_vector(conn, points_sf, "points", overwrite = TRUE)
output2 <- ddbs_distance(
conn = conn,
x = "points",
y = "points",
dist_type = "haversine"
)
head(output2)
}
Run the code above in your browser using DataLab