I have a layer of polygons that I spatially joined to a raster to point layer of slope percents. My polygons now have the percent of slope in a field called Avg_point. I want to use the field calculator to take that percent number (something like 22.345 or 56.45 etc.) and turn it into a text in the "slope" field (that was already in the layer of polygons) and I want that text to say something likes "Steep (>25%)"

So I wrote a script

SLOPE=slopecorrect(!SLOPE!, !Avg_grid_code!)


def slopecorrect(slope, avg):
    if avg > 25: 
       return Steep

I am getting no errors but my "slope" field just fills in I have tried other things but I can't seem to get it to fill in that field

I have looked around a bit and thought this thread was helpful but its still not producing results ArcMap Calculate Field..if "text" in !Field!

  • For code formatting easiest is to paste block in from your text editor, select the block, and use Ctrl-K to apply (will indent properly etc., most of the time). – matt wilkie Dec 3 '14 at 20:39
  • 2
    you need to quote your return, in order to make it a string, return "Steep" – matt wilkie Dec 3 '14 at 20:41
  • Awesome thanks for the help everyone. I can't believe it was that easy1 :-) – Daniel LaFlash Dec 3 '14 at 20:50
def slope_correct(slope, avg):
    if avg > 25:
        return "holly crap"
    elif 0 < avg <= 25:
        return "easy peasy"
        return "unknown"

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.