[mapserver-users] queryUsingPoint

Daniel Morissette morissette at dmsolutions.ca
Thu Jul 26 11:06:40 EDT 2001


"Vinko Vrsalovic B." wrote:
> 
> Well, it wasn't the last message of the night. :)
> 
>         Browsing to php_mapscript.c dated 2001/07/23 I can't seem
> to find queryUsingPoint, only queryByPoint.
> 
>         Will queryUsingPoint disappear?
> 

Yes, queryUsingPoint() is gone... well actually it was renamed to
queryByPoint() because of the way queries work (the return value in this
case) changed in 3.5 and renaming the call is the only way to make sure
users update their scripts... otherwise scripts would just silently
fail.

>         Does queryByPoint return an int? (doc bug?)
> 

No... this time it's not a doc bug... the new queryByPoint() returns
MS_SUCCESS or MS_FAILURE, and the query results are accessable via the
layerObj's getResult() method.

However there's a bug in the LayerObj docs: the queryUsingPoint() and
family are still listed but they should be gone... I'll have this fixed.

> And my last problem:
> 
>         When I load a map with this layer:
> 
> LAYER
>     NAME rbusproj
>     TYPE LINE
>     STATUS OFF
>     DATA rbusproj
>     QUERY
>         TEMPLATE "q1.html"
>     END
>     CLASS
>         COLOR 100 150 54
>     END
> END
> 
> Warning: MapServer Error in loadLayer(): (QUERY):(66) in /file/path line 4
> 
> Fatal error: Failed to open map file ../mymap.map in /file/path on line 4

The QUERY object is gone in 3.5 and its parameters moved into the CLASS
object... you have to move your TEMPLATE parameter inside the CLASS
object when going from 3.4 to 3.5.


Finally, I attached below portions of code extracted from gmap75.php3
(for MapServer 3.5) that shows how to deal with the new query functions.

The whole Gmap distribution for MapServer 3.5 can be downloaded at
http://www2.dmsolutions.ca/mapserver/dl/gmap-ms35-20010726.tar.gz
or
http://www2.dmsolutions.ca/mapserver/dl/gmap-ms35-20010726.zip

(I added this file in our download page this morning... I thought it had
been there for quite a while but it was not... so I apologize to those
of you that I pointed to "the gmap demo for ms 3.5 on our download site"
since this file didn't exist until today.)
-- 
------------------------------------------------------------
 Daniel Morissette               morissette at dmsolutions.ca
 DM Solutions Group              http://www.dmsolutions.ca/
------------------------------------------------------------
  Don't put for tomorrow what you can do today, because if 
      you enjoy it today you can do it again tomorrow.



// This code performs a point query given georeferenced coodrinates:
// GMapDumpQueryResults() will be called later on to display
// a table with the results if something was found.

       $oClickGeo = ms_newPointObj();
       $oClickGeo->setXY($nClickGeoX, $nClickGeoY);

       // Use '@' to avoid warning if query found nothing
       @$gpoMap->queryByPoint($oClickGeo, MS_SINGLE, -1);

       $gbShowQueryResults = TRUE;

//...
//...


/************************************************************************/
/*                     function GMapDumpQueryResults()                  */
/*                                                                      */
/*      Produce a table with query results.                             */
/*      Simply prints an " " if there are no query results.        */
/************************************************************************/
function GMapDumpQueryResults()
{
    GLOBAL $gpoMap, $gbShowQueryResults;

    if (! $gbShowQueryResults )
    {
        printf(" ");
        return;
    }

    $numResultsTotal = 0;

    for($iLayer=0; $iLayer < $gpoMap->numlayers; $iLayer++)
    {
        $oLayer = $gpoMap->GetLayer($iLayer);

        $numResults = $oLayer->getNumResults();

        if ($numResults == 0)
            continue;  // No results in this layer

        // Open layer's table... take the list of fields to display from 
        // the "HEADERRESULT_FIELDS" metadata in the layer object.
        $oLayer->open($gpoMap->shapepath);

        $selFields = explode(" ", $oLayer->getMetaData("RESULT_FIELDS"));
            
        printf("<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=2 WIDTH=100%%>\n");
        printf("<TR>\n");
        printf("<TD COLSPAN=%d BGCOLOR=#C1D8E3>", sizeof($selFields));
        printf("<CENTER> %s </CENTER>", $oLayer->getMetaData("DESCRIPTION"));
        printf("</TR>\n");
            
        //
        // Table header: attribute names...
        //
        printf("<TR>\n");
        for ($iField=0; $iField < sizeof($selFields); $iField++)
        {
            printf("<TD BGCOLOR=#E2EFF5>");
            printf("%s",$selFields[$iField]);
            printf("</TD>");
        }
        printf("</TR>\n");

        //
        // One row in table for each selected record
        //

        for ($iRes=0; $iRes < $numResults; $iRes++)
        {
            $oRes = $oLayer->getResult($iRes);

            $oShape = $oLayer->getShape($oRes->tileindex,$oRes->shapeindex);

            printf("<TR>\n");

            printf("<!-- bounds(%f, %f)-(%f, %f)-->\n", 
                   $oShape->bounds->minx, $oShape->bounds->miny,
                   $oShape->bounds->maxx, $oShape->bounds->maxy);
            
            for($iField=0; $iField < sizeof($selFields); $iField++)
            {
                printf("<TD BGCOLOR=#FFFFFF>");
                printf("%s", $oShape->values[$selFields[$iField]]);
                printf("</TD>");
            }
            printf("</TR>\n");

            $oShape->free();

            $numResultsTotal++;
        }

        $oLayer->close();

        printf("</TABLE>\n");
    }

    if ($numResultsTotal == 0)
        echo "Nothing found at query location.";

}




More information about the mapserver-users mailing list