diff --git a/NAMESPACE b/NAMESPACE index eadf4e5..61ae7b3 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -73,6 +73,7 @@ exportMethods(twdtwMatches) exportMethods(twdtwRaster) exportMethods(twdtwTimeSeries) exportMethods(twdtwXtable) +exportMethods(writeRaster) import(ggplot2) import(methods) import(raster) diff --git a/NEWS.md b/NEWS.md index 95821aa..8f7fbed 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,14 +4,16 @@ Include the function twdtwApplyParallel for TWDTW parallel processing using the package snow + Include writeRaster for twdtwRaster class + Improve tests and documentation -* Fixing bugs - Improve memory usage of twdtwApply Improve memory usage and speed of twdtwClassify +* Fixing bugs + Fix bug in twdtwAssess for class twdtwMatches Fix bug in twdtwRaster diff --git a/R/methods.R b/R/methods.R index 53b9e7a..385fb26 100644 --- a/R/methods.R +++ b/R/methods.R @@ -66,6 +66,10 @@ extent.twdtwRaster = function(x){ extent(x@timeseries[[1]]) } +writeRaster.twdtwRaster = function(x, filepath, ...){ + lapply(names(x@timeseries), function(i) writeRaster(x@timeseries[[i]], filename = paste0(filepath, "/", i, ".grd"), ...)) +} + projection.twdtwRaster = function(x){ projection(x@timeseries[[1]]) } @@ -163,6 +167,15 @@ setMethod(f = "res", "twdtwRaster", setMethod(f = "extent", "twdtwRaster", definition = extent.twdtwRaster) +#' @inheritParams twdtwRaster-class +#' @rdname twdtwRaster-class +#' @export +setMethod("writeRaster", "twdtwRaster", + definition = function(x, filepath = ".", ...) { + writeRaster.twdtwRaster(x, filepath, ...) + } +) + #' @inheritParams twdtwRaster-class #' @rdname twdtwRaster-class #' @export diff --git a/man/twdtwRaster-class.Rd b/man/twdtwRaster-class.Rd index 3169f36..d6da042 100644 --- a/man/twdtwRaster-class.Rd +++ b/man/twdtwRaster-class.Rd @@ -9,6 +9,7 @@ \alias{dim,twdtwRaster-method} \alias{res,twdtwRaster-method} \alias{extent,twdtwRaster-method} +\alias{writeRaster,twdtwRaster,ANY-method} \alias{projection,twdtwRaster-method} \alias{ncol,twdtwRaster-method} \alias{nrow,twdtwRaster-method} @@ -45,6 +46,8 @@ \S4method{extent}{twdtwRaster}(x, y, ...) +\S4method{writeRaster}{twdtwRaster,ANY}(x, filepath = ".", ...) + \S4method{projection}{twdtwRaster}(x) \S4method{ncol}{twdtwRaster}(x)