#' @title Fast Dissolve for Spatial* objects.
#'
#' @description
#' \code{splitDissolve} splits a Spatial* object from the (sp) package using
#' \code{seqSPDF}, and runs \code{sp::aggregate()} on the list.
#'
#' @details
#' This is a general wrapper for \code{sp::aggregate()} that allows
#' for quicker aggregation and fixed a ram leak issue caused by large datasets.
#'
#' @param input Spatial* object. SpatialPoints objects will be passed through
#' as is.
#' @param sep Passed to \code{seqSPDF()}. Default set to 1000.
#'
#' @return Returns a fully aggregated feature of Spatial* \code{input}
#'
#' @export
# @examples need to find test data and add examples
splitDissolve <- function(input, sep= 1000) {
if (!grepl("Spatial", class(input))) {
stop("\"input\" input not of a \'Spatial\' class")
} else if (grepl("Point", class(input))) {
warning("Cannot Dissolve SpatialPoints")
return(input)
}
inputSplit <- seqSPDF(input, sep)
dissolvedList <- lapply(inputSplit, function(i) {
dissolved <- raster::aggregate(i, dissolve = T)
return(dissolved)
})
dissolvedBind <- suppressWarnings(do.call(raster::bind, dissolvedList))
dissolvedSP <- raster::aggregate(dissolvedBind, dissolve = T)
return(dissolvedSP)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.