# Calculate river distance to headwater for every pixel?

I already posted a similar question a few weeks before. But since my dataset changed and I still havent solved it, I thought its good to post a new question instead of editing the old. Using ArcGIS 10.4

I am now working with a DEM. With the ArcHydro Toolbox I calculated subcatchments which I need for running a habitat model later. Now I need the maximum distance of every subcatchment to the source of the river (headwater).

I was thinking a tool like "path distance" or "flow length" should do the trick. And then maybe zonal statistics to calculate it for my subcatchments. But I cant get it right.

Any ideas?

UPDATE: With Lovette's tip with the weightraster I finally got it done. But since my subcatchment are not 100% correct (I guess that is normal) and my pixels are a little big (I need 50x50), the results of the zonal statistics are then a little weird sometimes. In picture 1 you can see that the blue (larger distance) pixel pf the main stream also touches the subcatchment of the side stream. Because the zonal statistics always takes the maximum, the whole catchment of the small side river gets a distance value that is way too high. The side streams should always have shorter distances.

Any ideas what to do about that? Can I maybe give the subcatchments values manually. This would take me a while, but from the numbers it would be doable.

Flow length and zonal statistics should do the trick.

For Flow Length, you should calculate distance upstream and use a weights raster with your stream pixels set to 1 and all non-stream pixels set to 0. You can then calculate the maximum value of this raster within each catchment using zonal statistics.

One thing to keep in mind is that the Flow Length tool will always calculate the longest distance upstream.

UPSTREAM — Calculates the longest upslope distance along the flow path, from each cell to the top of the drainage divide.

This will negate any short headwater stream segments and calculate the distance of each pixel to the furthest upstream point (with your weights raster, the drainage divide will be the end of your defined network).

• Great, thank you Lovette! Can you give me a hint on how to create the weights raster? I tried around but I guess I am missing an easy step. Commented Feb 16, 2018 at 17:07
• If you have your streams already delineated, convert them to a raster with the cell size set to the same as your DEM and the cells snapped to the DEM as well. Off the top of my head I can't recall if this will make a binary 0/1 raster or one with 1 for stream pixels and NoData for everywhere else. Either way, this stream pixel raster should work as the weights raster as you're telling the algorithm to only calculate the Flow Length within those stream pixels. Commented Feb 16, 2018 at 18:03
• Dear Lovette, after A LOT of try and error I finally got it done. But its not always working correctly because my subcatchments are not 100% or because the pixels are too wide (have to make them 50*50 to make them fit to other parameters in the final model). I will edit my question and include pictures of how it looks now. Maybe you or someone else has an idea what to do about that. Thank you! Commented Feb 21, 2018 at 12:16
• It seems to me that in order to get the most accurate results from zonal statistics, you may have to rebuild your subcatchments with the 50x50 raster so that you are not splitting cells between subcatchments. Zonal Statistics is a raster-to-raster comparison and therefore converts your vector zones to rasters first and then assigns your value cells to the zones based on a "cell centroid method". (good discussion here and here). Commented Feb 21, 2018 at 13:36
• Or could you use the smaller pixels to get the correct zonal statistics output and then still use the 50x50 pixels for your model? Commented Feb 21, 2018 at 13:37