It is often impractical, inefficient, or impossible to perform an operation on a vector of geometries with all the geometries loaded into memory at the same time. These functions generalize the pattern of split-apply-combine to one or more handlers recycled along a common length. These functions are designed for developers rather than users and should be considered experimental.

wk_chunk_map_feature(
  handleables,
  fun,
  vector_args = NULL,
  args = NULL,
  input_handler_factory = wk_writer,
  output_template = NULL,
  strategy = wk_chunk_strategy_feature(chunk_size = 10000)
)

Arguments

handleables

A single handleable or a list() of handleables recycleable along a common length.

fun

A function called like fun(!!! transformed_handleables, !!! vector_args, !!! args) for each chunk. For wk_chunk_map_feature() this must be length-stable (i.e., return a value whose size is the recycled length of handleables and vector_args for that chunk).

vector_args

Vectorized arguments to fun.

args

Non-vectorized arguments to fun.

input_handler_factory

A function of handleable applied to handleable inputs. The default, wk_writer(), will result in fun getting called with a clone of the handleables for each chunk. Another useful pattern is to return a single type of handler so that all handleables have a common type.

output_template

A vector whose subset-assign method will get called for every chunk or NULL to ignore the output of fun.

strategy

A function of handleables and n_features such as that returned by wk_chunk_strategy_feature().

Value

output_template of the recycled common length of handleablesand vector_args filled with values generated by fun.

Examples

# apply a transformation or calculate a value using the data frame version
# of the geometries (but without resolving all of them at once)
wk_chunk_map_feature(
  wk_linestring(xy(1:10, 1:10), rep(1:5, each = 2)),
  function(features) {
    coords <- wk_coords(features)
    vapply(split(coords, coords$feature_id), nrow, integer(1))
  },
  output_template = integer()
)
#> [1] 2 2 2 2 2