[mapserver-users] How do you get shape attributes from a query result object (also a working code snippet for queryusingpoint ) ?
Lowell Filak
lfilak at yahoo.com
Wed Jan 2 11:01:03 PST 2002
The shape index value is actually the record number of
the attribute information in the DBF file associated
with the SHP file. You can use the DBD::XBase module
from CPAN to access the DBF file directly from Perl.
Check 'man DBD::XBase' for the syntax to use, but it's
pretty typical:
...
use XBase;
...
$dbf =
DBI->connect("dbi:XBase:DIRECTORY_WHERE_DBF_FILES_ARE");
$stf = $dbf->prepare ...
Hope that helps.
Lowell Filak
--- Steven Hayes <shayes at bigpond.net.au> wrote:
> 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
>
__________________________________________________
Do You Yahoo!?
Send your FREE holiday greetings online!
http://greetings.yahoo.com
More information about the MapServer-users
mailing list