Building and display scalebar object using python mapscript

Sean Gillies sgillies at FRII.COM
Tue Aug 17 16:58:20 EDT 2004


On Aug 17, 2004, at 2:28 PM, William Hudspeth wrote:

> Hello,
>
> Does anyone have a code snippet illustrating building and displaying a
> scalebar object using python mapscript?
>
> Thanks, Bill
>
>

Bill,

Say you have a mapObj instance named 'the_map'.  You can modify
properties
of the map's scalebar like

     the_map.scalebar.height = 10
     the_map.scalebar.width = 100

See the mapscript documentation at

     http://users.frii.com/sgillies/projects/mapscript/4.2/mapscript.html

for details of scalebar properties.

The scalebarObj class has no drawing methods of its own, you have to
draw it through methods of the parent mapObj.  drawScalebar returns an
instance of imageObj:

     scalebar_image = the_map.drawScalebar()

You can save the image to disk for use

     filename = 'scalebar.%s' % (scalebar_image.format.extension)
     scalebar_image.save(filename)

You can also embed the scalebar in the map image

     map_image = the_map.draw()
     the_map.embedScalebar(map_image)   # puts scalebar into label cache
     the_map.drawLabelCache(map_image)

Hope this helps,
Sean

--
Sean Gillies
sgillies at frii dot com
http://users.frii.com/sgillies



More information about the mapserver-users mailing list