1

I am mapping the municipalities 911 numbers on our road network and built a simple python expression to find the lowest value between 2 fields. Then it shows that value on the line followed by an arrow indicating direction of numbers ascending.

Spot checks revealed random segments that did not present the correct value.

If anyone can spot the problem, please let me know.

def FindLabel ( [L_FIRST], [R_FIRST] ):
    if [L_FIRST] < [R_FIRST]:
        return [L_FIRST] + '>'
    elif  [R_FIRST] < [L_FIRST]:
        return [R_FIRST] + '>'
  • 2
    Convert them to numbers using float or int. Label engine treats them as strings, e.g. "2">"11" – FelixIP Feb 24 '17 at 21:43
  • 1
    Welcome to GIS SE! As a new user please take the tour to learn about our focused Q&A format. Please edit your question to include a sample of the values you have in your two fields (including some that aren't working), and details about your fields such as field type. – Midavalo Feb 24 '17 at 22:26
4

As FelixIP has commented, the fields are possibly being assessed as text rather than as numbers.

To illustrate:

> x = "333"
> y = "44"
> if x > y:
>     print "yes"
> else:
>     print "no"
no

This is because when a string is assessed for order (or greater than / less than) it starts at the left, as if it's a word (text) being sorted. 3 is less than 4 therefore "333" is less than "44". Or to use a text analogy, LARGE comes before SMALL when sorting alphabetically, therefore LARGE < SMALL!

To make it assess as numbers use int() or float() when assessing the two fields.

> x = "333"
> y = "44"
> if float(x) > float(y):
>     print "yes"
> else:
>     print "no"
yes

So in your code convert the strings to numeric to have these assess correctly

def FindLabel ( [L_FIRST], [R_FIRST] ):
    lf = float([L_FIRST])
    rf = float([R_FIRST])
    if lf < rf:
        return [L_FIRST] + '>'
    elif  rf < lf:
        return [R_FIRST] + '>'
  • Elit not really needed +1 you have patience – FelixIP Feb 25 '17 at 2:51

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.