geoarrow / geoarrow-r

Extension types for geospatial data for use with 'Arrow'
http://geoarrow.org/geoarrow-r/
Apache License 2.0
152 stars 6 forks source link

fix: Fix schema inference for default method #33

Closed paleolimbot closed 8 months ago

paleolimbot commented 8 months ago

Closes #32.

Good catch!

library(geoarrow)
library(sf)
#> Linking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE

sf_obj <- data.frame(x = 1:5, y = 6:10) |> 
  sf::st_as_sf(coords = c("x", "y"), crs = "EPSG:3857")

# Now works
as_geoarrow_array(sf_obj)
#> <nanoarrow_array geoarrow.point{struct}[5]>
#>  $ length    : int 5
#>  $ null_count: int 0
#>  $ offset    : int 0
#>  $ buffers   :List of 1
#>   ..$ :<nanoarrow_buffer validity<bool>[0][0 b]> ``
#>  $ children  :List of 2
#>   ..$ x:<nanoarrow_array double[5]>
#>   .. ..$ length    : int 5
#>   .. ..$ null_count: int 0
#>   .. ..$ offset    : int 0
#>   .. ..$ buffers   :List of 2
#>   .. .. ..$ :<nanoarrow_buffer validity<bool>[0][0 b]> ``
#>   .. .. ..$ :<nanoarrow_buffer data<double>[5][40 b]> `1 2 3 4 5`
#>   .. ..$ dictionary: NULL
#>   .. ..$ children  : list()
#>   ..$ y:<nanoarrow_array double[5]>
#>   .. ..$ length    : int 5
#>   .. ..$ null_count: int 0
#>   .. ..$ offset    : int 0
#>   .. ..$ buffers   :List of 2
#>   .. .. ..$ :<nanoarrow_buffer validity<bool>[0][0 b]> ``
#>   .. .. ..$ :<nanoarrow_buffer data<double>[5][40 b]> `6 7 8 9 10`
#>   .. ..$ dictionary: NULL
#>   .. ..$ children  : list()
#>  $ dictionary: NULL

# Also works...slightly differently (also gives attributes)
nanoarrow::as_nanoarrow_array(sf_obj)
#> <nanoarrow_array struct[5]>
#>  $ length    : int 5
#>  $ null_count: int 0
#>  $ offset    : int 0
#>  $ buffers   :List of 1
#>   ..$ :<nanoarrow_buffer validity<bool>[0][0 b]> ``
#>  $ children  :List of 1
#>   ..$ geometry:<nanoarrow_array geoarrow.point{struct}[5]>
#>   .. ..$ length    : int 5
#>   .. ..$ null_count: int 0
#>   .. ..$ offset    : int 0
#>   .. ..$ buffers   :List of 1
#>   .. .. ..$ :<nanoarrow_buffer validity<bool>[0][0 b]> ``
#>   .. ..$ children  :List of 2
#>   .. .. ..$ x:<nanoarrow_array double[5]>
#>   .. .. .. ..$ length    : int 5
#>   .. .. .. ..$ null_count: int 0
#>   .. .. .. ..$ offset    : int 0
#>   .. .. .. ..$ buffers   :List of 2
#>   .. .. .. .. ..$ :<nanoarrow_buffer validity<bool>[0][0 b]> ``
#>   .. .. .. .. ..$ :<nanoarrow_buffer data<double>[5][40 b]> `1 2 3 4 5`
#>   .. .. .. ..$ dictionary: NULL
#>   .. .. .. ..$ children  : list()
#>   .. .. ..$ y:<nanoarrow_array double[5]>
#>   .. .. .. ..$ length    : int 5
#>   .. .. .. ..$ null_count: int 0
#>   .. .. .. ..$ offset    : int 0
#>   .. .. .. ..$ buffers   :List of 2
#>   .. .. .. .. ..$ :<nanoarrow_buffer validity<bool>[0][0 b]> ``
#>   .. .. .. .. ..$ :<nanoarrow_buffer data<double>[5][40 b]> `6 7 8 9 10`
#>   .. .. .. ..$ dictionary: NULL
#>   .. .. .. ..$ children  : list()
#>   .. ..$ dictionary: NULL
#>  $ dictionary: NULL

Created on 2024-01-29 with reprex v2.0.2