I need to label some hydrants (points) - some of these belong to the fire brigade and have a number assigned to them, some do not and thus do not have a number. I would like to write an expression along the lines of:

'Label Hydrant with number if number exists, if hydrant has null value label with 'WO'.'

I just can't figure it out.

The simplest way for me to do this would be to change the null values to WO but the data is not mine, and I do not want to make changes to it. I suppose I could make a copy and put the values in the copy, but ideally I would like an expression.


  • Thanks, Think I'm still missing something this is what I am doing: 1. Tick Label features in the layer 2. Select 'Define classes of features and label each class differently 3. Add label Class Number 4. Add Label Class WO 5. tick 'label features in this class' for each <br/> 6. Under 'Number' click SQL Query use ("SYMBOLCODE" = 3 ) AND ( "FIREAUTHOR" <> "") 7. Label field is set to FIREAUTHOR 8. For WO SQL is ("SYMBOLCODE" = 3 ) AND ("FIREAUTHOR" ="") 9. Expression is "WO" 10. Get error 'no features found. Could not verify expression' – jorp Oct 14 '11 at 14:06

You can use a simple script like this to label the features with Null values.

Function FindLabel ( [yourfield] )
  if isnull( [yourfield]) then
    FindLabel = "WO"
    FindLabel = [yourfield]
  end if
End Function
  • 1
    It's great to see you on gis.se. Your answers on the ESRI forums have helped a lot of people, including me. – Devdatta Tengshe Oct 14 '11 at 13:41
  • Thanks - this script is certainly neat, but the null values are not being labelled as WO. – jorp Oct 14 '11 at 15:31
  • 1
    Are you working with values that are showing up as <Null> or as blanks in the attribute table? – kenbuja Oct 14 '11 at 15:58

Here is what you can do.

  1. Set up two labeling classes under the labeling tab under the Method: Define clases of features and label each class differently.
  2. Create a hydrant class that has numbers and one that does not (e.g. Number, & WO).
  3. For the number class define the SQL Query as, "MyLabelField" <> ""
  4. Point the number class to the correct label field.
  5. For the WO class define the SQL Query as, "MyLabelField" = ""
  6. For the WO class under the Expression option type, "WO"
  7. Turn labeling on.

Further to @kenbuja sript which is the correct answer; If you have a combination of null and 0 length strings or spaces with no characters you could do something like this:

Function FindLabel ( [LABELFIELD] )
  if  isnull([LABELFIELD]) then
    FindLabel = "WO"
  elseif trim([LABELFIELD]) = "" then
    FindLabel = "WO"
    FindLabel = ucase([LABELFIELD])
  end if
End Function

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.