[Mapserver-users] mapscript - queryByPoint help, simple Q

Eric Bridger eric at gomoos.org
Thu Aug 28 06:02:06 EDT 2003


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

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
> 





More information about the mapserver-users mailing list