Skip to content

Commit

Permalink
and do this more elegantly; #484
Browse files Browse the repository at this point in the history
  • Loading branch information
edzer committed Jun 17, 2022
1 parent 04bd227 commit fd08566
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions R/raster.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,14 @@ setAs("stars_proxy", "Raster", function(from) {
get_terra_levels = function(x, min_v) {
# create factor levels, as used by stars, from SpatRaster levels in a data.frame
# see https://github.com/r-spatial/stars/pull/484
x = x[order(x[[1]]), ] # sort table on level
levels = x[[1]]
o = order(levels) # may be arbitrary
levels = levels[o] # sorts
if (any(levels < 0))
stop("negative IDs in SpatRaster levels not supported")
ex = setdiff(0:max(levels), levels)
exclude = rep(FALSE, max(levels) + 1)
exclude[ex + 1] = TRUE # 0-based vector
list(levels = levels, labels = x[[2]][o], exclude = exclude)
list(levels = levels, labels = x[[2]], exclude = exclude)
}

#' @name st_as_stars
Expand Down

0 comments on commit fd08566

Please sign in to comment.