R/grass_i_cluster.R

Defines functions grass_i_cluster

Documented in grass_i_cluster

##' QGIS Algorithm provided by GRASS i.cluster (grass:i.cluster). Generates spectral signatures for land cover types in an image using a clustering algorithm.
##'
##' @title QGIS algorithm - i.cluster
##'
##' @param input `multilayer` - Input rasters. .
##' @param classes `number` - Initial number of classes (1-255). A numeric value. field:FIELD_NAME to use a data defined value taken from the FIELD_NAME field. expression:SOME EXPRESSION to use a data defined value calculated using a custom QGIS expression.
##' @param seed `file` - Name of file containing initial signatures. Path to a file.
##' @param sample `string` - Sampling intervals (by row and col). String value. field:FIELD_NAME to use a data defined value taken from the FIELD_NAME field. expression:SOME EXPRESSION to use a data defined value calculated using a custom QGIS expression.
##' @param iterations `number` - Maximum number of iterations. A numeric value. field:FIELD_NAME to use a data defined value taken from the FIELD_NAME field. expression:SOME EXPRESSION to use a data defined value calculated using a custom QGIS expression.
##' @param convergence `number` - Percent convergence. A numeric value. field:FIELD_NAME to use a data defined value taken from the FIELD_NAME field. expression:SOME EXPRESSION to use a data defined value calculated using a custom QGIS expression.
##' @param separation `number` - Cluster separation. A numeric value. field:FIELD_NAME to use a data defined value taken from the FIELD_NAME field. expression:SOME EXPRESSION to use a data defined value calculated using a custom QGIS expression.
##' @param min_size `number` - Minimum number of pixels in a class. A numeric value. field:FIELD_NAME to use a data defined value taken from the FIELD_NAME field. expression:SOME EXPRESSION to use a data defined value calculated using a custom QGIS expression.
##' @param signaturefile `fileDestination` - Signature File. Path for new file.
##' @param reportfile `fileDestination` - Final Report File. Path for new file.
##' @param GRASS_REGION_PARAMETER `extent` - GRASS GIS region extent. A comma delimited string of x min, x max, y min, y max. E.g. '4,10,101,105'. Path to a layer. The extent of the layer is used..
##' @param GRASS_REGION_CELLSIZE_PARAMETER `number` - GRASS GIS region cellsize (leave 0 for default). A numeric value. field:FIELD_NAME to use a data defined value taken from the FIELD_NAME field. expression:SOME EXPRESSION to use a data defined value calculated using a custom QGIS expression.
##' @param ... further parameters passed to `qgisprocess::qgis_run_algorithm()`
##' @param .complete_output logical specifying if complete out of `qgisprocess::qgis_run_algorithm()` should be used (`TRUE`) or first output (most likely the main) should read (`FALSE`). Default value is `TRUE`.
##' @param .quiet logical specifying if parameter `.quiet` for `qgisprocess::qgis_run_algorithm()` Default value is `TRUE`.
##' @param .messages logical specifying if messages from `qgisprocess::qgis_run_algorithm()` should be printed (`TRUE`) or not (`FALSE`). Default value is `FALSE`.
##'
##' @details
##' ## Outputs description
##' * reportfile - outputFile - Final Report File
##' * signaturefile - outputFile - Signature File
##'
##'
##' @export
##' @md
##' @importFrom qgisprocess qgis_run_algorithm

grass_i_cluster <- function(input = qgisprocess:::qgis_default_value(), classes = qgisprocess:::qgis_default_value(), seed = qgisprocess:::qgis_default_value(), sample = qgisprocess:::qgis_default_value(), iterations = qgisprocess:::qgis_default_value(), convergence = qgisprocess:::qgis_default_value(), separation = qgisprocess:::qgis_default_value(), min_size = qgisprocess:::qgis_default_value(), signaturefile = qgisprocess:::qgis_default_value(), reportfile = qgisprocess:::qgis_default_value(), GRASS_REGION_PARAMETER = qgisprocess:::qgis_default_value(), GRASS_REGION_CELLSIZE_PARAMETER = qgisprocess:::qgis_default_value(),..., .complete_output = .complete_output_option(), .quiet = .quiet_option(), .messages = .message_option()) {

  check_algorithm_necessities("grass:i.cluster")

  if (.messages){
    output <- qgisprocess::qgis_run_algorithm("grass:i.cluster", `input` = input, `classes` = classes, `seed` = seed, `sample` = sample, `iterations` = iterations, `convergence` = convergence, `separation` = separation, `min_size` = min_size, `signaturefile` = signaturefile, `reportfile` = reportfile, `GRASS_REGION_PARAMETER` = GRASS_REGION_PARAMETER, `GRASS_REGION_CELLSIZE_PARAMETER` = GRASS_REGION_CELLSIZE_PARAMETER,..., .quiet = .quiet)
  } else {
    suppressMessages(
      output <- qgisprocess::qgis_run_algorithm("grass:i.cluster", `input` = input, `classes` = classes, `seed` = seed, `sample` = sample, `iterations` = iterations, `convergence` = convergence, `separation` = separation, `min_size` = min_size, `signaturefile` = signaturefile, `reportfile` = reportfile, `GRASS_REGION_PARAMETER` = GRASS_REGION_PARAMETER, `GRASS_REGION_CELLSIZE_PARAMETER` = GRASS_REGION_CELLSIZE_PARAMETER,..., .quiet = .quiet)
      )
  }

  if (.complete_output) {
    return(output)
  }
  else{
    qgisprocess::qgis_extract_output(output, "reportfile")
  }
}
JanCaha/r_package_qgis documentation built on Oct. 1, 2024, 11:50 p.m.