# Calculating Stream Length-gradient Index (Hack Index) with the field calculator

I'm trying to calculate the Stream Length-Gradient Index of a stream (example data below). Just started to get into python, but am struggling with a solution to this problem. I have 42 streams to run this code on and doing it by with excel is tedious. The stream is broken up into segments and I'd like to get a SL index for each stream.

The equation: SL = (10/Length of segment)*(sum(length of segments) * (length of segment/2))

In each stream attribute table I have:

Length

69.98 <-- top of stream

90.228

94.206

85.429

94.039

99.095

92.983

76.736

Now the biggest hickup I have is that all the data is backwards I need to run the calculation from the head of the stream (bottom of the attribute table) to the top of the stream.

Thanks!

• so each row in your stream attribute table corresponds to a segment? Feb 6, 2014 at 22:49
• Yeah, each row is a segment length Feb 6, 2014 at 22:51
• does this table indicate the next downstream segment, too? Or is the routing topology stored elsewhere? If you have more to add, might just edit the original post. Feb 6, 2014 at 22:52
• It does not, other than the last value is the furthest point down slope and the first is the hightest point upstream Feb 6, 2014 at 22:57
• Your formula does not appear to compute a stream length index: this calculation depends on elevation differences as well as lengths, at least according to one of Hack's original papers (ees.lehigh.edu/ftp/retreat/outgoing/roma_tre_short_course/…). Is it possible that your stream has been broken into segments of equal elevation drop? Even then the last factor in the formula is mysterious; it does not seem to have any equivalent in the paper. Feb 6, 2014 at 23:13

You can use `Statistics` to sum the length for the table/the stream in question. You can then use something like the following to capture that value
``````csr = arcpy.SearchCursor('TableViewOfStatsOutput)
Then you should be able to write your formula into an `CalculateField` statement and get your answer.