[mapserver-users] Questions about PHP Mapscript and Queries

LaFone, Frank flafone at GEO.WVU.edu
Tue Jul 30 10:55:14 EDT 2002


Thanks for your help - I do appreciate it.

I tried your ideas and it still doesn't seem to work.  I verified in ArcView
3.2 the points on which I'm clicking and they're right in the middle of the
polygon.  I tried your function (modified to use my variable names), but
it's still telling me no results were found.  Here's my code:

$map->setextent($extent_to_set[0],$extent_to_set[1],$extent_to_set[2],$exten
t_to_set[3]);
$my_point = ms_newpointObj();
$tmpx = $HTTP_GET_VARS["themap_x"];
$tmpy = $HTTP_GET_VARS["themap_y"];
$my_point->setXY($tmpx,$tmpy);
$xmin = $map->extent->minx;
$ymin = $map->extent->miny;
$xmax = $map->extent->maxx;
$ymax = $map->extent->maxy;

$x = (($my_point->x / $map->width) * ($xmax - $xmin)) + $xmin;
$y = $ymax - (($my_point->x / $map->height) * ($ymax - $ymin));
$clickpt = ms_newPointObj();
$clickpt->setXY($x, $y);
print "<h1>xmin = $xmin<br>xmax = $xmax<br>ymin = $ymin<br>ymax =
$ymax<br>my_point->x = $my_point->x<br>my_point->y = $my_point->y<br>x =
$x<br>y = $y<br>clickpt->x = $clickpt->x<br>clickpt->y = $clickpt->y</h1>";
$temp = $map->queryByPoint($clickpt, MS_MULTIPLE, -1);


Here's the error message I'm getting in return:

Warning: MapServer Error in msQueryByPoint(): No matching record(s) found.
in c:\website\html\mapserver\test\test.php on line 224


Anyone got any ideas on what I'm doing wrong?  I know there's a polygon at
the point on which I'm searching.  It's contained in a layer called "WVU
Buildings".  What I'm ACTUALLY looking for is the name of the building on
which they click.  I'll then take that name and do a search on a seperate
database to pull up a bunch of information about the building and display it
in a seperate area apart from the map.


-----Original Message-----
From: Hankley, Chip [mailto:Chip.Hankley at GASAI.Com]
Sent: Monday, July 29, 2002 4:52 PM
To: MapServer List (E-mail)
Subject: RE: [mapserver-users] Questions about PHP Mapscript and Queries


Frank -

First off, the gMap demo (I assume that's where you got that) is a great
place to start w/ PHP Mapscript. I would try to verify that you are giving
it the right coordinates. Somehow passing 0 in doesn't seem right to me. It
just doesn't make much sense... but I don't use that function so I don't
know. Anyway, a quick way to figure out if that's the problem is to use
another program (arcview, mapinfo, grass, whatever) to look at what the
coordinates are of the point you are clicking on, then see what the function
is returning for comparison.

I do my conversion a little differently... the code looks a little hairy by
comparison. Probably could be re-written to look a lot nicer. Reflects the
genesis of my learning. End of disclaimers.


  //$Last_Extent: an array (x_min, y_min, x_max, y_max) of 
  //              geographic coordinates that was collected 
  //              into form variables at the last submit. This 
  //              way I am sure that I have the geographic 
  //              coordinates that bound the image *that the user 
  //              clicked on* not an image that was generated later.
  //
  //$ll_coord:    an array (x, y) of pixel coordinates on the image.
  //
  //$map:         the map object

  $ImgWidth = $map->width;
  $ImgHeight = $map->height;
  $x = (($ll_coord[0] / $ImgWidth) * ($Last_Extent[2] - $Last_Extent[0])) +
$Last_Extent[0];
  $y = $Last_Extent[3] - (($ll_coord[1] / $ImgHeight) * ($Last_Extent[3] -
$Last_Extent[1]));

  $click_pt = ms_newPointObj();
  $click_pt->setXY($x, $y);

... you can probably take it from there. You can use the click_pt object
that is created in the query.

FWIW, I found it a very useful learning excercise to kind of re-write what
these various gMap functions were doing in my own (albeit maybe not as
elegant) style.

HTH...

Chip

-----Original Message-----
From: LaFone, Frank [mailto:flafone at GEO.WVU.edu]
Sent: Monday, July 29, 2002 3:24 PM
To: Hankley, Chip; mapserver-users at lists.gis.umn.edu
Subject: RE: [mapserver-users] Questions about PHP Mapscript and Queries


The function is one I took from the DM Solutions Group advanced example.  I
just renamed it.  I haven't verified the function, but I sorta assumed
(yeah, I know what happens to you and me) it worked properly.

function Pix2Geo($nPixPos, $dfPixMin, $dfPixMax, $dfGeoMin, $dfGeoMax,
$nInversePix){
    
    $dfWidthGeo = $dfGeoMax - $dfGeoMin;
    $dfWidthPix = $dfPixMax - $dfPixMin;
   
    
    $dfPixToGeo = $dfWidthGeo / $dfWidthPix;

    if (!$nInversePix)
        $dfDeltaPix = $nPixPos - $dfPixMin;
    else
        $dfDeltaPix = $dfPixMax - $nPixPos;

    $dfDeltaGeo = $dfDeltaPix * $dfPixToGeo;


    $dfPosGeo = $dfGeoMin + $dfDeltaGeo;

    return ($dfPosGeo);
}


-----Original Message-----
From: Hankley, Chip [mailto:Chip.Hankley at GASAI.Com]
Sent: Monday, July 29, 2002 4:21 PM
To: 'LaFone, Frank'
Subject: RE: [mapserver-users] Questions about PHP Mapscript and Queries


Frank - 

My initial hunch on both of your problems is that your 'Pix2Geo' function
has got some kind of problem with it and isn't returning a valid
coordinate... or at least isn't returning the *correct* coordinate. Have you
checked this? This would certainly explain why your code would be executing
w/out errors, but not giving you the results you expect.

You might want to forward your function back to the list for us to look at.

Chip



-----Original Message-----
From: LaFone, Frank [mailto:flafone at GEO.WVU.edu]
Sent: Monday, July 29, 2002 2:28 PM
To: mapserver-users at lists.gis.umn.edu
Subject: [mapserver-users] Questions about PHP Mapscript and Queries


Hi, I'm pretty new to Mapserver and PHP Mapscript (although I'm an old hand
at PHP).  I can't seem to get any of my queries to work correctly.  What I'm
trying to do is do a simple query on a point, but all I get back is an error
message that says "No records found".  Here's my snipet of code:

            $XGeoMin = $map->extent->minx;
            $XGeoMax = $map->extent->maxx;
            $geox = Pix2Geo($my_point->x, 0, 500, $XGeoMin, $XGeoMax, 0);

            $YGeoMin = $map->extent->miny;
            $YGeoMax = $map->extent->maxy;
            $geoy = Pix2Geo($my_point->y, 0, 500, $YGeoMin, $YGeoMax, 1);
            $clickpt = ms_newpointObj();
            $clickpt->setXY($geox,$geoy);
            $temp = $map->queryByPoint($clickpt, MS_MULTIPLE, -1);

On an vaguely related note, I'm also trying to draw a point on the middle of
a polygon on my map once a search has been done.  In otherwords, I have a
shape file that has a bunch of buildings on it.  If they click on the
building I want the application to do a search for the building on which
they clicked (the query part of my question).  However if they do a search
using my pull down menus with all the buildings listed by name, I want the
map to be updated to feature a red dot somewhere in the building polygon.
Here's my snipet of code of this:

            $XGeoMin = $map->extent->minx;
            $XGeoMax = $map->extent->maxx;
            $geox = Pix2Geo($my_point->x, 0, 500, $XGeoMin, $XGeoMax, 0);

            $YGeoMin = $map->extent->miny;
            $YGeoMax = $map->extent->maxy;
            $geoy = Pix2Geo($my_point->y, 0, 500, $YGeoMin, $YGeoMax, 1);
            $clickpt = ms_newpointObj();
            $clickpt->setXY($geox,$geoy);
            $layer = ms_newLayerObj($map);
            $layer = $map->getLayerByName("WVU Buildings");
            $temp = $clickpt->draw($map, $layer, $image, 0, "This is a test
string");
            $image = $map->draw();

            $image_url=$image->saveWebImage(MS_GIF,1,1,0);

I can get the image, but there's no point on the image and the "This is a
test string" label isn't anywhere on the map.

Any help anyone can give me on either of these two issues would be greatly
appreciated.

Thanks,

Frank LaFone
WV GIS Technical Center
West Virginia University



More information about the mapserver-users mailing list