[GIS] Conditional Labeling based on attributes in ArcGIS 10

arcgis-10.0labelingpython

I am trying to label a street centerline layer with a condition based on street width. I am using the Python parser and I can't figure out this simple logic. Neither of these questions address how to accomplish this within the "Label Expression" window of ArcGis using Python:

Customizing label features using arcpy

Displaying combined data values in ArcMap

My attempt at it looks like this:

def FindLabel ( [NAME] ):
  if [WIDTH] > 30
  return [NAME]

GIS returns me an error when I try this.

Any help is much appreciated.
Thanks in advance,
mike

Best Answer

From the help on Building label expressions:

Field values are automatically cast to text strings. Therefore, if you wish to use a numeric value in an arithmetic operation, or when making a comparison, you will need to cast it back to a numeric data type. The examples below add two integer fields:

Also, you need to pass two parameters to your function because you are referencing two different fields.

Parser:

Python

Expression:

def FindLabel ([NAME], [WIDTH]):
  if int([WIDTH]) > 30:
    return [NAME]
Related Question