Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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!

share|improve this question
    
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
add comment

3 Answers

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

Function FindLabel ( [yourfield] )
  if isnull( [yourfield]) then
    FindLabel = "WO"
  else
    FindLabel = [yourfield]
  end if
End Function
share|improve this answer
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! I appreciate that –  kenbuja Oct 14 '11 at 13:48
    
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
add comment

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.
share|improve this answer
add comment

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"
  else
    FindLabel = ucase([LABELFIELD])
  end if
End Function
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.