-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(r): Improve vctr class integration #79
Conversation
r/geoarrow/R/sf-compat.R
Outdated
# exported in zzz.R | ||
st_as_sfc.geoarrow_vctr <- function(x, ..., promote_multi = FALSE) { | ||
sfc <- wk::wk_handle(x, wk::sfc_writer(promote_multi)) | ||
sf::st_set_crs(sfc, sf::st_crs(wk::wk_crs(x))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we prefer wk::wk_set_crs(sfc, wk::wk_crs(x))
here?
In theory, this change reduces geoarrow's knowledge of sf by deferring that responsibility to wk. In reality, it's the same code and still requires sf to be installed, so maybe it doesn't matter.
I tried debugging this: But didn't get very far... What I think is happening, is the geoarrow_vctr attributes aren't being preserved somewhere in |
Thank you! That is incredibly useful...after reading it I'm pretty sure I know exactly what is happening: when converting an array stream with more than one chunk, nanoarrow does a "preallocate + fill" thing. Unfortunately it doesn't allow propagating any changes to the attributes and I'm pretty sure this requires some non-trivial changes to nanoarrow's stream conversion (they are, however, changes I've been meaning to make for a while, so this is good incentive to make them happen!). |
Maybe for another PR. get_chunks <- function(x) attr(x, "chunks", exact = TRUE)
get_schema <- function(x) attr(x, "schema", exact = TRUE)
get_offsets <- function(x) attr(x, "offsets", exact = TRUE) |
geo <- geoarrow_schema_parse(schema) | ||
vctr <- as_geoarrow_vctr(array) | ||
|
||
if (geo$extension_name == "geoarrow.wkt") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a future pr, I think we could extract some of this into as_wkt
, as_wkb
, as_xy
methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then these could be skeletons. Or the reverse, and as_ methods are just calling these methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They almost certainly should be optimized! I'm pretty sure they just go through the handler right now (but at least they work!):
library(wk)
library(geoarrow)
as_xy(as_geoarrow_vctr("POINT (0 1)"))
#> <wk_xy[1]>
#> [1] (0 1)
as_wkt(as_geoarrow_vctr("POINT (0 1)"))
#> <wk_wkt[1]>
#> [1] POINT (0 1)
as_wkb(as_geoarrow_vctr("POINT (0 1)"))
#> <wk_wkb[1]>
#> [1] <POINT (0 1)>
Created on 2023-12-01 with reprex v2.0.2
@@ -105,3 +105,51 @@ test_that("as_geoarrow_array() for wk generates the correct metadata", { | |||
sprintf('{"edges":"spherical"}') | |||
) | |||
}) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Relates to #79 (comment) and #79 (comment), add some geoedesic and crs checks.
I haven't much input on the nanoarrow specifics as I'm not familiar with that api. Two identical bugs in convert_array.wk_wkt & convert_array.wk_wkb methods (see comments). Otherwise I think it's go to go. |
Co-authored-by: Anthony North <anthony.jl.north@gmail.com>
Co-authored-by: Anthony North <anthony.jl.north@gmail.com>
Co-authored-by: Anthony North <anthony.jl.north@gmail.com>
Thank you for the detailed look! |
Closes #78.
Works, but because of a limitation in nanoarrow the R package, it can only convert one chunk at a time: