3

I'm trying to reclass 3000, 2000, 1000 and 0.5 into 1, 2, 3 and 4 respectively in a new field using field calculator. However it keeps returning an error message and I can't figure out why, any ideas?

def Reclass( !BUFF_DIST! ):
    if !BUFF_DIST! = 3000:
        return 1
    else if (!BUFF_DIST!) = 2000:
        return 2
    else if (!BUFF_DIST!) = 2000:
        return 3
    else: 
        return 4
  • (4000-v)/1000 will yield correct result on integer field. – FelixIP Jan 1 '18 at 8:34
3

Use Python parser and call the function with the actual field name enclosed in !!. BUFF_DIST=

Reclass(!BUFF_DIST!)

When you define the function use whatever name you want, for example buffdist. Also change = to == and else if to elif. Pre-Logic script code:

def Reclass( buffdist ):
    if buffdist == 3000:
        return 1
    elif buffdist == 2000:
        return 2
    elif buffdist == 1000:
        return 3
    else: 
        return 4
  • Thank you for your reply! I've just tried it and it still returns an error message. Just to clarify I've put that into a Python Praser with the type set as Number with no codeblock. – user111848 Dec 31 '17 at 14:26
  • You need the code block – BERA Dec 31 '17 at 14:27
  • 1
    That's worked now thank you! From there i'm trying to convert that into a raster in order to input it into model. However when i convert the polygon file to raster with the field being risk, it only returns one value for the whole raster instead of the 4 separate values. Is there a way to overcome this? – user111848 Dec 31 '17 at 14:33
  • 1
    Nice accept my answer with the checkbox please. Post a new question for that – BERA Dec 31 '17 at 14:37

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.