Simple VBScript Label Expression for labelling certain records of a shapefile

2381
3
07-25-2012 11:36 AM
KittyYiu
New Contributor II
I have a water feature shapefile have the names of all the records (names of the lakes, rivers, creeks, etc), but I only want to label certain water features (the major lakes for example) and at the same time showing all the water features (that is not definition querying out certain records) on the map.

By default labelling it would label all the records, which is not my preference for the map visualization.

Is there a VBScript Label Expression for labelling certain records of a shapefile ?
(In this case, I know the names of the major water features which I want to label).

Because right now I has been labelling them one-by-one using the text tool, which is not quit efficient at times.
Tags (2)
0 Kudos
3 Replies
DonovanCameron
Occasional Contributor II
You can apply a similar type of query that applies only to the labels.

Open the properties for that layer and go to the Label tab.

Select the field to label by (ie, [FEAT_NAME]) and press the "Expression" button.

Place a checkmark beside "advanced" and read over this recent thread on how to do just that.
http://forums.arcgis.com/threads/63054-Labels-again.-Sorry

Let the forum know if you have any issues.

In your case, you may need to incorporate a wildcard like the '%' operator, inStr function, or a regular expression.
0 Kudos
KittyYiu
New Contributor II
It works, thanks.


[INDENT]Function FindLabel ( [NAME] )
if ( [NAME] = "Lake A" ) then
  FindLabel = [NAME]
end if
End Function[/INDENT]


But how do I set it that it would only label the "Lake A", the "Lake B", and the "Lake C" ?

I don't think I can use wildcard like the '%' in my case, as sometime the names of the water features goes like this "Lake A", or "B Lake"; "B River", or "River B".
0 Kudos
DonovanCameron
Occasional Contributor II

But how do I set it that it would only label the "Lake A", the "Lake B", and the "Lake C" ?

I don't think I can use wildcard like the '%' in my case, as sometime the names of the water features goes like this "Lake A", or "B Lake"; "B River", or "River B".


If you have a small set of records you want to label, try using OR.

[LEFT]Function FindLabel ( [NAME] )
  if ( [NAME] = "Lake A" ) OR ( [NAME] = "Lake B" )  then
    FindLabel = [NAME]
  end if
End Function[/LEFT]


If your OR statement is getting large, try to incorporate the IN operator instead of OR.

[NAME] IN ('LAKE A', 'LAKE B', 'C LAKE')


Although I always have trouble including IN inside a vbscript label expression, mostly because the syntax is different depending on the data storage format (shapefiles vs geodatabase, etc...).
0 Kudos