1

I've tried writing a code block using the Python Parser of the ArcGIS Field Calculator. Here's what I am trying to achieve: There's a field in my attribute table with values for some, but not all of the polygons in the feature class. For those which have a Null Value I need to calculate the values using two other fields and a simple fraction. So the logic should be like this: If Field1 = Null, new value is Field2 / Field3, else Field1=Field1

I've written a script, but it won't work. It does compute, but there are either no results (meaning that the Null value stays like it is) or, in some cases for some reason, the new value is 1. This is the script, can anybody see the error? enter image description here

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Jul 23, 2016 at 16:44
0

1 Answer 1

4

Try to change your code to

def calc(Wert1, Wert2, Wert3):
 if (Wert1 == None):
 return Wert2/Wert3
 else:
 return Wert1
answered Jul 23, 2016 at 17:09
2
  • 1
    Yes, I think it's the quotes around Null that are the problem. The quotes make it a string, so your code is checking literally for a string that says <Null> exactly, instead of an empty value, which in Python is expressed as None (without the angle brackets). Commented Jul 23, 2016 at 18:19
  • Thank you for your answers. I'll try it out on Monday when I'm back at the office and let you know how it works. Commented Jul 23, 2016 at 19:59

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.