[mapserver-users] URL encoding for map file classexpressions

Stephen Woodbridge woodbri at mediaone.net
Wed Oct 31 14:56:36 EST 2001


In PHP you can have URL arguments like:

http://host/myfile.php?abc[]=expr-1&abc[]=expr-2&abc[]=expr-3

which will create a PHP array called abc and push each argument onto it,
so in the example above you would get:

abc[0] = expr-1
abc[1] = expr-2
abc[2] = expr-3

the [] is synonmous with push

I hope this helps.
  -Steve

ANDREW WOOLEY wrote:
> 
> Armin,
> 
> I think that I understand your question.  Pardon me if this is not what you were asking:
> 
> The way that I got around this is to use URL friendly characters and then use the PHP function explode().  Following is a snippet of code (pardon the poor coding):
> 
> if ($addto)
> {
>   if ($expr)
>     {
>       $routeid = $routeid . "_" . $expr;
>      }
> }
> 
>  $epr = explode("_", $routeid);
> 
> for($i = "0"; $i < sizeof($epr); $i++)
> {
> if ($i == 0 )
> {
> $newexpr = "(";
> }
> $newexpr = str_replace ("))", ") or ", $newexpr);
> 
> $newexpr = $newexpr . "([ID] eq " . $epr[$i] . ")";
> if ($i == sizeof($epr));
> {
> $newexpr = $newexpr . ")";
> }
> }
> 
> echo ("<input type=\"hidden\" name=\"expr\" value=" . $routeid . ">\n");
>  $oLayer = $map->GetLayerbyName("allbuiltQ");
> $FirstClass = $oLayer->GetClass(0);
> $FirstClass->setExpression($newexpr);
> 
> $oLayer->set("status", 1);
> 
> The first part of the code checks to see if the user wants to add to the selection and the $routeid is the value from the attribute table for the feature clicked.  Then it explodes the $epr which is the class expression and loops through the resulting array to build the expression string.  Then I set a hidden form variable to be the new expression value so it will be returned on the next form submit and set the class expression.  It works really well and seems to be quite fast.
> 
> I hope this helps.  Let me know if you have questions.
> 
> Andrew
> 
> Andrew Wooley
> GIS Operations Manager
> Mountainland Association of Governments
> Orem, UT
> 
> phone:  801.229.3844
> fax:       801.229.3801
> email:   awooley at mountainland.org
> web:    www.maps.mountainland.org
> 
> >>> Armin Burger <armin.burger at territoriumonline.com> 10/31/01 08:47AM >>>
> Hi all,
> 
> I would like to do a query on a layer with a combination of FILTER and
> EXPRESSION using the query definition via the URL. If I want to query more
> than one expression, how would I encode these expressions in the URL?
> 
> For example:
> I have the URL part for the LAYER - FILTER tag for the layer 'landcoverq'
>   &map_landcoverq_filter=%22313%22
> searching for the number 313 in the field defined with FILTERITEM in the
> mapfile.
> 
> and I would like to have the corresponding URL encoding for the EXPRESSION
> tag of the class section
>   EXPRESSION ('[LANCOV_CD]'='215/1' or '[LANCOV_CD]'='215/2' or
> '[LANCOV_CD]'='220' )
> 
> Adding all the expressions one by one in the URL with
>   &map_landcoverq_class_expression=%22215/1%22...
> selects always only the last one.
> 
> I think it should be possible but don't how to achieve it. Thanks for any
> help.
> 
> Has anyone experiences how queries like that are facilitated using the
> functionality of PostGIS?
> 
> Armin
> 
> --
> Armin Burger
> Territorium Online
> Via Siemens 19 - 39100 Bolzano - Italy
> _



More information about the mapserver-users mailing list