Problems translating map file layers to mapscript

Sean Gillies sgillies at FRII.COM
Tue Oct 18 17:31:47 EDT 2005


On Oct 18, 2005, at 1:58 PM, Damon Butler wrote:

> [...]
>>> They can be made transparent by supplying negative numbers for the  
>>> R, G,
>>> and B values.
>>>
>>> c.label.backgroundcolor = mapscript.colorObj(-1, -1, -1)
>>> c.label.outlinecolor = mapscript.colorObj(-1, -1, -1)
>>
>> Never done must this be! Proper usage is
>>
>>     c.label.backgroundcolor.setRGB(-1, -1, -1)
>>     c.label.outlinecolor.setRGB(-1, -1, -1)
>>
>> Otherwise the previously defined colors will be dereferenced  
>> improperly
>> and never cleaned up by Python's garbage collector. Anyhow, these
>> attributes begin with default values (-1, -1, -1), so no need to alter
>> them if you want the no-background default.
>
> I (we, actually) tried your syntax, but neither the backgroundcolor nor
> the outlinecolor attributes on the label object are color objects, and
> so attempting to call the setRGB method on them fails with an
> AttributeError. According to the mapscript API, and introspection of a
> mapscript-parsed map file in a Python interpreter, those attributes  
> must
> be set with mapscript color objects. Hence the code I previously  
> listed.
>

What MapServer and SWIG versions are you using? My experience is  
otherwise. Here's a sample session using mapscript from MapServer 4.4,  
generated using SWIG 1.3.25:

Python 2.3 (#1, Sep 13 2003, 00:49:11)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
 >>> import mapscript
 >>> c = mapscript.classObj()
 >>> c.label.backgroundcolor
<C colorObj instance at _0030b254_p_colorObj>
 >>> bg = c.label.backgroundcolor
 >>> bg.red, bg.green, bg.blue
(-1, -1, -1)

Now with a mapfile:

 >>> m =  
mapscript.mapObj('/Volumes/lenny/projects/ms_HEAD/mapserver/tests/ 
test.map')
 >>> l = m.getLayer(1)
 >>> c = l.getClass(0)
 >>> bg = c.label.backgroundcolor
 >>> bg
<C colorObj instance at _007e6074_p_colorObj>
 >>> bg.red, bg.green, bg.blue
(-1, -1, -1)

> I should note that the layer in question is being generated entirely
> from scratch with mapscript. It is not being modified from a layer that
> has been read in from a map file. We have learned that this means we
> have to set all kinds of default values that otherwise appear to be
> assumed. Having no background, for example, is not the default behavior
> for a layer generated entirely using mapscript commands. (It is, in
> fact, a solid black rectangle.)
>

Nothing in this area has changed significantly between 4.4 and 4.6, the  
labels above would be rendered with no background. Could you write back  
and show the relevant lines of your program?

> Your suggestion to specify basic values for our layers in a map file  
> and
> then merely modify them via mapscript commands is an excellent one,
> however, and definitely would simplify what we're trying to do. For
> workflow considerations, we hadn't considered it, let alone thought it
> possible.
>
> Thanks!
> --Damon
>

BTW, Damon, I'm also collaborating with other Python users on a new web  
programming package

     http://zcologia.org/pcl

The goal is to have all the capabilities of mapscript (because we use  
MapServer for rendering), but a more natural and safer API. If you are  
starting from scratch and don't need to reuse existing mapfiles, PCL  
may be worth a look.

cheers,
Sean

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



More information about the mapserver-users mailing list