diff --git a/R/addSource.R b/R/addSource.R index 25c17aa..629ae5c 100644 --- a/R/addSource.R +++ b/R/addSource.R @@ -3,7 +3,7 @@ #' @param map the [mapgl::maplibre()] or [mapgl::mapboxgl()] map to add the #' data source to. #' @param id a unique `ID` for the data source. -#' @param data a `sf`, `wk`, `geos` or `SpatVector` object. +#' @param data a `sf`, `wk`, `geos`, `SpatVector` or `duckspatial_df` object. #' @param file a valid local file path to a `geoarrow` or `geoparquet` file to be #' added to the map. Ignored if `data` is supplied. #' @param url a URL to a remotely hosted `geoarrow` or `geoparquet` file to be @@ -34,6 +34,23 @@ #' ## #' m #' +#' @tests tinytest +#' +#' stream_method = function(x, ..., native = FALSE) native +#' registerS3method( +#' "as_nanoarrow_array_stream" +#' , "deckglgeoarrow_test_duckspatial_df" +#' , stream_method +#' , envir = asNamespace("nanoarrow") +#' ) +#' +#' data = structure( +#' list() +#' , class = c("deckglgeoarrow_test_duckspatial_df", "duckspatial_df") +#' ) +#' +#' expect_identical(deckglgeoarrow:::parseGeoarrow(data), TRUE) +#' #' @export #' addSource = function( diff --git a/R/internals.R b/R/internals.R index b021edb..c02cb20 100644 --- a/R/internals.R +++ b/R/internals.R @@ -15,6 +15,10 @@ parseGeoarrow = function( return(data) } + if (inherits(data, "duckspatial_df")) { + return(nanoarrow::as_nanoarrow_array_stream(data, native = TRUE)) + } + if (inherits(data, "SpatVector")) { stopifnot( "need package 'terra' to handle 'SpatVector'" = diff --git a/inst/tinytest/test-addSource.R b/inst/tinytest/test-addSource.R new file mode 100644 index 0000000..1e407ba --- /dev/null +++ b/inst/tinytest/test-addSource.R @@ -0,0 +1,19 @@ +# File created by roxut; edit the function definition file, not this file + +# Test found in addSource.R:37 (file:line) + + +stream_method = function(x, ..., native = FALSE) native +registerS3method( + "as_nanoarrow_array_stream" + , "deckglgeoarrow_test_duckspatial_df" + , stream_method + , envir = asNamespace("nanoarrow") +) + +data = structure( + list() + , class = c("deckglgeoarrow_test_duckspatial_df", "duckspatial_df") +) + +expect_identical(deckglgeoarrow:::parseGeoarrow(data), TRUE) diff --git a/man/addSource.Rd b/man/addSource.Rd index 94d7292..80fbfb7 100644 --- a/man/addSource.Rd +++ b/man/addSource.Rd @@ -12,7 +12,7 @@ data source to.} \item{id}{a unique \code{ID} for the data source.} -\item{data}{a \code{sf}, \code{wk}, \code{geos} or \code{SpatVector} object.} +\item{data}{a \code{sf}, \code{wk}, \code{geos}, \code{SpatVector} or \code{duckspatial_df} object.} \item{file}{a valid local file path to a \code{geoarrow} or \code{geoparquet} file to be added to the map. Ignored if \code{data} is supplied.}