2

What am I doing wrong in this field calculator logic?

Pre-logic

def re_score(elev_t,f2, contour):
 f2=contour
 if elev_t.endswith('.5'):
  f2 = "Midi"
 return f2

Expression for field "Contourtyp"

 re_score(!Elev_t!,f2,!Contourtyp!)

I just want to rename the contour type where the contours are at half meter intervals. The 'Elev_T' is a text column with all the elevations (converted to text as I couldn't think of a way to do it with numerical elevation data which has .25, .5, 75 and 1m intervals). I want all .5 called 'midi' and .25/.75 remain as 'minor' and 1m remains as 'basic'

Executing (Calculate Field (3)): CalculateField 328000_8123000 Contourtyp " re_score(!Elev_t!,f2,!Contourtyp!)" PYTHON_9.3 "def re_score(elev_t,f2, contour):\n f2=contour\n if elev_t.endswith('.5'):\n f2 = "Midi"\n return f2" Start Time: Thu Apr 12 17:10:40 2012 ERROR 000539: : unexpected indent (, line 1) Failed to execute (Calculate Field (3)). Failed at Thu Apr 12 17:10:40 2012 (Elapsed Time: 0.00 seconds)

I have tried different indentation and no luck...

4

Try:

def re_score(elev_t, contour):
        if elev_t.endswith('.5'):
            return "Midi"
        else:
            return contour

and then:
Countourtyp =

re_score(!Elev_t!, !Contourtyp!)

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.