[Mapserver-users] Examples of simple map services with python mapscript?

Sean Gillies sgillies at frii.com
Fri Jul 30 12:37:47 EDT 2004


On Jul 30, 2004, at 10:13 AM, William Hudspeth wrote:

> Sean Gillies wrote:
>
>>
>> On Jul 29, 2004, at 3:04 PM, William Hudspeth wrote:
>>
>>> Does anyone have some simple examples of using python mapscript to 
>>> display a map service?
>>> Thanks, Bill
>>>
>>
>> Bill,
>>
>> At the 2004 MapServer Users Meeting and Open Source GIS conference I 
>> did a
>> workshop using Python mapscript.  The workshop web page is
>>
>> http://users.frii.com/sgillies/projects/mum04/workshop.html
>>
>> and has some examples.  One includes a lightweight web server built
>> using Twisted, a Python web app framework.  The other examples can 
>> easily
>> be adapted to a web platform like Apache + CGI.
>>
>> cheers,
>> Sean
>>
>
> Thanks again for helping out Sean,
> I am trying to get the basics down before proceeding too far. I looked 
> at your workshop scripts and power point demonstration, and am trying 
> to just display a simple map. Using the code below, all of the 
> mapscript functionality runs until the "save()" method:
> *************************************************************
>
> #start the map
> nmMap = mapscript.mapObj('/var/www/cgi-bin/python_test/nm_map.map')
>
> for i in range(nmMap.numlayers):
>    nmMap.getLayer(i).status=mapscript.MS_ON
>
> #render the map
> map_image=nmMap.draw()
>
> map_image.save("first.png")
>
> map_div="""<DIV ID='mapdiv'><input ID='mapimg' TYPE='image' 
> SRC='%s'></DIV>"""
>
> print map_div % "first.png"
>
> ******************************************************************
> then I get an error:
>
> IOError: msSaveImage(): Unable to access file. (first.png)
>
> *****************************************************************
> I suspect it has something to do with where or how I am storing my 
> output image files, I just don't know. Any help greatly appreciated.
>
> Bill
>

Bill,

Here is my recommendation:

Lets say you have a location like /var/www/html/ms-tmp for mapserver 
images
and that you make this directory accessible on the web by the url
http://HOST/ms-tmp.

In your script, you could define

     ms_temp_dir = '/var/www/html/ms-tmp'
     ms_temp_url = 'http://HOST/ms-tmp'

and then, when saving the image:

     image_name = 'first.%s' % map_image.format.extension
     image_path = os.path.join(ms_temp_dir, image_name)
     image_url = os.path.join(ms_temp_url, image_name)

     map_image.save(image_path)
     print map_div % image_url

See how you can get the file extension from the imageObj?

Sean

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




More information about the mapserver-users mailing list