[GIS] ArcGIS 10.0, Field Calculator Nested “if” statement with strings

arcgis-10.0arcgis-desktopfield-calculatorpythonunicode

I need to assign a value depending on other two columns "FNP" and "Teilort". I wrote this script in phyton for field calculator. It actually works (no error messages) but the results in every cell is 99.

I checked the two columns "FNP" and "Teilort" and the problem doesn't look like to com e from there (no extra blank or white spaces).

What can be the problem?

enter image description here

Best Answer

Apparently RefName never equals your comparison strings. All constant strings includes German characters ä or ü, but you don't use the "u" constant string prefix. Depending on the incoming string's format the comparison might not be what you expekt.

You should write if RefName==u"Flächen für die Landwirdshaft" and make sure that RefName also is a correct formatted unicode string.

EDIT: Do some print of RefName-column of your dataset in a python window in ArcMap to see how the strings look like.

Add the dataset to the map and select a row with RefName="Flächen für die Landwirdshaft"

type the following rows in the pyton window (replace names with your actual names):

curs=arcpy.SearchCursor("<name of layer>")
feat=curs.next()
feat.getValue("<name of column for RefName>")

The last row will probably print out something like u'Fl\xe4chen ...', which means you have a valid unicode string to compare against. Also try print feat.getValue("") to see that it prints like the literal you are comparing with. Note that the == operator is case sensitive.