1

I am working on a street addressing project. I want to add a number to every odd number. Example if [field] is odd [field]+=1. How can I do this in ArcMap using the field calculator.

I used to work programming in Microsoft Visual Basic And C++.But how can i do this in Arc Map field calculator.

enter image description here

What is wrong in this expression.

I used the expression that Ali Put. But still I am Having errors.

enter image description here

enter image description here

2
  • 3
    Select using Mod(fld,2)=0
    – FelixIP
    Feb 16, 2017 at 8:32
  • I've updated my answer to include the field expression. You had that part right in the first image.
    – Ali
    Feb 16, 2017 at 9:35

1 Answer 1

2

You're almost there. The modulo operation in Python is carried out using the % operator i.e.

>>> print 3 % 2
1

Incorporating this into your function:

def calc(val):
    if val % 2 > 0:
        return val + 1
    else:
        return val

Then underneath the codeblock, in the field expression:

calc(!LR!)

The field calculator will take the value from the LR field and push it into the calc function. If it is odd, the value will be incremented by 1 and returned, otherwise the input value will be returned without modification.

1
  • Val + (Val ℅ 2) will do
    – FelixIP
    Feb 16, 2017 at 18:50

Your Answer

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

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