[Mapserver-users] mapscript - queryByPoint help, simple Q
Lowther, David W
dlowther at ou.edu
Thu Aug 28 08:43:50 PDT 2003
Seems like I came across something in the archive a while back that said
querybypoint doesn't work on layers... I am using it on the map object -
heres a snip... Most of this code came from somewhere else - if I could
remember where I would cite ref, but... Obviously you'd have to work around
the getMetaData / selFields stuff... But maybe this will help.
$map_path = "e:\map.map";
$gpoMap = ms_newMapObj($map_path);
$oClickGeo->setXY($minx,$miny);
// Use '@' to avoid warning if query found nothing
$oLayer = $gpoMap->GetLayerByName("huc8");
$oLayer->set("status",MS_ON);
$oLayer = $gpoMap->GetLayerByName("quad100");
$oLayer->set("status",MS_ON);
$oLayer = $gpoMap->GetLayerByName("tr_line");
$oLayer->set("status",MS_ON);
$oLayer = $gpoMap->GetLayerByName("sections");
$oLayer->set("status",MS_ON);
$oLayer = $gpoMap->GetLayerByName("county");
$oLayer->set("status",MS_ON);
@$gpoMap->queryByPoint($oClickGeo, MS_MULTIPLE, 20);
for($iLayer=0; $iLayer < $gpoMap->numlayers; $iLayer++)
{
$oLayer = $gpoMap->GetLayer($iLayer);
$numResults = $oLayer->getNumResults();
if ($numResults == 0)
continue; // No results in this layer
$oLayer->open();
$selFields = explode(" ", $oLayer->getMetaData("RESULT_FIELDS"));
for ($iRes=0; $iRes < $numResults; $iRes++)
{
$oRes = $oLayer->getResult($iRes);
$oShape = $oLayer->getShape($oRes->tileindex,$oRes->shapeindex);
for($iField=0; $iField < sizeof($selFields); $iField++)
{
print "<input type=hidden
name=".$selFields[$iField]."
value=\"".$oShape->values[$selFields[$iField]]."\">\n";
}
$oShape->free();
$numResultsTotal++;
}
$oLayer->close();
}
David Lowther
Software Engineer
GEO Information Systems
University of Oklahoma
dlowther at ou.edu
(405) 325-3131
http://www.geo.ou.edu
> -----Original Message-----
> From: poff [mailto:poff at sixbit.org]
> Sent: Thursday, August 28, 2003 9:51 AM
> To: Mapserver List
> Cc: jose.quintal at cfe.gob.mx
> Subject: Re: [Mapserver-users] mapscript - queryByPoint help, simple Q
>
>
> Thank you for your help - I tried to translate to
> phpmapscript and came up
> with:
>
> $shp=ms_newShapeObj(MS_SHAPE_POINT);
>
> ... loop through points
>
> $oPoint=...
>
> $line=ms_newLineObj();
> $line->add($oPoint);
> $shp->add($line);
> $shp->index = $i;
> $i++;
> ...
>
> $uLayer->addFeature($shp);
>
> $my_point = ms_newpointObj();
> $my_point->setXY($_REQUEST["mapa_x"],$_REQUEST["mapa_y"]);
>
> $result=$uLayer->queryByPoint ($my_point,MS_SINGLE,-10);
>
> But alas still "No Results"
>
> Is there anything wrong with the above? I have the Dummy
> TEMPLATE in the
> map file.
>
> I just found:
>
> http://lists.gis.umn.edu/pipermail/mapserver-users/2003-April/
> 003470.html
>
> Who seems to have (had) exactly the same problem as I.
>
> Any ideas?
>
> Thanks again!
>
> P
>
> ps. I put the shpObj and addfeature inside the loop with no change in
> results.
>
>
> On Thu, Aug 28, 2003 at 10:02:06AM +0000, Eric Bridger wrote:
> > For such a layer you need to add the points as features in
> order for
> > them to be queryable (as well as having the dummy TEMPLATE).
> >
> > So for each point you can't just do $point->draw($map,
> $layer, $img,
> > undef, $text) you also need to do: $layer->addFeature($shp). Since
> > addFeature requires a shape object you need to create the shape:
> >
> > my $line = new mapscript::lineObj();
> > $line->add($point);
> > my $shp = new mapscript::shapeObj($mapscript::MS_SHAPE_POINT);
> > $shp->add($line);
> > $shp->setBounds();
> > $shp->{index} = $point_number;
> >
> > Sorry these examples are in perl. One neat thing, the
> $shp->{index}
> > value can be any number, so if you have a numeric database
> key you can
> > use that and queryByPoint() results will return the key. I
> you don't
> > have that you'll need to create a lookup array which maps each
> > database key value with the point number in the layer.
> >
> > You need to draw the layer before queryByPoint can be called.
> >
> > What I have been doing for dynamic point layers is to call both
> > point->draw() and layer->addFeature() but not
> layer->draw(). With the
> > point->draw() I can control the color, size, text, etc. of
> each point
> > using the layers class. The addFeature() makes the layer queryable
> > w/o a shapefile.
> >
> >
> > There is a perl example here:
> >
> http://mapserver.gis.umn.edu/cgi-bin/wiki.pl?PerlMapScriptExamples35ex
> > 14
> >
> > Eric
> >
> > On Thu, 2003-08-28 at 13:06, poff wrote:
> > > > Do you have a template defined for the layer?
> > >
> > > No, sounds like I should!
> > >
> > > I have never used templates before, but in the query
> layer, and the
> > > point
> > > class I added:
> > >
> > > TEMPLATE "dummy"
> > >
> > > And instead of No Records I get:
> > >
> > > Warning: MapServer Error in msOpenSHPFile(): No (NULL) filename
> > > provided
> > >
> > > So it seems like progress!
> > >
> > > $result=$uLayer->queryByPoint ($my_point,MS_SINGLE,-10);
> > >
> > > Generates this error, but I didn't think I'd need a SHP file or
> > > anything.
> > >
> > > Any ideas how to proceed?
> > >
> > > Thanks very much!
> > >
> > > P
> > >
> > > > Lowell
> > > >
> > > > The following message was sent by poff
> <poff at sixbit.org> on Thu,
> > > > 28 Aug 2003 09:54:37 +0200.
> > > >
> > > > > Hello again,
> > > > >
> > > > > I'm having problems getting any results with queryByPoint.
> > > > >
> > > > > Basically I draw my map as usual then I try the
> following on the drawn
> > > > > layer:
> > > > >
> > > > > $my_point = ms_newpointObj();
> > > > >
> > > > >
> > > > > $my_point->setXY($_REQUEST["mapa_x"],$_REQUEST["mapa_y"]);
> > > > >
> > > > > $result=$uLayer->queryByPoint
> ($my_point,MS_SINGLE,-20);
> > > > >
> > > > > I tried different buffers, zooming in etc. but I
> always get: "No
> > > > > matching
> > > > > Record(s) found"
> > > > >
> > > > > The layer is drawn OK, and is simple as far as the
> mapfile goes
> > > > > (nothing
> > > > > apart from):
> > > > >
> > > > > ...
> > > > > STATUS ON
> > > > > TYPE POINT
> > > > > LABELCACHE FALSE
> > > > >
> > > > > CLASS
> > > > > SYMBOL
> > > > > END
> > > > >
> > > > > END
> > > > > ...
> > > > >
> > > > > The points are drawn in from a database, so if I
> could convert
> > > > > the
> > > > > $_REQUEST clicks into lat/lon I could just query the
> database instead of
> > > > > mapserver.
> > > > >
> > > > > Has anyone got any light to shed on this? I'd be most
> grateful
> > > > > if someone
> > > > > could show me what I'm doing wrong, or suggest how to
> get the lat/long
> > > > > values. The archives didn't seem to have anyone in my
> situation - which
> > > > > suggested to me I'm missing something basic out.
> > > > >
> > > > > Thanks in advance,
> > > > >
> > > > > --
> > > > > poff at sixbit.org
> > > > > SDF Public Access UNIX System - http://sdf.lonestar.org
> > > > >
> > > > > Please do not carbon copy replies to me
> > > > > _______________________________________________
> > > > > Mapserver-users mailing list Mapserver-users at lists.gis.umn.edu
> > > > > http://lists.gis.umn.edu/mailman/listinfo/mapserver-users
> > > >
> > > > _______________________________________________
> > > > Mapserver-users mailing list Mapserver-users at lists.gis.umn.edu
> > > > http://lists.gis.umn.edu/mailman/listinfo/mapserver-users
> > >
> > > --
> > > poff at sixbit.org
> > > SDF Public Access UNIX System - http://sdf.lonestar.org
> > >
> > > Please do not carbon copy replies to me
> > > _______________________________________________
> > > Mapserver-users mailing list Mapserver-users at lists.gis.umn.edu
> > > http://lists.gis.umn.edu/mailman/listinfo/mapserver-users
> > >
> >
> >
> > _______________________________________________
> > Mapserver-users mailing list
> > Mapserver-users at lists.gis.umn.edu
> > http://lists.gis.umn.edu/mailman/listinfo/mapserver-users
>
> --
> poff at sixbit.org
> SDF Public Access UNIX System - http://sdf.lonestar.org
>
> Please do not carbon copy replies to me
> _______________________________________________
> Mapserver-users mailing list
> Mapserver-users at lists.gis.umn.edu
> http://lists.gis.umn.edu/mailman/listinfo/mapserver-users
>
>
More information about the MapServer-users
mailing list