4

I have results that range from ex. 113,009 down to 0.00495 - Can someone recommend a way to write/construct a label expression for the following in ArcMap:

• If less than 1, use 2 decimal places (or three if absolutely necessary to show the first non-zero value) • From 1 to 10, use 1 decimal place • If 10 or greater, use no decimal places

Or a way to quickly generate a new text column/field which adheres to the above?

1
  • Certainly, sorry about that...done.
    – Michael
    Commented Mar 27, 2014 at 18:25

1 Answer 1

4

Put the code below as the label expression for your feature in ArcMap. Set the parser to Python and check the Advanced box. Change [yourField] to the field containing the values you want to label.

def FindLabel([yourField]):
    if [yourField] is not None:
        value = float([yourField])
        if value < 1:
            return round(value, 3)
        elif 1 <= value < 10:
            return round(value, 1)
        else:
            return round(value, 0)
    else:
        return None

I put the values that are less than one to three decimal places, but change it to two if you want.

5
  • Please do not "correct" the elif line here because the elif 1 <= value < 10:syntax is quite valid and, I think, more pythonic than a non-author edit which was made to it and approved.
    – PolyGeo
    Commented Mar 27, 2014 at 8:11
  • @PolyGeo yes my bad and I apologize. I saw it and the quick reaction from the programmer in me changed it so that it made sense to someone reading it. Both work. For the record pythonic at times is synonymous with esoteric which generally is not good for reusable code.
    – GeoSharp
    Commented Mar 27, 2014 at 18:00
  • @JamesSLC Yeah, well, you know, that's just, like, your opinion, man.
    – ianbroad
    Commented Mar 27, 2014 at 18:19
  • @ian I agree. No worries/disrespect though, I upvoted your answer.
    – GeoSharp
    Commented Mar 27, 2014 at 18:22
  • 1
    @JamesSLC No I didn't think that. I just wanted to use a quote from The Big Lebowski :)
    – ianbroad
    Commented Mar 27, 2014 at 18:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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