Convert vector indices or Raster* cell numbers into worldMatrix indices.

NLworldIndex(world, cellNum)

# S4 method for worldMatrix,numeric
NLworldIndex(world, cellNum)

Arguments

world

WorldMatrix or worldArray object.

cellNum

Integer. Vector of cells number.

Value

Numeric. Vector of worldMatrix indices.

Author

Eliot McIntire

Examples

if (requireNamespace("raster", quietly = TRUE)) {
  w1 <- createWorld(minPxcor = 0, maxPxcor = 9, minPycor = 0, maxPycor = 9, data = 1:100)
  w1Ras <- world2raster(w1)
  index <- 24
  pxpy <- PxcorPycorFromCell(world = w1, cellNum = index)

  rasValue <- as.integer(unname(w1Ras[index]))
  # Not correct index:
  identical(w1[index], rasValue)

  # Correct index
  identical(w1[NLworldIndex(w1, index)], rasValue)
}
#> [1] TRUE