pyflwdir.FlwdirRaster.snap#
- FlwdirRaster.snap(idxs: ndarray | None = None, xy: tuple[ndarray, ndarray] | None = None, mask: ndarray | None = None, max_length: float | None = None, unit: Literal['m', 'cell'] = 'cell', direction: Literal['up', 'down'] = 'down') tuple[ndarray, ndarray][source]#
Snap starting cells to a downstream or upstream target.
Tracing stops at a pit, at a True cell in mask, or when max_length is exceeded. Provide either idxs or xy to specify starting cells.
- Parameters:
idxs (array_like, optional) – Linear indices of starting cells.
xy (tuple of array_like of float, optional) – x and y coordinates of starting cells.
mask (2D array of bool) – True for target cells. The first target encountered is returned.
max_length (float, optional) – Maximum tracing distance, measured in unit.
unit ({'m', 'cell'}, optional) – Distance unit, either metres (‘m’) or cells (‘cell’), by default ‘cell’.
direction ({'up', 'down'}, optional) – Trace downstream (‘down’, default) or upstream (‘up’).
- Returns:
array_like of int – Linear index of the snapped cell for each starting cell.
1D array of float – Distance from each starting cell to its snapped cell, in unit.