[mapserver-users] PHP MapScript - Trouble with Point Query

Daniel Morissette morissette at dmsolutions.ca
Wed Jul 4 17:34:15 PDT 2001


Chip,

If a query fails (i.e. nothing found), the returned value is FALSE (or
0, not sure), but either way you should be able to test the return value
to find out if you actually got a result or not by changing your code
to:

    $q_map_res = $map->queryUsingPoint($real_pts[2], MS_SINGLE, -1);

    if ($q_map_res)
    {
      $q_map_res->rewind();
      $oResult = $q_map_res->next();
      $iCurLayer = $oResult->layer;
      $oLayer = $map->GetLayer($iCurLayer);
      $dbfname = $map->shapepath . $oLayer->data . ".dbf";

      ...

    }
    else
    {
       // Nothing found...
    }


Best Regards,
-- 
------------------------------------------------------------
 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.


"Hankley, Chip" wrote:
> 
> Hi List,
> 
> Totally stumped...
> 
> I'm having trouble with a point query and a shapefile.
> 
> What I'm trying to do is set up an app that will let users point at a
> polygon, and have an attribute from that polygon be returned. The attribute
> (field value) that is returned will always be the same (i.e. I'm not
> returning values from multiple fields...just one).
> 
> Anyway, I followed the way this is done in DMSolutions GMap application, and
> it works...most of the time. But, on certain shapefiles, for certain
> polygons, I get the following PHP error:
> 
> Fatal error: Call to a member function on a non-object in
> C:\Inetpub\wwwroot/seating/test_seat1.php on line 49
> 
> Doesn't happen for every polygon in an effected shapefile, but it does
> happen to the same polygons consistently.
> 
> Here's my php code around line 49:
> 
> 44    $x_click = $HTTP_POST_VARS["img_x"];
> 45    $y_click = $HTTP_POST_VARS["img_y"];
> 46    $real_pts = getRealPts($x_click, $y_click, $map);
> 47
> 48    $q_map_res = $map->queryUsingPoint($real_pts[2], MS_SINGLE, -1);
> 49    $q_map_res->rewind();
> 50
> 51    $oResult = $q_map_res->next();
> 52    $iCurLayer = $oResult->layer;
> 53    $oLayer = $map->GetLayer($iCurLayer);
> 54    $dbfname = $map->shapepath . $oLayer->data . ".dbf";
> 
> I think it's really bombing on line 48 b/c if I comment out 49, my error
> says line51. I think I must be missing some error trapping routine around
> line 48, although I don't understand why it isn't returning a value.
> 
> For further ref, here's the layer definition from the map file...
> 
> LAYER
>   NAME "Employee"
>   DESCRIPTION "Location Codes"
>   TYPE Polygon
>   STATUS DEFAULT
>   DATA ml4
>     CLASSITEM CODE
>       CLASS
>         EXPRESSION ''
>         COLOR 255 0 0
>         OUTLINECOLOR 0 0 0
>      END  # CLASS
>   TOLERANCE 0
>   HEADER "CODE"
>   QUERYITEM "Code"
>   QUERY
>     EXPRESSION /1|2|3/
>     TEMPLATE "ttt"
>   END
> END  # LAYER
> 
> TIA!
> 
> Chip



More information about the MapServer-users mailing list