[Mapserver-users] Annotation setExpression() problem

Rene Teniere TENIERER at gov.ns.ca
Mon Feb 16 13:58:16 EST 2004


Charlton,

I added the parentheses, but it didn't work, and I put it exactly the
way it was written in the variable in the mapfile: EXPRESSION
/1699|1804/ and that worked! The problem is that the expression is being
changed, but doesn't seem to be applied to the layer itself. I checked
this through the getExpression(), whereby I printed out the initial
expression (the one that's in the mapfile ([TRTAREA]>0)), then set the
new expression and printed that one out. The formats should be
acceptable. Ex: If I initially set the mapfile expression to: EXPRESSION
/1699|1700/ then through getExpression(), /1699|1700/ is printed off.
When I use setExpression($sExp) whereby $sExp = "/1699|1700/",
/1699|1700/ is printed off as well. The difference is that the first one
works (I only get poly's 1699 and 1700 displayed), while the other
method does not work at all. If the initial expression is different than
the one set in PHP, the original mapfile expression is used. Man I hope
this makes sense to someone :(

Rene

>>> "Charlton Purvis" <cpurvis at asg.sc.edu> 2004-02-16 2:15:06 PM >>>
Rene:

I know that I have to put in opening and closing parens for my
setFilter's (for postgis), and that isn't explicitly documented in the
PHP documentation.  Maybe you could try that?

Or what if you tried to dump everything to a .map to see the state of
all your variables?

Charlton

> -----Original Message-----
> From: Rene Teniere [mailto:TENIERER at gov.ns.ca] 
> Sent: Monday, February 16, 2004 12:26 PM
> To: mapserver-users at lists.gis.umn.edu 
> Subject: [Mapserver-users] Annotation setExpression() problem
> 
> Hi all,
> Wondering if someone can help me here. I am creating an annotation
> layer with a dynamic expression to label only what I want each time.
> Problem is that I cannot set the expression through mapscript. It
works
> fine hard-coded in the mapfile, but it has to be done through php.
The
> expression would look like: /1234|2345|3456/ or /1234/  That is
> represented in the $sExp variable in the code below. At first I set
up
> the mapfile annotation layer without an expression then used
> $class->setExpression($sExp); to set the expression. That did not
work,
> even though the variable contents worked in the mapfile with the
desired
> results.
> 
> Next, I got rid of the annotation layer in the map file and decided
to
> create it through php/mapscript. The end results showed up with no
> annotation at all. The code for the layer creation is below, and I
have
> no idea why it will not work. Anyone have any ideas?
> 
> Rene
> 
>    <?php
>       $map_path = "C:/chameleon11a/websites/wap/";
>       $map = ms_newMapObj($map_path."sketch.map");
>       $map->setExtent($minX-10, $minY-10, $maxX+10, $maxY+10);
>       $image = $map->draw();
>       $wap = $map->getLayerByName("WAP");
>       $shapes = ms_newLayerObj($map, $wap);
>       $shapes->set("name","Shapes");
>       $shapes->set("data","");
> 
>       //Create the annotation layer
>       $anno = ms_newLayerObj($map);
>       $anno->set("name","annolayer");
>       $anno->set("maxscale",500000);
>       $anno->set("status",MS_ON);
>       $anno->set("data","D:\gis_data\wap_2002\all");
>       $anno->set("type",MS_LAYER_ANNOTATION);
>       $anno->set("labelitem","ID");
>       $anno->set("classitem","ID");
> 
> 
>       $class = ms_newClassObj($anno);
>       $class->set("name","annoclass");
>       $class->set("status",MS_ON);
> 
>       $class->label->type->MS_BITMAP;
>       $class->label->size->MS_MEDIUM;
>       $class->label->position->MS_CC;
>       $class->label->color->setRGB(255,0,0);
> 
>       //Create Annotation Expression
>       $sExp = "/".$nID[0];
>       for($k=0; $k<=$nCOUNT; $k=$k+1)
>       {
>         if($k>0)
>         {
>           $sExp = $sExp."|".$nID[$k];
>         }
>       }
>       $sExp = $sExp."/";
> 
>       //$expression = $class->getExpression();
>       //error_log("Before:".$expression);
> 
>       $class->setExpression($sExp);
> 
>       //$expression = $class->getExpression();
>       //error_log("After:".$expression);
> 
>       $shapes_class = ms_newClassObj($shapes);
> 
>       $wap->open();
>       for($j=0; $j<=$nCOUNT; $j=$j+1)
>       {
>         $nShape[$j] = $wap->getShape(-1, $nIndex[$j]);
>         $nShape[$j]->draw($map, $shapes, $image);
>       }
>       $wap->close();
> 
>       $scalebar = $map->drawScaleBar();
>       $image_url = $image->saveWebImage();
>       $scalebar_url = $scalebar->saveWebImage();
>     ?>
> 
> _______________________________________________
> Mapserver-users mailing list
> Mapserver-users at lists.gis.umn.edu 
> http://lists.gis.umn.edu/mailman/listinfo/mapserver-users



More information about the mapserver-users mailing list