glowabio / hydrographr

https://glowabio.github.io/hydrographr/
GNU General Public License v3.0
13 stars 1 forks source link

Function to extract all subc_ids from a raster layer #46

Open merretbuurman opened 8 months ago

merretbuurman commented 8 months ago

This is needed for the modelling workflow proposed by Jaime. Today, we discussed two ways how it could be added:

First way: A new function extract_all_ids(cropped_subc_layer, ...) { ... }

Second way: Extend the existing extract_ids() function (https://github.com/glowabio/hydrographr/blob/main/R/extract_ids.R#L70). Instead of a data table containing points for which you want the ids, just pass the string 'ALL'. The logic is: The first argument is currently the one determining for which points we want the ids, so having a simple way of saying all of them might be understandable.

extract_ids <- function(data, lon, lat, id = NULL, basin_layer = NULL,
                        subc_layer = NULL, quiet = TRUE) {

  # Check if input data is of type data.frame,
  # data.table or tibble
  if (!is(data, "data.frame"))
      if (data == 'ALL') {
         terra.unique(...) # blablabla
      } else {
    stop("data: Has to be of class 'data.frame' or the string 'ALL'.")
    ...

Any opinions?

JaimeRi commented 8 months ago

or Third way: use of terra.unique() directly in the R workflow (no wrapping)