[MapServer-users] How to format labels on contours

Trygve Aspenes trygve at aspenes.priv.no
Sat Oct 21 01:25:32 PDT 2023


Thanks Seth

I'm sure I did try the setText method, but I forgot to mention that in 
the post.

Thanks for the tip of convertToString() method.

Using your example I get
LABEL
   <label parameters>
   TEXT (tostring(([SQKM]),"%.0f")+" km2")
END # LABEL

And the expected label format in my contour layer.

Somehow I must missed something with I tried this in the first place, I 
think the parentheses around tostring.

Thanks again!

Trygve Aspenes



Den 2023-10-21 09:04, skrev Seth G:
> Hi,
> 
> The MapScript API docs are back online - see 
> https://mapserver.org/mapscript/mapscript-api/stub/mapscript.classObj.html#mapscript.classObj
> 
> The setText() method should give you what you need. Example (using 
> Python):
> 
> s = mapscript.classObj(layer)
> # other style and label stuff
> s.setText('(tostring(([SQKM]),"%.0f")+" km2")')
> # check the output using
> print(s.convertToString())
> 
> When using updateFromString it will replace everything in the classObj 
> hence the error.
> 
> Seth
> 
> 
> --
> web:https://geographika.net & https://mapserverstudio.net
> twitter: @geographika
> 
> On Fri, Oct 20, 2023, at 9:16 PM, Trygve Aspenes via MapServer-users 
> wrote:
>> Hi
>> 
>> So I have made a contour plot from a raster. Works nicely.
>> Then I added labels to give context to the contours. Fine.
>> Now I want to format the labels.
>> 
>> I have found this post
>> https://gis.stackexchange.com/questions/350089/round-number-for-label-in-mapserver
>> suggesting a syntax:
>> TEXT (tostring(([SQKM]),"%.0f")+" km2")
>> 
>> Nice, but I use mapscript. And I do not understand nor find any 
>> examples
>> how I could do this with mapscript
>> I tried with:
>> s = mapscript.classObj(layer)
>> <other style and label stuff>
>> s.updateFromString('TEXT (tostring(([SQKM]),"%.0f")+" km2")')
>> 
>> But I get:
>> EOFError: loadClass(): Premature End-of-File.
>> 
>> So obviously not correct.
>> 
>> Is there someone who could suggest what could be wrong here or what 
>> else
>> to look at and try?
>> 
>> Trygve Aspenes
>> _______________________________________________
>> MapServer-users mailing list
>> MapServer-users at lists.osgeo.org
>> https://lists.osgeo.org/mailman/listinfo/mapserver-users


More information about the MapServer-users mailing list