Skip to content
Prev 29289 / 29559 Next

Using duckdb spatial module from R (with sf)?

Ah ha.  if we ask duckdb to coerce it's geometry format to hex, it
appears sf can understand it just fine!

replacing the above query with the following we are good to go.



query <- paste(
  'SELECT *, ST_AsHEXWKB(ST_Point(longitude, latitude)) AS geom',
  'FROM "test"'
)
ex <- st_read(con, query=query, geometry_column = "geom", EWKB=FALSE)
ex


I'll experiment further.  I'm terrible at SQL, and to my eyes it looks
needlessly verbose.  I'm keen to understand how I can better leverage
sf's notation to compose the sql queries to duckdb....  but it seems
to work!   I'm also still trying to determine if duckdb is using EWKB
or vanilla WKB....

---
Carl Boettiger
http://carlboettiger.info/
On Tue, Aug 15, 2023 at 4:02?PM Carl Boettiger <cboettig at gmail.com> wrote: