[mapserver-users] New method for Python mapscript

Sean Gillies sgillies at i3.com
Mon Aug 12 11:07:08 PDT 2002


Greetings Python mapscript users,

Recently, I've found the use for getting mapserver map images as
Python string objects.  Rather than fill in the empty Python
getImageToVar() method, I decided to write a new interface for
a method I'm calling getImageString().  Mostly I disagreed with
the notion of getting to a variable through its name as a string.

I'm including the code that you might paste into your mapscript.i
file within the imageObj definition.  You will need to modify your
setup.py script so that -DUSE_GD_PNG and -DUSE_GD_JPEG as passed as
arguments to swig.  I've only tested this with gd-1.8.4 but will be
moving on to gd-2 next week.

So, now we can do stuff like this:

    import MapScript

    mapob = MapScript.mapObj(...)
    imgob = mapObj.draw()
    data = imgob.getImageString(...)
    png = file("map.png", "wb")
    png.write(data)
    png.close()

This is trivial.  It's more useful for creating Zope image objects
from a Zope Python script like this:

    import StringIO
    import MapScript

    mapob = MapScript.mapObj(...)
    imgob = mapObj.draw()
    data = StringIO.StringIO(imgob.getImageString(...))
    self.manage_addImage('map.png', data, "", "", 'image/png')

Hope that you find this of use and happy to hear any other ideas.

cheers,
Sean
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: getImageString.txt
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20020812/546229f6/attachment.txt>


More information about the MapServer-users mailing list