Showing 9 of 133 files from the diff.
Other files ignored by Codecov
.gitignore has changed.
R/dependencies.R has changed.
NAMESPACE has changed.
.travis.yml has changed.
docs/sitemap.xml has changed.
Makefile has changed.
docs/index.html has changed.
docs/pkgdown.yml has changed.
.Rbuildignore has changed.
R/raptr.R has changed.
data/datalist was deleted.
R/data.R has changed.
docs/404.html has changed.
docs/authors.html has changed.
man/summary.Rd has changed.
README.md has changed.
man/RapResults.Rd has changed.
NEWS.md has changed.
man/raptr.Rd has changed.
inst/WORDLIST has changed.
man/sim.pus.Rd has changed.
README.Rmd has changed.
DESCRIPTION has changed.
cran-comments.md has changed.
man/solve.Rd has changed.

@@ -24,7 +24,8 @@
Loading
24 24
#'
25 25
#' @slot .cache [base::environment()] used to store extra data.
26 26
#'
27 -
#' @details The `summary` table follows Marxan conventions ("summary.dat" in <http://marxan.net/downloads/uq_marxan_web_2/module5.html>). The columns
27 +
#' @details The `summary` table follows Marxan conventions
28 +
#' (<https://marxansolutions.org/>). The columns
28 29
#' are:
29 30
#' \describe{
30 31
#' \item{Run_Number}{The index of each solution in the object.}
@@ -144,7 +145,8 @@
Loading
144 145
#'
145 146
#' @param .cache [base::environment()] used to cache calculations.
146 147
#'
147 -
#' @details The `summary` table follows Marxan conventions (summary.dat in <http://marxan.net/downloads/uq_marxan_web_2/module5.html>). The columns
148 +
#' @details The `summary` table follows Marxan conventions (
149 +
#' <https://marxansolutions.org/>). The columns
148 150
#' are:
149 151
#' \describe{
150 152
#' \item{Run_Number}{The index of each solution in the object.}

@@ -39,7 +39,7 @@
Loading
39 39
#'   [RapUnreliableOpts-class], [RapData-class].
40 40
#'
41 41
#' @examples
42 -
#' \donttest{
42 +
#' \dontrun{
43 43
#' # set random number generator seed
44 44
#' set.seed(500)
45 45
#'

@@ -4,7 +4,6 @@
Loading
4 4
#' Calculate average value for species data in planning units
5 5
#'
6 6
#' This function calculates the average of species values in each planning unit.
7 -
#' Be aware that using polygons with overlaps will result in inaccuracies.
8 7
#' By default all polygons will be treated as having separate ids.
9 8
#'
10 9
#' @param x [sp::SpatialPolygons()] or
@@ -20,9 +19,6 @@
Loading
20 19
#' @param ncores `integer` number of cores to use for processing. Defaults
21 20
#'   to 1.
22 21
#'
23 -
#' @param gdal `logical` Should raster processing be performed using GDAL
24 -
#'   libraries? Defaults to `FALSE`.
25 -
#'
26 22
#' @param field `integer` index or `character` name of column with
27 23
#'   planning unit ids. Valid only when `x` is a
28 24
#'   [sp::SpatialPolygonsDataFrame()] object. Default behavior is to
@@ -33,9 +29,6 @@
Loading
33 29
#' @return [base::data.frame()] with sum of raster values in each
34 30
#'   polygon.
35 31
#'
36 -
#' @seealso [is.gdalInstalled()], <http://www.gdal.org/>,
37 -
#'   <http://trac.osgeo.org/gdal/wiki/DownloadingGdalBinaries>.
38 -
#'
39 32
#' @examples
40 33
#' # simulate data
41 34
#' sim_pus <- sim.pus(225L)
@@ -187,7 +180,7 @@
Loading
187 180
#' @examples
188 181
#' # load RapUnsolved object
189 182
#' data(sim_ru)
190 -
#' \donttest{
183 +
#' \dontrun{
191 184
#' # solve it using Gurobi
192 185
#' sim_rs <- solve(sim_ru)
193 186
#'
@@ -432,8 +425,8 @@
Loading
432 425
#'
433 426
#' @param ... not used.
434 427
#'
435 -
#' @details This table follows Marxan conventions ("summary.dat" in
436 -
#'   <http://marxan.net/downloads/uq_marxan_web_2/module5.html>). The
428 +
#' @details This table follows Marxan conventions
429 +
#'   (<https://marxansolutions.org/>). The
437 430
#'   columns are:
438 431
#' \describe{
439 432
#' \item{Run_Number}{The index of each solution in the object.}

@@ -132,7 +132,7 @@
Loading
132 132
#' # print object
133 133
#' print(dps1)
134 134
#'
135 -
#' \donttest{
135 +
#' \dontrun{
136 136
#' # generate demand points for a 2d space using hypervolume
137 137
#' dps2 <- make.DemandPoints(points = env.points,
138 138
#'                           kernel.method = "hypervolume",

@@ -283,7 +283,6 @@
Loading
283 283
                              envir = environment())
284 284
      doParallel::registerDoParallel(clust)
285 285
    }
286 -
    #### TODO DOUBLE CHECK THIS LINE
287 286
    x <- plyr::rbind.fill(plyr::llply(seq_len(nlayers(y)), function(l) {
288 287
     zonalMean.RasterLayerNotInMemory(bs, x, y[[l]], ids[l],
289 288
                                      registered = isTRUE(ncores > 1), clust)
@@ -325,353 +324,6 @@
Loading
325 324
  tmp[which(tmp$value > 0),, drop = FALSE]
326 325
}
327 326
328 -
#' GDAL installation path
329 -
#'
330 -
#' Find GDAL installation location.
331 -
#'
332 -
#' @details This function is basically the same as
333 -
#'   `gdalUtils:::set_gdalInstallation`, it has addiitonal functionality to
334 -
#'   be compatible with Ubuntu 14.04 Trusty
335 -
#'
336 -
#' @return `character` path.
337 -
#'
338 -
#' @noRd
339 -
findGdalInstallationPaths <- function(search_path = NULL, rescan = FALSE,
340 -
                                      ignore.full_scan = TRUE,
341 -
                                      verbose = FALSE) {
342 -
  gdal_python_utilities <- function(path) {
343 -
    if (missing(path))
344 -
      path <- gdal_path()
345 -
    sapply(path, list.files, pattern = "\\.py")
346 -
  }
347 -
  gdal_drivers <- function(path, verbose = FALSE) {
348 -
    if (missing(path))
349 -
      path <- gdal_path(checkValidity = TRUE)
350 -
    cmd <- file.path(path, "gdalinfo")
351 -
    cmd <- paste0("\"", cmd, "\"", " --formats")
352 -
    drivers_raw <- lapply(cmd, system, intern = TRUE)
353 -
    result <- vector(mode = "list", length(path))
354 -
    names(result) <- path
355 -
    for (i in seq_along(drivers_raw)) {
356 -
      drivers_raw[[i]] <- drivers_raw[[i]][-1]
357 -
      drivers <- strsplit(drivers_raw[[i]], ":")
358 -
      driver_names <- gsub("^ ", "", sapply(drivers, function(x) {x[2]}))
359 -
      driver_codes_perm <- strsplit(sapply(drivers, function(x) {x[1]}), "\\(")
360 -
      driver_codes <- gsub(" ", "", sapply(driver_codes_perm,
361 -
                                           function(x) {x[1]}), fixed = TRUE)
362 -
      driver_perm <- gsub("\\)", "", sapply(driver_codes_perm,
363 -
                                            function(x) {x[2]}))
364 -
      r <- w <- u <- v <- s <- rep(FALSE, length(driver_perm))
365 -
      r[grep(driver_perm, pattern = "r")] <- TRUE
366 -
      w[grep(driver_perm, pattern = "w")] <- TRUE
367 -
      u[grep(driver_perm, pattern = "\\+")] <- TRUE
368 -
      v[grep(driver_perm, pattern = "v")] <- TRUE
369 -
      s[grep(driver_perm, pattern = "s")] <- TRUE
370 -
      result[[i]] <- data.frame(format_code = driver_codes,
371 -
        read = r, write = w, update = u, virtualIO = v,
372 -
        subdatasets = s, format_name = driver_names
373 -
      )
374 -
    }
375 -
    return(result[[1]])
376 -
  }
377 -
  gdal_version <- function(path, newerThan = NULL, verbose = FALSE) {
378 -
    if (missing(path))
379 -
      path <- gdal_path()
380 -
    cmd <- normalizePath(list.files(path, "^gdalinfo$|^gdalinfo\\.exe$",
381 -
                                    full.names = TRUE))
382 -
    cmd <- paste0("\"", cmd, "\"", " --version")
383 -
    result <- lapply(cmd, system, intern = TRUE)
384 -
    res <- sapply(result, length)
385 -
    if (sum(res) != length(result))
386 -
      message("Probably broken install of gdal at '",
387 -
              paste0(path[which(res != 1)], collapse = "' and '"), "'")
388 -
    result <- result[res == 1]
389 -
    date <- version <- vector(mode = "list", length = length(result))
390 -
    for (i in seq_along(result)) {
391 -
      ingd <- strsplit(result[[i]], ",")[[1]]
392 -
      version[[i]] <- gsub(ingd[1], pattern = "GDAL ", replacement = "")
393 -
      ind <- grep(ingd, pattern = "releas")
394 -
      date[[i]] <- as.character(as.Date(gsub(ingd[ind], pattern = " released ",
395 -
                                             replacement = ""),
396 -
                                        format = "%Y/%m/%d"))
397 -
    }
398 -
    if (!is.null(newerThan)) {
399 -
      test <- try(as.Date(newerThan), silent = TRUE)
400 -
      if (!inherits(test, "try-error")) {
401 -
        datein <- lapply(date, as.Date)
402 -
        res <- sapply(datein, ">=", as.Date(newerThan))
403 -
      } else {
404 -
        version <- gsub(tolower(version), pattern = "[a-z]", replacement = "")
405 -
        res <- sapply(version, strsplit, "\\.")
406 -
        newerThan <- strsplit(newerThan, "\\.")[[1]]
407 -
        for (i in seq_along(res)) {
408 -
          difs <- as.numeric(res[[i]]) - as.numeric(newerThan)
409 -
          difs <- sign(difs)
410 -
          if (sum(difs == -1) == 0) {
411 -
            res[[i]] <- TRUE
412 -
          } else {
413 -
            if (difs[1] < 0) {
414 -
              res[[i]] <- FALSE
415 -
            } else if (difs[1] > 0) {
416 -
              res[[i]] <- TRUE
417 -
            } else if (difs[1] == 0) {
418 -
              if (difs[2] < 0) {
419 -
                res[[i]] <- FALSE
420 -
              } else if (difs[2] > 0) {
421 -
                res[[i]] <- FALSE
422 -
              }
423 -
              else {
424 -
                if (difs[3] >= 0) {
425 -
                  res[[i]] <- TRUE
426 -
                }
427 -
                else if (difs[3] < 0) {
428 -
                  res[[i]] <- FALSE
429 -
                }
430 -
              }
431 -
            }
432 -
          }
433 -
        }
434 -
      }
435 -
      names(res) <- path
436 -
      return(res)
437 -
    }
438 -
    result <- as.data.frame(cbind(path = path[res == 1], version = version,
439 -
                                  date = date), stringsAsFactors = FALSE)
440 -
    return(result)
441 -
  }
442 -
  correctPath <- function(x) {
443 -
    if (!is.null(x)) {
444 -
      if (.Platform$OS.type == "windows") {
445 -
        x <- utils::shortPathName(x)
446 -
      } else {
447 -
        x <- path.expand(x)
448 -
      }
449 -
      x <- gsub(x, pattern = "\\\\", replacement = "/")
450 -
      ind <- substr(x, nchar(x), nchar(x)) != "/"
451 -
      x[ind] <- paste0(x[ind], "/")
452 -
    }
453 -
    return(x)
454 -
  }
455 -
  gdal_check_validity <- function(path) {
456 -
    checkValidity <- sapply(path, function(x) {
457 -
      cmd <- normalizePath(list.files(path = x,
458 -
                                      pattern = "^gdalinfo$|^gdalinfo\\.exe$",
459 -
                                      full.names = TRUE))
460 -
      if (length(cmd) == 0) {
461 -
        return(FALSE)
462 -
      } else {
463 -
      cmd <- paste0("\"", cmd, "\"", " --version")
464 -
      validity <- length(try(gdal <- system(cmd, intern = TRUE), silent = TRUE))
465 -
      return(as.logical(validity))
466 -
      }
467 -
      }
468 -
    )
469 -
  }
470 -
  gdal_path <- function(search_path = NULL, ignore.options = FALSE,
471 -
                        ignore.which = FALSE, ignore.common = FALSE,
472 -
                        ignore.full_scan = FALSE,
473 -
                        force_full_scan = FALSE, checkValidity,
474 -
                        search_path_recursive = FALSE,
475 -
                        verbose = FALSE) {
476 -
    owarn <- getOption("warn")
477 -
    options(warn = -2)
478 -
    on.exit(options(warn = owarn))
479 -
    if (missing(checkValidity)) {
480 -
      if (is.null(getOption("gdalUtils_gdalPath"))) {
481 -
        checkValidity <- TRUE
482 -
      } else {
483 -
        checkValidity <- FALSE
484 -
      }
485 -
    }
486 -
    path <- NULL
487 -
    if (!force_full_scan) {
488 -
      if (!ignore.options) {
489 -
        if (verbose)
490 -
          message("Checking the gdalUtils_gdalPath option...")
491 -
        option_paths <- unlist(sapply(getOption("gdalUtils_gdalPath"),
492 -
                                      function(x) return(x$path)))
493 -
        if (!is.null(option_paths) && checkValidity) {
494 -
          option_paths_check <- gdal_check_validity(option_paths)
495 -
          option_paths <- option_paths[option_paths_check]
496 -
        }
497 -
        path <- c(path, option_paths)
498 -
      }
499 -
      if (!is.null(search_path) && length(path) == 0) {
500 -
        if (verbose)
501 -
          message("Checking the search path...")
502 -
        if (.Platform$OS == "unix") {
503 -
          search_paths <- list.files(path = search_path,
504 -
                                     pattern = "^gdalinfo$|^gdalinfo\\.exe$",
505 -
                                     recursive = search_path_recursive,
506 -
                                     full.names = TRUE)
507 -
        } else {
508 -
          search_paths <- list.files(path = search_path,
509 -
                 pattern = "^gdalinfo$|^gdalinfo\\.exe$",
510 -
                 recursive = search_path_recursive, full.names = TRUE)
511 -
        }
512 -
        if (length(search_paths) == 0) {
513 -
          search_paths <- NULL
514 -
        } else {
515 -
          search_paths <- normalizePath(dirname(search_paths))
516 -
        }
517 -
        if (!is.null(search_paths) && checkValidity) {
518 -
          search_paths_check <- gdal_check_validity(search_paths)
519 -
          search_paths <- search_paths[search_paths_check]
520 -
        }
521 -
        path <- c(path, search_paths)
522 -
      }
523 -
      if (!ignore.which && length(path) == 0) {
524 -
        if (verbose)
525 -
          message("Checking Sys.which...")
526 -
        Sys.which_path <- dirname(Sys.which("gdalinfo"))
527 -
        if (Sys.which_path == "")
528 -
          Sys.which_path <- NULL
529 -
        if (!is.null(Sys.which_path) && checkValidity) {
530 -
          Sys.which_path_check <- gdal_check_validity(Sys.which_path)
531 -
          Sys.which_path <- Sys.which_path[Sys.which_path_check]
532 -
        }
533 -
        path <- c(path, Sys.which_path)
534 -
      }
535 -
      if (!ignore.common && length(path) == 0) {
536 -
        if (verbose)
537 -
          message("Checking common locations...")
538 -
        if (.Platform$OS == "unix") {
539 -
          common_locations <- c("/usr/bin", "/usr/local/bin",
540 -
                                "/Library/Frameworks/GDAL.framework",
541 -
                                "/opt/local/bin")
542 -
        } else if (.Platform$OS == "windows") {
543 -
        common_locations <- c("C:\\Program Files",
544 -
                              "C:\\Program Files (x86)", "C:\\OSGeo4W")
545 -
        }
546 -
        if (length(common_locations != 0)) {
547 -
          common_paths <- unlist(sapply(common_locations,
548 -
            function(x) {
549 -
              if (.Platform$OS == "unix") {
550 -
                search_common_paths <- list.files(path = x,
551 -
                  pattern = "^gdalinfo$|^gdalinfo\\.exe$", recursive = TRUE,
552 -
                  full.names = TRUE)
553 -
              } else {
554 -
                search_common_paths <- list.files(path = x,
555 -
                  pattern = "^gdalinfo$|^gdalinfo\\.exe$", recursive = TRUE,
556 -
                  full.names = TRUE)
557 -
              }
558 -
              if (length(search_common_paths) == 0) {
559 -
                return(search_common_paths)
560 -
              } else {
561 -
                return(normalizePath(dirname(search_common_paths)))
562 -
              }
563 -
            }))
564 -
          if (length(common_paths) == 0)
565 -
            common_paths <- NULL
566 -
          if (!is.null(common_paths) && checkValidity) {
567 -
            common_paths_check <- gdal_check_validity(common_paths)
568 -
            common_paths <- common_paths[common_paths_check]
569 -
          }
570 -
          path <- c(path, common_paths)
571 -
        }
572 -
      }
573 -
      if (!ignore.full_scan && length(path) == 0) {
574 -
        force_full_scan <- TRUE
575 -
      }
576 -
    }
577 -
    if (force_full_scan) {
578 -
      if (verbose)
579 -
        message("Scanning your root-dir for available GDAL installations,...",
580 -
                "This could take some time...")
581 -
      if (.Platform$OS == "unix") {
582 -
        root_dir <- "/"
583 -
      }
584 -
      if (.Platform$OS == "windows") {
585 -
        root_dir <- "C:\\"
586 -
      }
587 -
      if (.Platform$OS == "unix") {
588 -
        search_full_path <- list.files(path = root_dir,
589 -
                                       pattern = "^gdalinfo$|^gdalinfo\\.exe$",
590 -
                                       recursive = TRUE, full.names = TRUE)
591 -
      } else {
592 -
        search_full_path <- list.files(path = root_dir,
593 -
          pattern = "^gdalinfo$|^gdalinfo\\.exe$", recursive = TRUE,
594 -
          full.names = TRUE)
595 -
      }
596 -
      if (length(search_full_path) == 0)  {
597 -
        search_full_path <- NULL
598 -
      } else {
599 -
        search_full_path <- normalizePath(dirname(search_full_path))
600 -
      }
601 -
      if (!is.null(search_full_path) && checkValidity) {
602 -
        search_full_path_check <- gdal_check_validity(search_full_path)
603 -
        search_full_path <- search_full_path[search_full_path_check]
604 -
      }
605 -
      path <- c(path, search_full_path)
606 -
    }
607 -
    if (length(path) == 0) {
608 -
      return(NULL)
609 -
    } else {
610 -
      return(correctPath(unique(path)))
611 -
    }
612 -
  }
613 -
  gdal_installation <- function(return_versions = TRUE, return_drivers = TRUE,
614 -
                  return_python_utilities = TRUE, sort_most_current = TRUE,
615 -
                  rescan = FALSE, search_path = NULL, ignore.full_scan = FALSE,
616 -
                  verbose = FALSE) {
617 -
    if (verbose)
618 -
      message("Scanning for GDAL installations...")
619 -
    path <- gdal_path(ignore.options = rescan, search_path = search_path,
620 -
                      ignore.full_scan = ignore.full_scan, verbose = verbose)
621 -
    if (is.null(path))
622 -
      return(NULL)
623 -
    gdal_installation_results <- lapply(path, function(x, return_drivers,
624 -
                                                       return_python_utilities,
625 -
                                                       return_versions) {
626 -
      result <- list(path = x)
627 -
      if (return_versions) {
628 -
        version <- gdal_version(x)
629 -
        result$version <- unlist(version$version)
630 -
        result$date <- unlist(version$date)
631 -
      }
632 -
      if (return_drivers) {
633 -
        result$drivers <- gdal_drivers(x)
634 -
      }
635 -
      if (return_python_utilities) {
636 -
        result$python_utilities <- gdal_python_utilities(x)
637 -
      }
638 -
      return(result)
639 -
    }, return_drivers = return_drivers,
640 -
       return_python_utilities = return_python_utilities,
641 -
       return_versions = return_versions)
642 -
    if (sort_most_current) {
643 -
      versions <- unlist(sapply(gdal_installation_results,
644 -
                                function(x) return(x$date)))
645 -
      gdal_installation_results <-
646 -
        gdal_installation_results[order(as.Date(unlist(versions)),
647 -
                                        decreasing = TRUE)]
648 -
    }
649 -
    return(gdal_installation_results)
650 -
  }
651 -
  if (is.null(getOption("gdalUtils_gdalPath")))
652 -
    rescan <- TRUE
653 -
  gdal_installation_out <- gdal_installation(search_path = search_path,
654 -
                        rescan = rescan,
655 -
                        ignore.full_scan = ignore.full_scan,
656 -
                        verbose = verbose
657 -
  )
658 -
  options(gdalUtils_gdalPath = gdal_installation_out)
659 -
  if (is.null(getOption("gdalUtils_gdalPath"))) {
660 -
    warning(paste0("No GDAL installation found. Please install 'gdal' before ",
661 -
                   "continuing:\n\t- www.gdal.org (no HDF4 support!)\n\t-",
662 -
                   "www.trac.osgeo.org/osgeo4w/ (with HDF4 support ",
663 -
                   "RECOMMENDED)\n\t- www.fwtools.maptools.org (with HDF4 ",
664 -
                   "support)\n"))
665 -
    if (ignore.full_scan)
666 -
      warning(paste0("If you think GDAL is installed, please ",
667 -
                     "run:\ngdal_setInstallation(ignore.full_scan=FALSE)"))
668 -
  } else {
669 -
    if (verbose)
670 -
    message("GDAL version ",
671 -
            unlist(getOption("gdalUtils_gdalPath")[[1]]$version))
672 -
  }
673 -
}
674 -
675 327
#' Merge list of RapResults into a single object
676 328
#'
677 329
#' @noRd

@@ -31,7 +31,7 @@
Loading
31 31
#'
32 32
#' # generate 225 rectangular pus arranged in a square
33 33
#' y <- sim.pus(225, xmn = -5, xmx = 10, ymn = -5, ymx = 5)
34 -
#' \donttest{
34 +
#' \dontrun{
35 35
#' par(mfrow = c(1, 2))
36 36
#' plot(x, main = "x")
37 37
#' plot(y, main = "y")

@@ -412,7 +412,7 @@
Loading
412 412
#' @examples
413 413
#' # load data
414 414
#' data(cs_pus, cs_spp, cs_space)
415 -
#' \donttest{
415 +
#' \dontrun{
416 416
#' # make RapData object using the first 10 planning units in the dat
417 417
#' x <- make.RapData(cs_pus[1:10,], cs_spp, cs_space,
418 418
#'                   include.geographic.space = TRUE)

@@ -8,14 +8,13 @@
Loading
8 8
#' @export
9 9
calcSpeciesAverageInPus.SpatialPolygons <- function(x, y,
10 10
                                                    ids = seq_len(nlayers(y)),
11 -
                                                    ncores = 1, gdal = FALSE,
11 +
                                                    ncores = 1,
12 12
                                                    ...) {
13 13
  # check for invalid inputs
14 14
  assertthat::assert_that(inherits(x, "SpatialPolygons"), inherits(y, "Raster"),
15 15
                          raster::nlayers(y) == length(ids),
16 16
                          sum(duplicated(ids)) == 0,
17 -
                          assertthat::is.count(ncores),
18 -
                          assertthat::is.flag(gdal))
17 +
                          assertthat::is.count(ncores))
19 18
  return(calcSpeciesAverageInPus.SpatialPolygonsDataFrame(
20 19
    x = SpatialPolygonsDataFrame(x@polygons,
21 20
                                 data = data.frame(id = seq_len(nrow(x@data)),
@@ -23,7 +22,7 @@
Loading
23 22
                                                     sapply(x@polygons,
24 23
                                                            methods::slot,
25 24
                                                            name = "ID"))),
26 -
    y = y, ids = ids, ncores = ncores, gdal = gdal, field = "id"))
25 +
    y = y, ids = ids, ncores = ncores, field = "id"))
27 26
}
28 27
29 28
#' @method calcSpeciesAverageInPus SpatialPolygonsDataFrame
@@ -32,15 +31,13 @@
Loading
32 31
#'
33 32
#' @export
34 33
calcSpeciesAverageInPus.SpatialPolygonsDataFrame <- function(
35 -
  x, y, ids = seq_len(nlayers(y)), ncores = 1, gdal = FALSE, field = NULL,
36 -
  ...) {
34 +
  x, y, ids = seq_len(nlayers(y)), ncores = 1, field = NULL, ...) {
37 35
  # check for invalid inputs
38 36
  assertthat::assert_that(inherits(x, "SpatialPolygonsDataFrame"),
39 37
                          inherits(y, "Raster"),
40 38
                          raster::nlayers(y) == length(ids),
41 39
                          sum(duplicated(ids)) == 0,
42 40
                          assertthat::is.count(ncores),
43 -
                          assertthat::is.flag(gdal),
44 41
                          assertthat::is.string(field) || is.null(field))
45 42
  # prepare attribute table
46 43
  if (is.null(field)) {
@@ -50,14 +47,7 @@
Loading
50 47
    x@data <- data.frame(id = x@data[[field]], row.names = row.names(x@data))
51 48
  }
52 49
  # generate raster layer with polygons
53 -
  if (gdal && is.gdalInstalled()) {
54 -
    x <- rasterizeGDAL(x, y[[1]], "id")
55 -
  } else {
56 -
    if (gdal && !is.gdalInstalled())
57 -
      warning(paste0("GDAL is not installed on this computer, using ",
58 -
                     "raster::rasterize for processing"))
59 -
    x <- raster::rasterize(x, y[[1]], method = "ngb")
60 -
  }
50 +
  x <- raster::rasterize(x, y[[1]], method = "ngb")
61 51
  # main processing
62 52
  return(zonalMean(x, y, ids, ncores))
63 53
}

@@ -13,7 +13,7 @@
Loading
13 13
#' @seealso [base::options()].
14 14
#'
15 15
#' @examples
16 -
#' \donttest{
16 +
#' \dontrun{
17 17
#' # check if Gurobi is installed
18 18
#' is.GurobiInstalled()
19 19
#'
@@ -68,82 +68,6 @@
Loading
68 68
  return(TRUE)
69 69
}
70 70
71 -
#' Test if GDAL is installed on computer
72 -
#'
73 -
#' This function tests if GDAL is installed on the computer.
74 -
#' If not, download it here: <http://download.osgeo.org/gdal>.
75 -
#'
76 -
#' @return `logical` is GDAL installed?
77 -
#'
78 -
#' @seealso [gdalUtils::gdal_setInstallation()].
79 -
#'
80 -
#' @examples
81 -
#' # check if gdal is installed on system
82 -
#' \donttest{
83 -
#' is.gdalInstalled()
84 -
#' }
85 -
#'
86 -
#' @export
87 -
is.gdalInstalled <- function() {
88 -
  suppressWarnings(findGdalInstallationPaths())
89 -
  return(!is.null(getOption("gdalUtils_gdalPath")))
90 -
}
91 -
92 -
#' Rasterize polygon data using GDAL
93 -
#'
94 -
#' This function converts a [sp::SpatialPolygonsDataFrame()] to a
95 -
#' [raster::raster()] using GDAL. It is expected to be faster than
96 -
#' [raster::rasterize()] for large datasets. However, it will be
97 -
#' significantly slower for small datasets because the data will need to be
98 -
#' written and read from disk.
99 -
#'
100 -
#' @param x [sp::SpatialPolygonsDataFrame()] object.
101 -
#'
102 -
#' @param y [raster::raster()] with dimensions, extent, and
103 -
#'   resolution to be used as a template for new raster.
104 -
#'
105 -
#' @param field `character` column name with values to burn into the
106 -
#'   output raster. If not supplied, default behaviour is to burn polygon
107 -
#'   indices into the [raster::raster()].
108 -
#'
109 -
#' @return [raster::raster()] object.
110 -
#'
111 -
#' @seealso [raster::rasterize()], [is.gdalInstalled()].
112 -
#'
113 -
#' @examples
114 -
#' \donttest{
115 -
#' # load dat
116 -
#' data(cs_pus,cs_spp)
117 -
#'
118 -
#' # rasterize spatial polygon data
119 -
#' x <- rasterizeGDAL(cs_pus[1:5,], cs_spp[[1]])
120 -
#'
121 -
#' # plot data
122 -
#' par(mfrow = c(1,2))
123 -
#' plot(cs_pus[1:5,], main = "original data")
124 -
#' plot(x, main = "rasterized data")
125 -
#' }
126 -
#'
127 -
#' @export
128 -
rasterizeGDAL <- function(x, y, field = NULL) {
129 -
  assertthat::assert_that(inherits(x, "SpatialPolygonsDataFrame"),
130 -
                          inherits(y, "RasterLayer"),
131 -
                          is.null(field) || (assertthat::is.string(field) &&
132 -
                                             field %in% names(x@data)))
133 -
  if (is.null(field)) {
134 -
    x@data$id <- seq_len(nrow(x@data))
135 -
    field <- "id"
136 -
  }
137 -
  rgdal::writeOGR(x, tempdir(), "polys", driver = "ESRI Shapefile",
138 -
                  overwrite_layer = TRUE)
139 -
  raster::writeRaster(raster::setValues(y, NA), file.path(tempdir(),
140 -
                      "rast.tif"), NAflag = -9999, overwrite = TRUE)
141 -
  return(gdalUtils::gdal_rasterize(file.path(tempdir(), "polys.shp"),
142 -
                                  file.path(tempdir(), "rast.tif"),
143 -
                                  l = "polys", a = field,
144 -
                                  output_Raster = TRUE)[[1]])
145 -
}
146 -
147 71
#' Blank raster
148 72
#'
149 73
#' This functions creates a blank raster based on the spatial extent of a
Files Coverage
R 75.13%
src 84.42%
Project Totals (41 files) 78.96%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading