to_sf {duckdbfs} | R Documentation |
Convert output to sf object
Description
Convert output to sf object
Usage
to_sf(x, crs = NA, conn = cached_connection())
Arguments
x |
a remote duckdb |
crs |
The coordinate reference system, any format understood by |
conn |
the connection object from the tbl.
Takes a duckdb table (from Note: |
Value
an sf
class object (in memory).
Examples
library(dplyr)
csv_file <- system.file("extdata/spatial-test.csv", package="duckdbfs")
# Note that we almost always must first create a `geometry` column, e.g.
# from lat/long columns using the `st_point` method.
sf <-
open_dataset(csv_file, format = "csv") |>
mutate(geom = ST_Point(longitude, latitude)) |>
to_sf()
# We can use the full space of spatial operations, including spatial
# and normal dplyr filters. All operations are translated into a
# spatial SQL query by `to_sf`:
open_dataset(csv_file, format = "csv") |>
mutate(geom = ST_Point(longitude, latitude)) |>
mutate(dist = ST_Distance(geom, ST_Point(0,0))) |>
filter(site %in% c("a", "b", "e")) |>
to_sf()
[Package duckdbfs version 0.0.4 Index]