[Mapserver-users] Query of Point in multiple layers

Stephen Clark stephen.clark at focus.ca
Mon Aug 25 14:03:34 PDT 2003


Eric,

Which version of perl are you using?

my version is 5.6.1.

Stephen

----- Original Message -----
From: "Eric Bridger" <eric at gomoos.org>
To: "Stephen Clark" <stephen.clark at focus.ca>
Cc: "Mapserver List" <mapserver-users at lists.gis.umn.edu>
Sent: Monday, August 25, 2003 8:28 AM
Subject: Re: [Mapserver-users] Query of Point in multiple layers


> This is certainly possible using mapscript but you will need to query
> each layer individually and then save the results for each
> queryByPoint() on each polygon layer.
> The map file does allow you to put layers in a group using the GROUP
> tag, but I'm not sure if that would allow you to query all the layers at
> once.
>
> Remember, querying a shapefile layer only returns the record number of
> the attribute data in the shapefile dbf file.  So for each query, you
> need to open the DBF file and get the attributes you want.
>
> Below is some perl code which you should be able to adapt to PHP. Note:
> this is for mapserver 3.6.6 It gets the first attribute in the dbf file.
> --------------------------------------------------------------------------
------
> use mapscript:
> use XBase;
>
> my @layers = ('states', 'counties', 'civil_divisions');
> my @results = ();
> foreach my $layer (@layers){
>    my @tmp = queryLayer($layer, $map, $click_pt, 1);
>    push @results, @tmp;
> }
> #########################################
> # Run queryByPoint on a layer and lookup the $fld number in the XBase
> dbf file.
> #########################################
> sub queryLayer{
>     my($layer, $map, $point, $fld) = @_;
>     my @results = ();
>
>     my $layerObj = $map->getLayerByName($layer);
>     $layerObj->{status} = $mapscript::MS_ON;
>     if(!$layerObj->queryByPoint($map,$point,$mapscript::MS_MULTIPLE,
> undef)){
>         # Open the db handle.
>         my $dbfile = $layerObj->{data};
>         $dbfile .= '.dbf';
>         my $hDBF = new XBase "$dbfile" or warn XBase->errstr . "\n";
>         my $results = $layerObj->{resultcache};
>         my $num_results = $results->{numresults};
>         for my $i (0..$num_results-1){
>             my $rslt = $layerObj->getResult($i);
>             # record is the record number in the shape dbf file.
>             my $record = $rslt->{shapeindex};
>             my @row = $hDBF->get_record_nf($record, $fld) or warn
> $hDBF->errstr . "\n";
>             push @results, $row[1];
>         }
>         $hDBF->close();
>     }
>     return @results;
> }
>
> On Mon, 2003-08-25 at 17:13, Stephen Clark wrote:
> >
> > I was wondering if there is the capability using php or mapscript to
query
> > multiple layers (each of polygons) and retrieve the list of which
polygon
> > this Point falls within?
> >
> >
> >
> > thanks,
> > Stephen Clark
> >
> > _______________________________________________
> > 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
>




More information about the MapServer-users mailing list