Skip to content

Commit

Permalink
start
Browse files Browse the repository at this point in the history
  • Loading branch information
paleolimbot committed May 29, 2024
1 parent 8558d1d commit 5c445c4
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
Imports:
nanoarrow (>= 0.5.0),
wk (>= 0.6.0)
wk (>= 0.9.0)
LinkingTo:
wk
Config/testthat/edition: 3
Expand Down
6 changes: 6 additions & 0 deletions R/array.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ as_geoarrow_array <- function(x, ..., schema = NULL) {
as_geoarrow_array.default <- function(x, ..., schema = NULL) {
if (is.null(schema)) {
schema <- infer_geoarrow_schema(x)
} else {
schema <- nanoarrow::as_nanoarrow_schema(schema)
}

wk::wk_handle(x, geoarrow_writer(schema))
Expand Down Expand Up @@ -58,6 +60,10 @@ as_geoarrow_array_stream <- function(x, ..., schema = NULL) {

#' @export
as_geoarrow_array_stream.default <- function(x, ..., schema = NULL) {
if (!is.null(schema)) {
schema <- nanoarrow::as_nanoarrow_schema(schema)
}

nanoarrow::basic_array_stream(
list(as_geoarrow_array(x, schema = schema)),
schema = schema
Expand Down
3 changes: 3 additions & 0 deletions R/pkg-wk.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ wk_is_geodesic.geoarrow_vctr <- function(x) {
#' @export
as_geoarrow_array.wk_wkt <- function(x, ..., schema = NULL) {
if (!is.null(schema)) {
schema <- nanoarrow::as_nanoarrow_schema(schema)
if (!identical(schema$metadata[["ARROW:extension:name"]], "geoarrow.wkt")) {
return(NextMethod())
}
Expand All @@ -48,6 +49,7 @@ as_geoarrow_array.wk_wkt <- function(x, ..., schema = NULL) {
#' @export
as_geoarrow_array.wk_wkb <- function(x, ..., schema = NULL) {
if (!is.null(schema)) {
schema <- nanoarrow::as_nanoarrow_schema(schema)
if (!identical(schema$metadata[["ARROW:extension:name"]], "geoarrow.wkb")) {
return(NextMethod())
}
Expand All @@ -70,6 +72,7 @@ as_geoarrow_array.wk_wkb <- function(x, ..., schema = NULL) {
#' @export
as_geoarrow_array.wk_xy <- function(x, ..., schema = NULL) {
if (!is.null(schema)) {
schema <- nanoarrow::as_nanoarrow_schema(schema)
if (!identical(schema$metadata[["ARROW:extension:name"]], "geoarrow.point")) {
return(NextMethod())
}
Expand Down
27 changes: 26 additions & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,33 @@ pak::pak("geoarrow/geoarrow-r")

## Example

This is a basic example which shows you how to solve a common problem:
The geoarrow package implements conversions to/from various geospatial types (e.g., sf, sfc, s2, wk) with various Arrow representations (e.g., arrow, nanoarrow). The most useful conversions are between the **arrow** and **sf** packages, which in most cases allow sf objects to be passed to **arrow** functions directly after `library(geoarrow)` or `requireNamespace("geoarrow")` has been called.

```{r example}
library(geoarrow)
library(arrow, warn.conflicts = FALSE)
library(sf)
nc <- read_sf(system.file("gpkg/nc.gpkg", package = "sf"))
tf <- tempfile(fileext = ".parquet")
nc |>
tibble::as_tibble() |>
write_parquet(tf)
open_dataset(tf) |>
dplyr::filter(startsWith(NAME, "A")) |>
dplyr::select(NAME, geom) |>
st_as_sf()
```

By default, arrow objects are converted to a neutral wrapper around chunked Arrow memory, which in turn implements conversions to most spatial types:

```{r}
read_parquet(tf)
```





0 comments on commit 5c445c4

Please sign in to comment.