Solution: mapscript setExpression problems

Robert Chavez rchavez at perseus.tufts.edu
Fri Oct 20 14:51:20 EDT 2000


I figured it out.  
There's nothing wrong with the setExpression function I was using.  

The problem is (it seems) that when you reset an expression in a class
after the map file is read in you can no longer use the other attributes
of that class -- in effect, you are redefining the class.

As a result, I couldn't use the color codes I had written into the map
file for that class -- the layer drew, but it just appeared blank.  Once I
also redefined the color the layer was rendered according to the
expression.

So originally I had this bit of code (which didn't work):
$layer = $map->getLayerByName(leis);
$class = $layer->getClass(0);
$class->setExpression("\"Bankside Gallery\"");
$layer->draw($map, $img);

and I changed it to this (which worked):
$layer = $map->getLayerByName('leis');
$class = $layer->getClass(0);
$class->setExpression("Bankside Gallery");
$class->{'color'} = $color;
$layer->draw($map, $img);

where $color is defined using addColor() prior to running prepareImage().  
I probably should have picked up on that earlier.

For what it's worth.

Rob Chavez
Perseus Project


On Fri, 20 Oct 2000, Doyon, Jean-Francois wrote:

> Humm, well my first thought would be about those escaped double-quotes ...
> do you really need them ?
> 
> Wouldn't just $class->setExpression("Bankside Gallery");
> 
> work ? Of course if the double quotes are IN the DBF, that could be weird
> ...
> 
> J.F.
> 
> > ----------
> > From: 	Robert Chavez[SMTP:rchavez at perseus.tufts.edu]
> > Sent: 	Friday, October 20, 2000 10:57 AM
> > To: 	mapserver-users at lists.gis.umn.edu
> > Subject: 	mapscript setExpression problems
> > 
> > 
> > Howdy folks,
> > 
> > I'm having some trouble changing an expression in a layer using
> > setExpression.  All this should do is highlight the polygon whose NAME
> > attribute matches "Bankside Gallery" but when the map draws I get a blank
> > layer, no highlighting.
> > 
> > Spelling and capitalization are correct and the original expression in the
> > layer renders correctly, so I must be doing something wrong with
> > setExpression.  Can anyone shed a little light?  I'm using version
> > 3.3.011.
> > 
> > Here's my snippet of code:
> > 
> > $layer = $map->getLayerByName(leis);
> > $class = $layer->getClass(0);
> > $class->setExpression("\"Bankside Gallery\"");
> > $layer->draw($map, $img);
> > 
> > and mapfile layer:
> > LAYER
> >  NAME leis
> >  TYPE POLYGON
> >  STATUS DEFAULT
> >  DATA blg_leis
> >  CLASSITEM "NAME"
> >  CLASS
> >    EXPRESSION "Buckingham Palace"
> >    COLOR 255 204 0
> >  END
> > END
> > 
> > Thanks,
> > Rob Chavez
> > Perseus Project
> > 
> 




More information about the mapserver-users mailing list