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?

  • Try divmod or % operator on autoincremented value and 1400-result – FelixIP Apr 25 '17 at 20:18
  • Sorry, I'm new to this - I'm not sure I understand what you mean by this, could you explain further? – miss_lilly_belle Apr 26 '17 at 16:59
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!

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

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.