[Mapserver-users] RE: need some help with queryByPoint()
Charlton Purvis
cpurvis at asg.sc.edu
Wed Jul 23 09:17:47 PDT 2003
Hi, Bhavana:
I'll assume that you're using MS 3.7.
First off, queryByPoint only returns an int. See the mapscript
documentation: "Returns MS_SUCCESS if shapes were found or MS_FAILURE
if nothing was found or if some other error happened (note that the
error message in case nothing was found can be avoided in PHP using the
'@' control operator)."
But having it return a 1 does imply MS_FAILURE.
But it looks like you're querying by the mouse click. You need to
translate that in to georeferenced coordinates. Something like:
function pixelToGeo($map,$x,$y) {
# Convert x,y pixel values to georeferenced coords. Returns a
# pointObj.
$minx = $map->extent->minx;
$miny = $map->extent->miny;
$maxx = $map->extent->maxx;
$maxy = $map->extent->maxy;
$dx = $maxx - $minx;
$dy = $maxy - $miny;
$width = $map->width;
$height = $map->height;
$dxpp = (double)$dx/$width;
$dypp = (double)$dy/$height;
$geox = $minx + $dxpp*$x;
$geoy = $maxy - $dypp*$y;
$pointObj = ms_newPointObj();
$pointObj->setXY($geox,$geoy);
return $pointObj;
}
Then you're ready for something like:
$my_point->setXY($HTTP_POST_VARS["mapa_x"],$HTTP_POST_VARS["mapa_y"]);
$geo_point = pixelToGeo($map,$my_point->x,$my_point->y);
if(isset($geo_point)) {
@$layerObj->queryByPoint($geo_point,MS_MULTIPLE,0.10);
}
else {
@$layerObj->queryByRect($map->extent);
};
Let me know if that helps.
Charlton
-----Original Message-----
From: Bhavana Rakesh [mailto:Bhavana.Rakesh at noaa.gov]
Sent: Wednesday, July 23, 2003 11:00 AM
To: Charlton Purvis
Subject: need some help with queryByPoint()
Hi Charloton,
I got your email from the mapscript question archives. I hope I'm not
imposing by sending you this email. I have all the data stored in the
dbf file, but when I run the queryByPoint no results are being
returned.
Any pointers will help. I have attached the code and the error message
that
i'm getting when i try to use the queryByPoint function. Please do
reply at your earliest conveniece if you know the answer.
function query_map($map, $global_layer){
$layer = $map->getLayer($global_layer);
$layer->set("status",MS_ON);
printf("x,y co-ords are ". $_POST['mapa_x']."
".$_POST['mapa_y']);
$m_point = ms_newpointObj();
$m_point->setXY($_POST['mapa_x'],$_POST['mapa_y']);
$queryresult = $map->queryByPoint($m_point,MS_MULTIPLE,-1);
print("queryresult ". $queryresult);
}
The $queryresult prints out a 1.
The error message from the php log files :-
PHP Warning: MapServer Error in msQueryByPoint(): No matching record(s)
found.
Would you know where I'm going wrong. Any pointers will help.
Regards - Bhavana
More information about the MapServer-users
mailing list