[mapserver-users] How do you get shape attributes from a query result object (also a working code snippet for queryusingpoint ) ?

Steven Hayes shayes at bigpond.net.au
Mon Dec 31 23:49:48 EST 2001


Thanks to all on the list for you patience in watching and sometimes helping
me semi publicly work out how to use mapscript. Hopefully the subject line
of this email will be indexed by the search engines and the code snippet
(for Mapserv 3.3.011)  at the end of this email might help new mapscript
users in future. What it will now do - after many hours of trying - is
return the shape index corresponding to a map click. In my final
application, you can zoom in and out and pan but wherever you click you also
end up with the relevant shape index.

What I would like to know is if there is a simple way for me to query the
shapefile for an attribute associated with this shapeindex ?

######################################################
# mapscript code snippet to return a shape index from a map click
######################################################

die $mapscript::ms_error->{message} unless $map = new
mapObj("/www/hosted/streamwatch/cgi-bin/streamwatch_adv.map");

&set_extent();
# set extent subroutine taken verbatim from Stephen Limes quakes.pl -
# you need this amongs other things to translate image coordinates into
mapcoordinates

my $img = $map->prepareImage();

my $layer = $map->getLayerByName('regall');
$layer->draw($map, $img);

my $point = new pointObj();
$point->{x}   = $my_x_coord;
$point->{y}   = $my_y_coord;

$qryResult = $map->queryUsingPoint($point, MS_SINGLE, -1);
$shpResult = $qryResult->next();

my $ndx = $shpResult->{shape};

# $ndx will return the shape index corresponding to a map click on my regall
layer

###################################################

Regards

Steven Hayes




More information about the mapserver-users mailing list