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@lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/mapserver-users
_______________________________________________
MapServer-users mailing list
MapServer-users@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/mapserver-users

Reply via email to