[mapserver-users] Can't figure out queries with Mapscript.

Thomas Haechler thaechl at geo.unizh.ch
Tue Jul 9 02:52:35 EDT 2002


hi chip and list,

I think what ben wants to know (and I couldn't figure it out eighter),
is how to use the processquerytemplate method, i.e. process a template
and replace some tags in it with query results, or link external info. 
Steve Lime recently answered this question for the cgi version

(http://mapserver.gis.umn.edu/wilma/mapserver-users/0206/msg00377.html),
but I don't know how it works with mapscript.

any ideas?
thanks,

Thomy



"Hankley, Chip" wrote:
> 
> Ben...
> 
> There's probably a number of ways to do this, but here's how I do it (see
> below). There's a Mapfile component, and a mapscript component. FWIW, this
> is essentially exactly the way it's done in the GMAP demo.
> 
> Cheers!
> 
> Chip
> 
> ----------------------------------------------------------------
> 
> ...in the mapfile, this would be the layer definition for the layer I want
> to query:
> 
> LAYER
>   NAME "DePere_Parcels"
>   METADATA
>     "DESCRIPTION"   "PARCEL_INFO"
>     "RESULT_FIELDS" "PARCEL_NUM AREA"
>       # These are the two fields (PARCEL_NUM and
>       # AREA) that I want to return
>   END
>   DATA parcels
>   STATUS DEFAULT
>   #minscale 5000
>   TYPE polygon
>   CLASS
>     TEMPLATE "ttt_query.html"
>     Name Parcels
>   END  # CLASS
> END  # LAYER
> 
> ... in the PHP code, I have a function that handles the query...
> 
> function query_map($map, $real_pts) {
> 
>   //$map is the Map Object
>   //$real_pts is an array with two members:
>   //  $real_pts[0] x-coordinate in real world terms of the user click
>   //  $real_pts[1] y-coordinate in real world terms of the user click
>   //
>   //NOTE that this function is set up to query only ONE layer, and return
>   // the first HIT from a query... so it wouldn't handle multiple layers
>   // or return results from numerous objects, although it could easily be
>   // modified to do both.
> 
>   $click_pt = ms_newPointObj();
>   $click_pt->setXY($real_pts[0], $real_pts[1]);
> 
>   @$map->queryByPoint($click_pt, MS_SINGLE, -1);
>   $Layer = $map->GetLayerByName("DePere_Parcels");
>   $count_results = $Layer->getNumResults();
> 
>   if ($count_results > 0) {
>     $Layer->open($map->shapepath);
>     $selFields = explode(" ", $Layer->getMetaData("RESULT_FIELDS"));
> 
>     //Take the first record returned, you could modify this to
>     // loop through a bunch of returned records
>     $oRes = $Layer->getResult(0);
>     $oShape = $Layer->getShape($oRes->tileindex,$oRes->shapeindex);
>     //Save the bounding box to an array
>     $aResBoundBox = array($oShape->bounds->minx, $oShape->bounds->miny,
>                     $oShape->bounds->maxx, $oShape->bounds->maxy);
> 
>     //Retrieve the PIN into a variable
>     $PIN = $oShape->values[PARCEL_NUM];
>     $prcAREA = $oShape->values[AREA];
>     $oShape->free();
> 
>     $query_result = array($PIN, $prcAREA);
>     $return $query_result;
> }

-- 

THOMAS HAECHLER

Geographic Information Systems Division
Institute of Geography
University of Zurich
Switzerland

thomas.haechler at geo.unizh.ch



More information about the mapserver-users mailing list