nearestNeighbors: Find the nearest neighbors for a focal pixel among a list of...

View source: R/topology.r

nearestNeighborsR Documentation

Find the nearest neighbors for a focal pixel among a list of sites

Description

For a list of 'sites', this function first computes a distance matrix(if not specified), then finds the nearest upstream and downstream neighbors for focal pixels 'x'. Note that 'x' does not necessarily have to be in the list of sites, they can be anywhere in the watershed.

Usage

nearestNeighbors(ws, x, distMatrix, sites, selfAdjacency = FALSE)

Arguments

ws

A watershed, optional unless 'distMatrix' is missing

x

A vector of focal pixels (always required)

distMatrix

A site by pixel distance matrix, will be computed if not specified

sites

A list of sites for the distance matrix, required if distMatrix is missing

selfAdjacency

if TRUE, a site can be downstream of itself

Value

A list with a downstream and an upstream element. Each element is a matrix, where the first column corresponds to the focal pixels in 'x', and the second column lists the nearest neighbors in 'sites'.


mtalluto/WatershedTools documentation built on May 21, 2022, 7:49 p.m.