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?

asked Apr 25, 2017 at 14:51
2
  • Try divmod or % operator on autoincremented value and 1400-result 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!

answered Apr 25, 2017 at 15:16
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

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.