1

After some initial research, I was unable to find a solution for the following issue. I'm sure there's an answer to this question already floating around here somewhere, but hopefully someone can give me a more personalized answer for my particular situation.

I am using ArcMap 10.3

I would like to have a String field that automatically generates a category name based off of an Integer field range.
Basically: If the Integer is between 0-500, the String would generate "Red" for the category field.
There are 5 different Categories to choose from within my Integer data.

To my understanding, this would need to happen via the Field Calculator, using a code block and Python.

So,
Can I generate a String result in Field1 based on a designated Integer range in Field2?
If so, How?

asked May 6, 2015 at 20:40
2
  • Out of curiosity, are you trying to use these categories to define symbology/colors for these features for display? If so, maybe using graduated colors symbology may be a better way to go - resources.arcgis.com/en/help/main/10.1/index.html#//… Not sure of your familiarity with ArcGIS, so just checking to make sure you're not trying to reinvent an existing feature. Commented May 6, 2015 at 21:00
  • I was going to convert my Symbology to use graduated symbols instead of the color categories, but, the color categories needs to be part of my data anyway. So, the numbers dictate the color category, and the color category dictates my symbology. Commented May 6, 2015 at 21:45

3 Answers 3

4

In the pre-logic script code block (after having chosen python as the parser), you'll want something similar to this -

def categorize(value):
 if 0 <= value <= 500:
 return 'red'
 elif 501 <= value <= 1000:
 return 'green'
 else:
 return 'light purple'

and in the text box below it, you'll want to call the functio nyou just defined, passing in field names as paramaters using !fieldname! notation like so -

categorize(!integer_field_name!)
answered May 6, 2015 at 20:56
4
  • Am I correct in assuming this operation is done while I have the Color Category field highlighted, not the Integer field? Commented May 7, 2015 at 13:43
  • @Nomkins correct Commented May 7, 2015 at 14:00
  • Any time I try to run this using the field calculator, ArcMap crashes. Even when I narrow down my selected items to 10 or so. Any thoughts on why that might be? Commented May 7, 2015 at 14:38
  • Do you get any error messages? The only thing I can think of off the top of my head is that either you've somehow corrupted your python installation, or maybe you're just not selecting the Python parser option at the top of the field calculator where it has radio button for Pythong & VB Commented May 8, 2015 at 14:21
1

You can use an Update Cursor to do this type of classification:

import arcpy
fc = r'C:\temp\yourFC.shp'
with arcpy.da.UpdateCursor(fc, ["Field1", "Field2"]) as cursor:
 for row in cursor:
 # row[0] = "Field1"
 # row[1] = "Field2"
 if 500 >= row[1] >= 0:
 row[0] = "red"
 elif 1000 >= row[1] > 500:
 row[0] = "green"
 elif 1500 >= row[1] > 1000:
 row[0] = "blue"
 else:
 row[0] = "unassigned"
 cursor.updateRow(row)

enter image description here

answered May 6, 2015 at 20:55
1

Yeah, you have a basic if/else logic, check out this: Basic If/Then in Python Parser of ArcGIS Field Calculator?

dim n if[integerfield]> 500 then n = 'Red' elseif[integerfield].....

answered May 6, 2015 at 20:51

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.