R/get_total_edge.R

Defines functions get_total_edge

Documented in get_total_edge

#' Calculate total edge based on the input matrix
#'
#' @param x A matrix
#' @param resolution A numeric vector with two values representing the input matrix
#'   resolution on the x and y axis
#' @param neighbourhood The number of directions in which cell adjacencies are
#'   considered as neighbours: 4 (rook's case), 8 (queen's case) or a binary matrix
#'   where the ones define the neighbourhood. The default is 4.
#'
#' @return A total edge value
get_total_edge = function(x, resolution, neighbourhood = as.matrix(4)){
  resolution_x = resolution[[1]]
  resolution_y = resolution[[2]]
  neighbor_matrix = comat::get_coma(x, neighbourhood = neighbourhood)
  edge_total = sum(neighbor_matrix[lower.tri(neighbor_matrix)]) * resolution_x
  return(edge_total)
}

Try the bespatial package in your browser

Any scripts or data that you put into this service are public.

bespatial documentation built on April 3, 2025, 7:58 p.m.