4

I have a field in a shapefile with values ranging from 1-50 and multiple listed as 0. Is there a way to label only the features where the number in the priority field is > 0?

7

You can put this as the label expression for the feature:

def FindLabel([yourField]):
    if [yourField] is not None:
        if int([yourField]) > 0:
            return [yourField]
        else:
            return None
    else:
        return None

Using Python as the parser and checking the Advanced box.

Replace [yourField] with whatever field you are using to label.

  • note, in python it's better to say if XXXX is not None: – Paul H Mar 26 '14 at 16:54
  • 1
    Thanks Paul, that's actually what I normally use. I'll update my answer accordingly. – ianbroad Mar 26 '14 at 17:34
  • I've been trying to get this to work for a wildcard number that starts with 18 and ends with any number & length of digits. This is what I have, the syntax checks out and fine but it doesn't exclude anything: def FindLabel ( [SITE] ): if int([SITE]) == '18%': return " " else: return [SITE] – Alpheus Jul 20 '18 at 17:52
  • Try this: if str([SITE])[0:2] == "18": return "" – ianbroad Jul 23 '18 at 14:24
4

I deal with this from time to time. You should use the Expression button in the Label tab. There you use the Advanced parser (checkbox), and write something like this (Python):

def FindLabel ( [Name], [V5] ):
 if [V5] == "0":
   return "<BOL>"+ [Name]+"</BOL>"
 else:
  return "<BOL>"+ [Name]+"</BOL>" + "\n" +"<FNT size = '6'>"+  str([V5] )+"</FNT>"

This will return labels for each feature from field Name in bold, and in smaller print the value from V5for those that are > 0 (assuming non-negative values).

  • I've found the later solution of creating more data the generally superior solution because how the syntax goes (and which language) is subject to change over time. But a broken off data set, while strictly unnecessary, isn't subject to changing over the versions. Also futzing with snippets of code over and over again is godawful time sink if you're not fluent in said code. – Alpheus Jan 31 at 16:57
3

In Layer Properties - Labels- Method click the drop down to select Define Classes, then use the SQL Query to limit the label to only those features.

Alternately you could use a selection query for those features, save the selection as a new layer in your TOC using the create features option, and then label those features.

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.