2

I am trying to use field calculator to number points between -700 and 700. I have used this code block:

rec=0 
def autoIncrement(): 
  global rec 
  pStart = 700
  pInterval = -1 
  if (rec == 0):  
   rec = pStart   
 else:  
  rec += pInterval  
return rec

which works great, but only numbers between 700 and 0, but I would like it to number all the way to -700 before starting over. Is this possible with this approach or do I need to try a different method?

2
  • Try divmod or % operator on autoincremented value and 1400-result
    – FelixIP
    Commented Apr 25, 2017 at 20:18
  • Sorry, I'm new to this - I'm not sure I understand what you mean by this, could you explain further? Commented Apr 26, 2017 at 16:59

1 Answer 1

3

Assuming you have 1401 points to number and you are trying to autodecrement, try the code below:

rec=-700 
def autoIncrement(): 
 global rec 
 pStart = 700 
 pInterval = 1 
 if (rec == -700):  
  rec = pStart  
 else:  
  rec -= pInterval  
 return rec

I should say though, this is an easy fix, not a proper solution to your problem or possible derivatives!

1
  • This did what I needed and was more 'proper' than the clunky temporary solution I came up with. Thanks! Commented Apr 26, 2017 at 17:00

Your Answer

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

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