[Mapserver-users] help with python mapscript (no image)

Sean Gillies sgillies at frii.com
Tue Dec 30 13:58:48 EST 2003


Cristoph,

Glad to help.  There are more tips about using Python MapScript at

http://mapserver.gis.umn.edu/cgi-bin/wiki.pl?PythonMapScript

I'm using mod_python as well.  Maybe you'd be interested in
sharing notes about it on the Wiki site?

The advantage to using a string's join method is that it makes for
more readable and maintainable code.  Another good alternative is
this type of statement

     filename = '%s.%s' % (myMap.name, myImg.format.extension)

cheers,
Sean

On Tuesday, December 30, 2003, at 11:38  AM, Christoph Spoerri wrote:

> Hi Sean,
>
> thanks for your help. The code and comments you sent were very 
> usefull. I had
> to changed the code a bit to make it work, but I saw that you had to 
> save the
> map image explicit to a file (w/ name) set the URL appropriately. With 
> the
> PHP mapscript this is done for you.
>
> Thanks for your help!
> Christoph
>
> BTW. is there an advantage to using join() than using '+' to append 
> strings?
>
> On Tuesday 30 December 2003 12:38 pm, Sean Gillies wrote:
>> Hi Cristoph,
>>
>> Are you using 4.0.1?  If not, I strongly recommend that you download
>> and build MapServer 4.0.1.
>>
>> I'll try to explain the right way to do this with a little script:
>>
>>      # I'm pretty sure that import * is safe, but not 100% sure
>>      from mapscript import mapObj
>>      import os
>>
>> 	# Create map instance
>>      myMap = mapObj('/var/www/htdocs/mapserver/obis_test/testing.map')
>>
>>      # Draw map.  The resulting image acquires 'imagepath' and
>>      # 'imageurl' attributes from myMap and also acquires a 'format'
>>      # that is the same as the selected format of myMap, in this
>>      # case the built-in 'PNG24' format as defined in your map file
>>      mapImg = myMap.draw()
>>
>>      # Save image to the imageurl location using a filename formed
>>      # from the map name and the output format extension, result
>>      # in your case will be 'PYDEMO.png'
>>      imagename = '.'.join((myMap.name, mapImg.format.extension))
>>      mapImg.save(os.path.join(mapImg.imageurl, imagename))
>>
>> The IMAGEURL is a directory name.  It's not really required for a
>> Python MapScript app like it is with the mapserv CGI, but it remains
>> useful.
>>
>> Hope this helps, cheers,
>> Sean
>>
>>
--
Sean Gillies
sgillies at frii dot com
http://users.frii.com/sgillies




More information about the mapserver-users mailing list