[mapserver-users] New method for Python mapscript

Steve Lime steve.lime at dnr.state.mn.us
Thu Aug 15 00:06:10 EDT 2002


Sean: I added this to the CVS version. Have you checked the GIF enabled version of GD 1.8.4 to see if this is possible? I thought those guys did a pretty complete port, but perhaps not. This will need some updating with 3.7 since things like type, quality and so on are carried now in the imageObj (as an imageFormatObject) rather then independently).

Steve

Stephen Lime
Data & Applications Manager

Minnesota DNR
500 Lafayette Road
St. Paul, MN 55155
651-297-2937
>>> Sean Gillies <sgillies at i3.com> 08/12/02 13:10 PM >>>
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




More information about the mapserver-users mailing list