2

Is it possible to convert a value string into a float in a mapfile? The code is in CLASS / TEXT, so I can use expression.

For example my value is always displaying ".7". I would like to display "0.7". But I can't do "0" + [value], because sometimes, I have "1" and I don't want to show "01".

For now, it seems that a function float() doesn't exist.

I have MapServer 7.

Edit:

I also try ternary operation like:

TEXT (length([value]) = 1 ? [value] : "0"+[value])

But ternary doesn't exist...

1 Answer 1

1

The tostring expression should help you. The mapfile

MAP
  SIZE 100 100
  EXTENT 0 0 100 100
  UNITS meters
  IMAGETYPE png
  LAYER
    STATUS DEFAULT
    TYPE POINT
    FEATURE
      POINTS
        50 50
      END
      ITEMS ".7;1"
    END
    PROCESSING "ITEMS=without,with"
    CLASS
      LABEL
        TEXT (tostring([without],"%.2f") + " " + tostring([with],"%.1f"))
      END # LABEL
    END # CLASS
  END # LAYER
END # Map file

produces the following image with Mapserver 7.0.1

enter image description here

See also Mapserver CLASS documentation (http://mapserver.org/mapfile/class.html).

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.