[Mapserver-users] help with python mapscript (no image)
Christoph Spoerri
spoerri at duke.edu
Tue Dec 30 10:38:06 PST 2003
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
>
> On Tuesday, December 30, 2003, at 09:55 AM, Christoph Spoerri wrote:
> > Hi there,
> >
> > After using the php mapscripts for over a year now, I started to look
> > into the
> > python mapscripts. It seems to provide more functionality and doesn't
> > have to
> > have to be run as cgi (I'm using mod_python).
> >
> > The compilation, installation and setup went pretty smoothly. Now, I
> > would
> > like to create my first map, but for some reason I do not get an image
> > in my
> > output directory. I can create an image of the map by saving the image
> > (imgObj::saveImage() ), but the mapObje::draw() doesn't seem to work.
> >
> > I run also the following from the python prompt:
> >>>> from mapscript import *
> >>>> myMap = mapObj('/var/www/htdocs/mapserver/obis_test/testing.map')
> >>>> mapImg = myMap.draw()
> >>>> mapImg.imageurl
> >
> > '/output/'
> >
> >>>> mapImg.save('/tmp/test.png')
> >
> > As you can see the imageurl only points to the directory where the
> > image
> > should be and doesn't include the image name.
> >
> > I spent the last 4 hours search the mailing list, google, etc, yet
> > wasn't able
> > to find a solution. Any ideas? I have attached my map file.
> >
> > thanks, and a happy new year
> >
> > Christoph
> >
> > ************** my map file ************************
> >
> > MAP
> > NAME PYDEMO
> > EXTENT -180 -90 180 90
> > SIZE 400 300
> > SHAPEPATH "/usr/local/ims_data/"
> >
> > UNITS DD
> > RESOLUTION 72
> > IMAGETYPE PNG24
> > IMAGECOLOR 245 245 245
> > WEB
> > IMAGEPATH "/var/www/htdocs/ims_output/"
> > IMAGEURL "/output/"
> > END
> >
> > LAYER
> > NAME "Background"
> > STATUS DEFAULT
> > DATA "datalib/global/ocean_log.tif"
> > TYPE RASTER
> > OFFSITE 0 0 0
> > END
> >
> > LAYER
> > NAME "Continents"
> > STATUS DEFAULT
> > DATA "datalib/global/world_usa_canada"
> > TYPE POLYGON
> > TRANSPARENCY 0
> > CLASS
> > COLOR 180 210 170
> > OUTLINECOLOR 150 190 140
> > END
> > END
> > END
>
> --
> Sean Gillies
> sgillies at frii dot com
> http://users.frii.com/sgillies
More information about the MapServer-users
mailing list