[Mapserver-users] How can I get the query info programatically?

Stephen Woodbridge woodbri at swoodbridge.com
Tue May 18 19:36:02 PDT 2004


Oh and one more critical thing to remember is that any layer you want to 
query MUST have a TEMPLATE "dummy" or a real TEMPLATE to get any results 
returned from it.

-Steve

Paul Spencer wrote:

> Ethan,
> 
> the guts of it (for php mapscript) run something like this (completely 
> untested for syntax or logic errors):
> 
> //replace this with whatever your input is and your desired
> //query method, I'm assuming form variables named nX and nY
> //will contain the PIXEL location to query at
> 
> $oPoint = ms_newPointObj();
> $oPoint->setXY( $_GET['nX'], $_GET['nY'] );
> if (@$oMap->queryByPoint( $oPoint, MS_MULTIPLE, -1) == MS_SUCCESS)
> {
>     //query returned something, find out what by inspecting each layer
>     for ($i=0; $i<$oMap->numlayers; $i++)
>     {
>         $oLayer = $oMap->getLayer($i);
>         $nResults = $oLayer->getNumResults();
>         if ($nResults > 0)
>         {
>             echo "results for layer ".$oLayer->name."<BR>";
>             $oLayer->open();
>             for ($j=0; $j<$nResults; $j++)
>             {
>                 $oResult = $oLayer->getResult($j);
>                 $oShape = $oLayer->getShape( $oResult->tileindex, 
> $oResult->shapeindex);
>                 //now you can access $oShape->values as an associative
>                 //array of key:value pairs
>                 foreach($oShape->values as $key => $value)
>                 {
>                     echo "$key => $value<BR>";
>                 }
>             }
>             $oLayer->close();
>         }
>         else
>         {
>             //no results for this layer
>             echo "no results for layer ".$oLayer->name." :(<BR>";
>         }
>     }
> }
> else
> {
>     //query returned nothing
>     echo "no results found on any layer :(<BR>";
> }
> 
> If you get this working, perhaps you could do as Stephen has suggested 
> and add it to the accumulated knowledge of MapServerdom ;)
> 
> it is also possible to query just one or several layers directly using 
> essentially the same method but accessing the layer object for 
> queryByPoint instead.
> 
> Cheers,
> 
> Paul
> 
> Stephen Woodbridge wrote:
> 
>> Ethan,
>>
>> THere are ac bunch of Query examples at
>> http://mapserver.gis.umn.edu/cgi-bin/wiki.pl?PerlMapScriptExamples35
>> for mapserver 3.5 but on the bottom is an example mapserver 4.2. Look 
>> at the quake.pl I think that does some query stuff.
>>
>> I also check the archives, because this has been asked before. I 
>> thought there was a straight forward query example, but I can't seem 
>> to locate the one I was thinking of. Once you get your example worked 
>> out you might want to post it to the wiki for others.
>>
>> -Steve
>>
>> Ethan Alpert wrote:
>>
>>> Any chance you can be more specific? I've been to the docs several times
>>> looking for how to do this and I'm not finding what I'm looking for.
>>>
>>> I need to access information about items that were selected with a
>>> query.
>>>
>>> -e
>>>
>>> -----Original Message-----
>>> From: Stephen Woodbridge [mailto:woodbri at swoodbridge.com] Sent: 
>>> Tuesday, May 18, 2004 5:39 PM
>>> To: Ethan Alpert
>>> Cc: mapserver-users at lists.gis.umn.edu
>>> Subject: Re: [Mapserver-users] How can I get the query info
>>> programatically?
>>>
>>>
>>> Yes, and there are examples. See
>>>
>>> http://mapserver.gis.umn.edu/doc.html
>>> http://mapserver.gis.umn.edu/cgi-bin/wiki.pl
>>>
>>> -Steve
>>>
>>> Ethan Alpert wrote:
>>>
>>>
>>>> I'd like to get the information of the items selected in a query. 
>>>> The template approach isn't quite what I'm looking for. Is there a 
>>>> way to extract this info with perl (or php) mapscript?
>>>>
>>>> -e
>>>>
>>>> _______________________________________________
>>>> Mapserver-users mailing list Mapserver-users at lists.gis.umn.edu
>>>> http://lists.gis.umn.edu/mailman/listinfo/mapserver-users
>>>>
>>>
>>>
>>>
>>
>> _______________________________________________
>> 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