diff --git a/DESCRIPTION b/DESCRIPTION index a9b79a635..134226687 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: terra Type: Package Title: Spatial Data Analysis -Version: 1.8-0 -Date: 2024-10-14 +Version: 1.8-1 +Date: 2024-11-15 Depends: R (>= 3.5.0) Suggests: parallel, tinytest, ncdf4, sf (>= 0.9-8), deldir, XML, leaflet (>= 2.2.1), htmlwidgets LinkingTo: Rcpp diff --git a/R/tapp.R b/R/tapp.R index 402161595..5512da3ba 100644 --- a/R/tapp.R +++ b/R/tapp.R @@ -12,7 +12,7 @@ function(x, index, fun, ..., cores=1, filename="", overwrite=FALSE, wopt=list()) out_tz <- "UTC" if (length(index) == 1) { if (is.character(index)) { - choices <- c("years", "months", "week", "days", "doy", "yearmonths", "yearweeks", "7days", "10days", "15days") + choices <- c("years", "months", "dekads", "weeks", "days", "doy", "yearmonths", "yeardekads", "yearweeks", "7days", "10days", "15days") i <- pmatch(tolower(index), choices) if (is.na(i)) { error("tapp", paste("invalid time step. Use one of:", paste(choices, collapse=", "))) @@ -25,7 +25,16 @@ function(x, index, fun, ..., cores=1, filename="", overwrite=FALSE, wopt=list()) # or POSIXlt$yday index <- format(time(x, "days"), "%j") prename <- "doy_" - } else if (choice == "week") { + } else if (choice == "dekads") { + index <- floor(as.integer(format(time(x, "days"), "%j")) / 10) + 1 + prename <- "dekad_" + } else if (choice == "yeardekads") { + year <- time(res, "years") + year <- formatC(year, width=4, flag = "0") + dekad <- floor(as.integer(format(time(x, "days"), "%j")) / 10) + 1 + index <- paste0(year, dekad) + prename <- "yd_" + } else if (choice == "weeks") { index <- strftime(time(x, "days"), format = "%V") prename <- "week_" } else if (choice == "yearweeks") { diff --git a/man/tapp.Rd b/man/tapp.Rd index 8aa047aff..68698e126 100644 --- a/man/tapp.Rd +++ b/man/tapp.Rd @@ -14,7 +14,7 @@ The number of layers in the output SpatRaster equals the number of unique values For example, if you have a SpatRaster with 6 layers, you can use \code{index=c(1,1,1,2,2,2)} and \code{fun=sum}. This will return a SpatRaster with two layers. The first layer is the sum of the first three layers in the input SpatRaster, and the second layer is the sum of the last three layers in the input SpatRaster. Indices are recycled such that \code{index=c(1,2)} would also return a SpatRaster with two layers (one based on the odd layers (1,3,5), the other based on the even layers (2,4,6)). -The index can also be one of the following values to group by time period (if \code{x} has the appropriate \code{\link{time}} values): "years", "months", "yearmonths", "week" (the ISO 8601 week number, see Details), "yearweeks", "days", "doy" (day of the year), "7days" (seven-day periods starting at Jan 1 of each year), "10days", or "15days". It can also be a function that makes groups from time values. +The index can also be one of the following values to group by time period (if \code{x} has the appropriate \code{\link{time}} values): "years", "months", "yearmonths", "dekad", "yeardekad", "week" (the ISO 8601 week number, see Details), "yearweeks", "days", "doy" (day of the year), "7days" (seven-day periods starting at Jan 1 of each year), "10days", or "15days". It can also be a function that makes groups from time values. See \code{\link{app}} or \code{\link{Summary-methods}} if you want to use a more efficient function that returns multiple layers based on \bold{all} layers in the SpatRaster. } diff --git a/src/rasterize.cpp b/src/rasterize.cpp index 0e2d8836b..e5df0fe0f 100644 --- a/src/rasterize.cpp +++ b/src/rasterize.cpp @@ -698,9 +698,11 @@ SpatRaster SpatRaster::rasterize(SpatVector x, std::string field, std::vector 1) { SpatOptions topt(opt); double halfres = tmp.yres() / 2; @@ -726,10 +728,7 @@ SpatRaster SpatRaster::rasterize(SpatVector x, std::string field, std::vector subds, std::vector subdsname, std::vector drivers, std::vector options, bool flipped) { +bool SpatRaster::constructFromFile(std::string fname, std::vector subds, std::vector subdsname, std::vector drivers, std::vector options) { if (fname == "WCS:") { // for https://github.com/rspatial/terra/issues/1505