queryByPoint() on a dynamic layer

Eric Bridger eric at GOMOOS.ORG
Wed Jan 25 09:08:00 EST 2006


Mark,
You will need to set a value for the 'index' property of your shape
object before calling addFeature($shape).

Not sure how to do this is PHP mapscript but in Perl:
$shape->{index} = $point_id;

Then the point_id should be returned by your query.

Eric


On Fri, 2006-01-20 at 20:18, Mark Brooks wrote:
> I'm trying to queryByPoint on a dynamic point layer.  The points in the 
> layer are added from a mysql database.  When I queryByPoint on this 
> dynamic layer, the resulting shapeindex and tileindex are both -1, which 
> is not what is expected.
> 
> Here is how I ADD the points to the layer:
> $query = mysql_query(" mysql query...  ");
> while ($site = mysql_fetch_assoc($query)){
>     // this draws the dynamic point
>     $mypoint = ms_newPointObj()
>     $mypoint -> setXY($site['lon'],$site['lat']);
>     $mypoint->draw($map,$layer,$image,0,'name');
> 
>     // this adds the feature to the layer so that it
>     // can be queried.  No results are found from a query
>     // by only drawing it above.
>     // Probably not the most efficient and perhaps
>     // where I'm going wrong?
>     $mypoint_shape = ms_newShapeObj(MS_SHAPE_POINT);
>     $mypoint_line = ms_newLineObj();
>     $mypoint_line->add($mypoint);
>     $mypoint_shape->add($mypoint_line);
>     $stations_layer->addFeature($mypoint_shape);
> }
> 
> 
> Then later in my php script, this is how I query:
> // get coordinates to query
> $myclick = ms_newPointObj();
> $myclick -> setXY($geo_lon,$geo_lat);  // set the click point
> 
> // do the query
> $layer -> queryByPoint($myclick,MS_MULTIPLE,100);
> for ($i=0; $i<$layer->getNumResults(); $i++){
>     $result = $layer->getResult($i);
>     // output below shows 'shapeindex' and 'tileindex' are both -1
>     print_r($result);
> }
> 
> 
> What am I doing wrong?  If I queryByPoint on any static layer, tileindex 
> and shapeindex are good values.  But on this dynamic layer, they are 
> always -1.  Any ideas?
> 
> 
> -- 
> 
>    Mark Brooks
>    Environmental Meteorologist
>    State Climate Office of North Carolina
>    Box 7236, NC State University
>    Raleigh, NC 27695-7236
> 
>    E-mail:  mark_brooks at ncsu.edu
>    Phone:  919.515.1446
>    Fax:  919.515.1441



More information about the mapserver-users mailing list