More

Failed to Writing conditional (if/then) statements into Field Calculator of ArcGIS for Desktop using Python parser?

Failed to Writing conditional (if/then) statements into Field Calculator of ArcGIS for Desktop using Python parser?


I wrote this following several examples but it is still wrong. I need to populate a new field based on 5 ranges of values.

def marks(Wards for try.JHRatio ): if (Wards for try.JHRatio <= 50): return 0 elif Wards for try.JHRatio >50 and Wards for try.JHRatio <= 90): return 1 elif (Wards for try.JHRatio >90 and Wards for try.JHRatio <= 110): return 2 elif (Wards for try.JHRatio >= 110 and Wards for try.JHRatio <= 500): return 1 elif (Wards for try.JHRatio > 500): return 0 marks(!Wards for Try.JHRatio!)

you should use a simple variable name in your function : spaces will cause syntax errors (by the way, I recommend avoiding spaces in file names). it also makes your code more readable. Note that you do not need to do the ">" tests in your case, because the if statement already handle it.

def marks(myfield): if myfield <= 50: return 0 elif myfield <= 90: return 1 elif myfield <= 110: return 2 elif myfield <= 500: return 1 else: return 0 marks(!Wards for Try.JHRatio!)

Watch the video: GIS Python: Count shape files and Select by Location 2 Real world ArcPy examples