@@ -54,6 +54,58 @@ format.geoarrow_vctr <- function(x, ..., width = NULL, digits = NULL) {
54
54
sprintf(" <%s>" , formatted_chr )
55
55
}
56
56
57
+ # ' @export
58
+ `[.geoarrow_vctr` <- function (x , i ) {
59
+ tryCatch(
60
+ NextMethod(),
61
+ error = function (e ) {
62
+ if (! startsWith(conditionMessage(e ), " Can't subset nanoarrow_vctr" )) {
63
+ stop(e )
64
+ }
65
+
66
+ if (! requireNamespace(" arrow" , quietly = TRUE )) {
67
+ stop(" 'arrow' is required to subset geoarrow_vctr with non-slice input" )
68
+ }
69
+
70
+ chunked <- as_chunked_array.geoarrow_vctr(x )[i ]
71
+ stream <- as_nanoarrow_array_stream(chunked )
72
+ nanoarrow :: as_nanoarrow_vctr(stream , subclass = " geoarrow_vctr" )
73
+ }
74
+ )
75
+ }
76
+
77
+ # ' @export
78
+ c.geoarrow_vctr <- function (... ) {
79
+ dots <- list (... )
80
+ if (length(dots ) == 1 ) {
81
+ return (dots [[1 ]])
82
+ }
83
+
84
+ wk :: wk_crs_output(... )
85
+ wk :: wk_is_geodesic_output(... )
86
+ streams <- lapply(dots , as_nanoarrow_array_stream )
87
+
88
+ schemas <- lapply(dots , attr , " schema" )
89
+ parsed <- lapply(schemas , geoarrow_schema_parse )
90
+ ids <- unique(unlist(lapply(parsed , " [[" , 1 )))
91
+ if (length(ids ) != 1 ) {
92
+ # We don't have a "cast common" operation here like we do in Python yet,
93
+ # so just turn them all into WKB for now
94
+ streams <- lapply(streams , as_geoarrow_array_stream , schema = geoarrow_wkb())
95
+ schemas <- lapply(streams , nanoarrow :: infer_nanoarrow_schema )
96
+ }
97
+
98
+ collected <- lapply(streams , nanoarrow :: collect_array_stream )
99
+ all_batches <- do.call(" c" , collected )
100
+ stream <- nanoarrow :: basic_array_stream(
101
+ all_batches ,
102
+ schema = schemas [[1 ]],
103
+ validate = FALSE
104
+ )
105
+
106
+ nanoarrow :: as_nanoarrow_vctr(stream , subclass = " geoarrow_vctr" )
107
+ }
108
+
57
109
# Because RStudio's viewer uses this, we want to use the potentially abbreviated
58
110
# WKT from the format method
59
111
# ' @export
0 commit comments