2

I'm trying to use the Field Calculator with a python elif statement to reclassify values from a different field and populate a new field, and while I'm not getting an error message of any kind, I'm also not getting any sort of result. In other words, the tool runs and it says that it succeeded but nothing has changed in the column that is being calculated.

In codeblock example below the column that I want to use the elif statement on is "pa_gNyr_ha" and the new column that I want to populate is "N_load_bin".

def Reclass(Nload):
 if (Nload >= 0 and Nload <= 10000): 
 return 5000 
 elif (Nload > 10000 and Nload <= 24000): 
 return 17000 
 elif (Nload > 24000 and Nload <= 40000): 
 return 37000
 elif (Nload > 40000 and Nload <= 58000):
 return 50000
 elif (Nload > 58000 and Nload <= 74000):
 return 66000
 elif (Nload > 74000 and Nload <= 90000):
 return 82000
 elif (Nload > 90000 and Nload <= 104000):
 return 97000
 elif (Nload > 104000 and Nload <= 118000):
 return 111000
 elif (Nload > 118000 and Nload <= 130000):
 return 124000
 elif (Nload > 130000 and Nload <= 142000):
 return 136000
 elif (Nload > 142000 and Nload <= 157000):
 return 149500
 elif (Nload > 157000 and Nload <= 173000):
 return 165000
 elif (Nload > 173000 and Nload <= 189000):
 return 181000
 elif (Nload > 189000 and Nload <= 210000):
 return 194500
 elif (Nload > 210000 and Nload <= 233000):
 return 221500
 elif (Nload > 233000 and Nload <= 261000):
 return 242000
 elif (Nload > 261000 and Nload <= 299000):
 return 280000
 elif (Nload > 299000 and Nload <= 356000):
 return 327500
 elif (Nload > 356000 and Nload <= 456000):
 return 406000
 elif (Nload > 456000):
 return 501500

And then the expression is

Reclass(!pa_gNyr_ha!)

Essentially what I'm trying to do is create a conditional statement that will look at a value in the "pa_gNyr_ha" field and return a value to the "N_load_bin" field based on the range it falls into.

Am I at least close?

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Nov 12, 2013 at 22:57
8
  • 5
    Don't see any mistakes. Maybe add at the end an else statement, just to see if it runs fine. Maybe else: return 9999. Let us know if that works. Commented Nov 12, 2013 at 23:00
  • 4
    Is it possible that the values in pa_gNy_ha are less than zero? Is the field definitely numeric? Commented Nov 12, 2013 at 23:02
  • 5
    Is it possible that you have a selection on the feature class? If so, you may only be calculating on the selected features and not seeing the changes. Commented Nov 12, 2013 at 23:04
  • 2
    Also what does the Results window say? (You find it under Geoprocessing>Results) Commented Nov 12, 2013 at 23:04
  • 1
    Your field delimiters should work for a file geodatabase - is that where you have a feature class stored or are you trying to use this on a shapefile? Commented Nov 12, 2013 at 23:21

3 Answers 3

2

See PolyGeo's 1st comment to the original Question.

I was trying to use the Field Calculator and python codeblock on a shapefile and it worked as expected when the shapefile was exported to a geodatabase and the tool run on that file geodatabase feature class. PolyGeo rules.

answered Nov 13, 2013 at 16:45
0

The ArcMap calculator breaks Python rules and accepts only if, not the elif. Just replace all the elif code with if instead. It is correct that the file must be a geodatabase and not a shapefile.

answered May 5, 2015 at 17:36
-2

If any of these conditional statements are true a value gets returned, but I don' t see any value assignment. So shouldn't your action after the if statement be something like:

if (Nload > 40000 and Nload <= 58000):
 N_load_bin= 5000

Have you run this script with the arcpy window open? Are these values being return to that window?

answered Nov 13, 2013 at 0:11
1
  • 2
    The syntax used by @SamP is correct in this regard - see the Calculate fields using logic with Python example on this help page to see that the return statement is needed. Commented Nov 13, 2013 at 0:17

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.