1

I am trying to create a label expression that labels features that contain hike in their name (versus those that don't).

I have tried something like this:

def FindLabel ([Name]):
    if [Name] is "*hike*":
        return [Name]

But that eliminates all of my labels, instead of just labeling the hikes with hike in their name.

How would I do this in the label expression builder?

7

Please follow the python syntax-Just check if hike is in the Name. Below should work

def FindLabel ([Name]):
    if 'hike' in [Name]:
        return [Name]

But if you need to label only Name does not contain hike use below-

def FindLabel ([Name]):
    if 'hike' not in [Name]:
        return [Name]

'LIKE' is an SQL operator that may be used with wildcards e.g. asterisk, percent sign etc but here you need to use pure python!

For more on arcmap label expression please consult arcmap documentation e.g.here.

Edit:


If you want to use SQL and avoid python expression then use Maplex Label Manger ,most efficient labeling system for arcmap sofar, as below-

demo

If you want more label class and each class with different properties (SQL query and label style) then you can and class as you want as below- class For more on SQL expression use ESRI documentation e.g.here. Or use the answer provided by @Midavalo if want to use classic labeling.

  • I tried the Pythonic method you posted and that still did not work (it eliminated all the labels rather than just the ones I wanted). I ended up just creating SQL statements to filter them out. Thank you!! – user48149 Apr 20 '16 at 20:06
  • @user48149 Ah! first code label all that have hike in them and second does the reverse! Any way, i am happy that you managed to get things done. – SIslam Apr 21 '16 at 5:18
5

As an alternative to using code in the label parser, you can filter labels and have different label styles for different labels, by using Label Classes instead of changing the label parser:

  1. In your layer properties Label Tab, select "Define classes of features and label each class differently" from the Method drop-down.

    enter image description here

  2. Click on the "Add" button to add a new label class and enter a name for your class (in this case "Hike")

    enter image description here

  3. Set a SQL query to filter to the values you want to label

    enter image description here

  4. And OK out to view your labels

    enter image description here

This method allows you to create completely different labels for different values (and different fields if desired). Each class can be set up with different styles, fonts, colours, scales, placement settings etc.

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.