1

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

4

Using a Label Class with a SQL Query is an alternative to using label expressions with python.

The SQL Expression is quite simple:

[WIDTH] > 30

In ArcGIS help you find a detailed step-by-step instruction to use a SQL Query within a label class.

  • (+1) Hmm, I never knew about this. It seems like it would be simpler (and probably faster) to build complex labeling expressions. – Paul Aug 19 '13 at 14:39
5

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]
  • Paul, your solution also worked for me. I wish I could mark both as the correct answer, but since you gave a nod to Jens, s/he got the green check. Thanks. – mikeLdub Aug 21 '13 at 12:57

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.