Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions wrappers/pyrichdem/richdem/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,35 @@ def TerrainAttribute(

terrain_attribs[attrib](dem.wrap(),resultw,zscale)

result.copyFromWrapped(resultw)

return result

def LabelWaterSheds(dem: rdarray, fill_deps: bool = False, topology: str="D8"):
"""Depression filling algorithm that also labels watersheds

Args:
dem (rdarray): An elevation model
fill_deps (bool): if True, fill depressions. This will alter the dem.
topology (string): Topology. Either the default ``D8``, or ``D4``.

Returns:
A raster with labels for each cell indicating its membership in a
given watershed. Cells bearing common labels drain to common points.
"""

demw = dem.wrap()
result = rdarray(np.zeros(shape=dem.shape, dtype='int32'), meta_obj=dem, no_data=-1)
resultw = result.wrap()

if topology == "D8":
_richdem.rdLabelWatershedsD8(demw, resultw, fill_deps)
elif topology == "D4":
_richdem.rdLabelWatershedsD8(demw, resultw, fill_deps)
else:
raise Exception("Topology must be either 'D8' or 'D4'. Not: " + topology)


result.copyFromWrapped(resultw)

return result
2 changes: 2 additions & 0 deletions wrappers/pyrichdem/src/pywrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ void TemplatedWrapper(py::module &m, std::string tname){
m.def("rdPFepsilonD4", &PriorityFloodEpsilon_Barnes2014<Topology::D4,T>, "Fill all depressions with epsilon."); //TODO

m.def("rdResolveFlatsEpsilon", &ResolveFlatsEpsilon<T>, "TODO");
m.def("rdLabelWatershedsD8", &PriorityFloodWatersheds_Barnes2014 <Topology::D8,T>, "Fill depressions and label watersheds"); //TODO?
m.def("rdLabelWatershedsD4", &PriorityFloodWatersheds_Barnes2014 <Topology::D4,T>, "Fill depressions and label watersheds"); //TODO?

m.def("rdBreachDepressionsD8", &BreachDepressions<Topology::D8,T>, "@@depressions/Lindsay2016.hpp:Lindsay2016@@"); //TODO
m.def("rdBreachDepressionsD4", &BreachDepressions<Topology::D4,T>, "@@depressions/Lindsay2016.hpp:Lindsay2016@@"); //TODO
Expand Down