I am working on a task to calculate Height Above Nearest Drainage (HAND) - that is the height above the nearest point along the flow path that is on a drainage - not the geographically nearest drainage point. I have created a raster where the value is the elevation of the next downstream point, based on a flow direction raster. I plan to populate my result raster by (unless I can figure out anything better):
Start with a raster where all stream cells are assigned a height of 0 above drainage and everything else is null. Use focal statistics to find the height above drainage for each cell's downslope cell (initially the values only along the stream) then calculate the HAND for each cell from:
HAND = cell elevation - downslope cell elevation + downslope cell HAND
This will only populate cells where downslope cell HAND is not null (i.e. adjacent to the stream initially). Then I will add those cells to the HAND raster and iterate until I have calculated all cells in the area.
How do I know when I'm done iterating?
My current thought is to either make a copy of the HAND raster before each iteration and compare it to the raster after to see if all cells have the same value or if any cell has a value where the old raster has a null, or to count the number of non-zero cells in each raster and stop when the number is the same. I don't know how to do either or if there is a better way.