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:


69.98 <-- top of stream








56.657 <----head of stream

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.


  • so each row in your stream attribute table corresponds to a segment?
    – Roland
    Feb 6, 2014 at 22:49
  • Yeah, each row is a segment length
    – user26439
    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.
    – Roland
    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
    – user26439
    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.
    – whuber
    Feb 6, 2014 at 23:13

1 Answer 1


looking at the formula again, I'm realizing that there is no need for accumulation of lengths up/downstream. Makes things much simpler.

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)
row = csr.next()
sumLength= row.getValue("SUM_Length")

Then you should be able to write your formula into an CalculateField statement and get your answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.