mdbartos / pysheds

:earth_americas: Simple and fast watershed delineation in python.
GNU General Public License v3.0
708 stars 191 forks source link

In catchment function, ensure that search does not go out of bounds #165

Open mdbartos opened 2 years ago

mdbartos commented 2 years ago

The catchment search should not go out of bounds because a cell only gets visited if it points to the previous cell:

https://github.com/mdbartos/pysheds/blob/9d8896080fdf9d9af88a57f203177ba1a365946c/pysheds/_sgrid.py#L266

...and the rim is replaced with zeros, meaning that they cannot be reached in the recursion if 0 is not in the dirmap:

https://github.com/mdbartos/pysheds/blob/9d8896080fdf9d9af88a57f203177ba1a365946c/pysheds/sgrid.py#L705

However, this should be tested for edge cases.

Also it is possible to go out of bounds if the initial starting cell is on a boundary.