[Mapserver-users] RE: need some help with queryByPoint()

Charlton Purvis cpurvis at asg.sc.edu
Thu Jul 24 16:29:18 EDT 2003


Hi, Bhavana:

cc. the list since there are plenty of people smarter than I that might
be able to nail it on the first shot.

But here goes.  I can't remember much about legends off the top of my
head.  I got down and dirty w/ them before, and now it's all automated.
So here are a couple of guesses:

* In your .map, does your LEGEND have a TEMPLATE associated w/ it?
* If processquerytemplate is supposed to return a path (don't remember),
is it creating that .png, i.e. is there a
/home/http/development/html/bhavana/test_bh/tmp/SNMAPPING1058992693.png
and does it look right if you open it by hand?  If you are passing the
path to the image and not the image itself, it needs to be relative to
your website.  If your path is truly what you said above, then your
browser would be trying to display the equivalent of
http://your.server.com/home/http/development/html/bhavana/test_bh/tmp/SN
MAPPING1058992693.png.  And I'm not 100% sure you mean for it to do
that.

Charlton

-----Original Message-----
From: Bhavana Rakesh [mailto:Bhavana.Rakesh at noaa.gov] 
Sent: Thursday, July 24, 2003 10:01 AM
To: Charlton Purvis
Subject: Re: need some help with queryByPoint()

Hi Charlton,
Thanks a lot for your quick reply.  Converting my mouse click to
geo-referenced co-ordinates, and using the '@' to runt he map functions
did
the trick.  The code now is :

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']);
        $m_point_geo = pixelToGeo($map, $m_point->x, $m_point->y);
        $queryresult =
@$map->queryByPoint($m_point_geo,MS_MULTIPLE,0.00000001);
        print "<BR>" .  "<BR>";
        $queryimg = $map->drawquery();
        $query_url = $queryimg->saveWebImage(MS_PNG,0,0,0);
        $queryarray['IMG'] = $query_url;
        $template = $map->processquerytemplate($queryarray);
        echo "<hr>";
        echo $template;
        echo "<hr>";
}

But the problem that I'm having now is, when I slap the $template on my
html
page, it's supposed to find an image and insert it into the html page,
and
can't find it.  I have attached a screen shot of page that I'm trying to
create.  The little box(with the missing image) on the left hand side of
the
screen, just below the "Queried Layer: Model and Probability data", is
supposed to have an zoomed in image of the chesapeak bay(left hand side
of
the screen) where the mouse was clicked.  It is supposed to be writing
out
the image to a file called SNMAPPING1058992693.png, but can't find the
image.
Php error message :-
[error] [client 140.90.196.252] File does not exist:
/home/http/development/html/bhavana/test_bh/tmp/SNMAPPING1058992693.png
PS: I am using MS 3.6.

Would you know what's going wrong or what I'm missing.  I'm new to map
server and mapscript.  So if my questions sound too silly or trivial,
please
over look the fact.   I really appreciate all the help that you've given
so
far.
Regards - Bhavana


Charlton Purvis wrote:

> 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
>





More information about the mapserver-users mailing list