Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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...

Thanks

share|improve this question

1 Answer 1

up vote 3 down vote accepted

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!)
share|improve this answer
    
Brilliant! thanks...didn't know that we could just return a value and not have it as f2=value... :-) –  GeorgeC Apr 12 '12 at 22:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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