[Mapserver-users] mapscript: queryByPoint() returns no results

Christoph Spoerri spoerri at duke.edu
Thu Jan 15 13:29:02 EST 2004


Thanks! Turning the layer ON did the job. I tried the TEMPLATE, pixel vs. map 
units, and a bunch of other things, but I forgot (or didn't know) that the 
layer has to be on in order to query it.

BTW. does anybody know why there has to be the TEMPLATE keyword in the 
layer/class? This make sense for the mapserver cgi, but not necessarly for 
the mapscripts. Also, I would think one should be able to query a later even 
when it's not visible.

Christoph

On Thursday 15 January 2004 12:47 pm, Eric Bridger wrote:
> I believe you need to add TEMPLATE "anything.html" in your LAYER or
> CLASS to make it queryable. May sure to turn the layer on.  Also your
> qryPt will need map coordinates not pixel values. You'll need to
> translate using something like: (in Perl):
>
>  @current_extent = split(' ', $q->param('imgext'));
>  my $click_x = $q->param('mapimg.x');
>  my $click_y = $q->param('mapimg.y');
>  my $x_pct = ($click_x / $map->{width});
>  my $y_pct = 1 - ($click_y / $map->{height});
>
>  $x_map = $current_extent[0] + ( ($current_extent[2] -
> $current_extent[0]) * $x_pct);
>  $y_map = $current_extent[1] + ( ($current_extent[3] -
> $current_extent[1]) * $y_pct);
>
>
> HTH.
> Eric
>
> On Thu, 2004-01-15 at 11:37, Christoph Spoerri wrote:
> > Hi there,
> >
> > I'm not sure what I'm doing wrong this time. I'm trying to query a
> > polygon layer with a point. Yet, for some reason I only receive a 'No
> > records found error', even if I click in the middle of the polygon!
> >
> > I'm using mapserver 4.0.1 with python scripts
> >
> > thanks for you help again,
> > Christoph
> >
> > Here's the code I'm using:
> >
> > 	lyrCoast = myMap.getLayerByName('Continents')
> > 	try:
> > 		qryPt = pointObj()
> > 		qryPt.x,qryPt.y = xStart,yStart # coords are in pixels
> > 		lyrCoast.queryByPoint(myMap.,qryPt,MS_MULTIPLE,0)
> > 		result = lyrCoast.getResult(0)
> > 		s = shapeObj(lyrCoast.type)
> > 		lyrCoast.open()
> > 		lyrCoast.getShape(s,result.tileindex,result.shapeindex)
> > 		...
> >
> >
> > Here's the layer in the map file:
> >
> > 	LAYER
> > 		NAME "Continents"
> > 		STATUS DEFAULT
> > 		TOLERANCE 5
> > 		TOLERANCEUNITS pixels
> > 		DATA "datalib/global/world_usa_canada"
> > 		TYPE POLYGON
> > 		TRANSPARENCY 0
> > 		CLASS
> > 			COLOR 180 210 170
> > 			OUTLINECOLOR 150 190 140
> > 		END
> > 	END
> >
> > _______________________________________________
> > 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