1

I have in my columns attribute the following table ( follows the image):

enter image description here

"rank" (which is related to the order of my data);

"SL" (which is a linear measure of my object);

"testada" (the formula):

enter image description here

I wanted a help in the implementation of the formula tested in the field command of the calculator arcgis.

The columns "rank" and "SL" range, containing more or less attributes. That is, My data vary and what I'm showing is just a sample of my data set so was wanting a more dynamic formula. This formula has to read up to the last line, and return the sum of tested according to formula.

ahmadhanb
41.8k5 gold badges55 silver badges110 bronze badges
asked Oct 11, 2016 at 19:55
1
  • 1
    What is the initial value if testdata? (first row) Commented Oct 11, 2016 at 22:09

2 Answers 2

1

You can use a python "closure" construct or a global var, but I prefer not to use globals.

Expression:

calc_testada( !SL! )

Code block:

def testada(initval=0):
 #Remember state using a "closure" pattern
 #Note closure vars are read-only in Python 2x
 #So we use a mutable var like a list
 val = [initval]
 def _testada(SL):
 val[0] += SL
 return val[0]
 return _testada
calc_testada = testada()

enter image description here

answered Oct 12, 2016 at 0:57
1

After setting your parser to Python and selecting Show Codeblock (inside Pre-Logic Script Code):

testada = 0 #Assuming your initial value for this is zero, i.e. testada[i-1] for rank 1
def sum_value (val):
 global testada
 testada += val
 return testada

And paste the following code in the smaller box below the Pre-Logic Script Code

sum_value(!SL!)
answered Oct 12, 2016 at 0:35
2
  • +1 from me. I said in my answer I prefer not to use globals, but that's just in general as I usually write code for larger scripts/libraries where global vars can lead to problems. In this case a global variable won't cause any issues and makes for simpler code than what I posted. Commented Oct 13, 2016 at 3:57
  • As you said, the use of global(s) is context dependent and for a very simple process like this, the interpreter will deal with only one global (and once) and yield. Commented Oct 13, 2016 at 4:19

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.