3

I've extracted values from a raster to a point file, but now I need a field with the text information from the raster attribute table that corresponds with the value. I've been trying to use the field calculator to do an if/then type function, but I can't get it to work;enter image description here Basically, where it says 1201 in the RASTERVALU field I want it to say "Developed, Open Space" in the CN_LEVEL3 Field. I have absolutely no experience with Python.

4 Answers 4

5

In your field calculator, select Python as your parser. In your code block:

def calcVal (inVal):
 if inVal == 1201:
   return "Developed, Open Space"

Then in your field calculation box:

calcVal(!RASTERVALU!)

Tweak as needed. Look into if/elif/else statements for a bit more complex logics.

5

To expand on the other answers:

If you will be defining other values from RASTERVALU, besides the 1201, to CN_LEVEL3 you can put a dictionary into the codeblock. Example (I made some random values):

def calcVal(inVal):
    values = {1201: "Developed, Open Space",
              1202: "Forest",
              1203: "Water"}
    if inVal in values.keys():
        return values[inVal]
    else:
        pass

Resources:

Python dictionary

Field calculator examples; 10.2

3

For a quick solution instead of using an if/than you could do a select by attribute then calculate the field on the selected records like this:

enter image description here

enter image description here

enter image description here

This is a quick approach if you only have to run this for one value however gm70560's answer is far superior if this has to be repeated for multiple values.

4
  • When I tried this method, instead of "Developed, Open Space" populating the field CN_LEVEl3 where RASTERVALU equal 1201 it populated CN_LEVEL3 with either -1 or 0
    – Trose3
    Commented Jan 26, 2015 at 13:27
  • is CN_LEVEL3 set as a text field Commented Jan 26, 2015 at 13:30
  • I got it! Something stupid and simple as usual. Since field CN-LEVLE3 was already indicated as the field where the calculation was being performed I did not need to add it to the codeblock. Thanks!
    – Trose3
    Commented Jan 26, 2015 at 13:40
  • happy to help out. Commented Jan 26, 2015 at 13:44
2

To avoid the need to use Python you can use Select By Attribute first. This is available as a tool, from the Selection pulldown or from Table Options. Then use Field Calculator or the Calculate Field tool to update just those features with the desired value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.