I add a field called Name in attribute table in arcgis 10.1 but I can't edit this field. From this site, I have learned that this can be done by field calculator using VBscript or Python. As I have very little knowledge in Visual Basic or Python, it becomes difficult for me to enter an expression using this programming language. In the picture shown, I created four category which I want to put in the Name section according to their GRIDCODE.

Can anyone tell me how can I do this ?

enter image description here


This will need you to modify values based on your GRIDCODE as I can only see 4 and 16 in your table, but to do this in the Field Calculator is fairly straightforward.

In the Field Calculator window, select Python parser, and select Show Codeblock. Enter the following into the Pre-Logic Script Code textbox:

def updateName(gCode):
    if gCode == 4:
        name = 'Vegetation'
    elif gCode == 8:
        name = 'Sand Fill'
    elif gCode == 12:
        name = 'Water Body'
    elif gCode == 16:
        name = 'Built-up Area'
        name = None
    return name

And then in the NAME = expression box enter

updateName( !GRIDCODE! )

You will need to modify the GRIDCODE values in the script to match the values in your field, and then modify the names to match the corresponding NAME value.

enter image description here

enter image description here

| improve this answer | |

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.