[mapserver-users] perl mapscript queryByRect() and queryByPoint() in 3.5

Steve Lime steve.lime at dnr.state.mn.us
Thu May 9 12:19:19 EDT 2002


The nature of queries changed in order to support data beyond
shapefiles, including tiled shapefiles. In 3.4 a result set was simply a
bit array where there was 1 bit/shape and presence or absence in the
result set was noted by 0/1. With the huge datasets that tiling and the
database-based allow that method wouldn't work. We needed to store more
information about each result so the current set up was put in place.

The next method was removed because of how it was coded in the previous
version. A static counter or pointer (don't remember which) was
maintained in the next method. Bad idea with threading in mind. I could
add a nextResult method to the layerObj pretty easily. It would simplify
things a tad:

while($result = $layer->nextResult()) {
  $record = $result->{shapeindex};
}

instead of the current:

for($i=0;$i=$layer->{resultcache}->{numresults}; $i++) {
  $record = $layer->getResult($i);
  $record = $result->{shapeindex};
}

Sound interesting?

Steve

Stephen Lime
Data & Applications Manager

Minnesota DNR
500 Lafayette Road
St. Paul, MN 55155
651-297-2937

>>> <imap at chesapeake.net> 05/08/02 04:06PM >>>


Steve(s) + Lowell + list,

About these perl mapscript 3.5 changes...

Ok, I understant $results = layer->{resultcache} part, but
in $layer->getResult(0), I'm having a bit of trouble with the
lack of documentation..  does 0 represent the first result
in the resultcache?  If so, I should be able to iterate the
$layer->getResult() thru numlayers, is that correct?  The
reason I am asking about this... In the 3.4 results object,
there was a method called $result->next() that we used to
fetch the MS_MULTIPLE results in a for loop.  If the next()
method is gone is mapserver 3.5, I am wondering why?  
It seemed to be much cleaner that dealing with shapeitems 
from a $result = getResult(0); $record = $result->{shapeitem};

Is there a technical reason for losing the $result->next() 
method?  Was this something that *needed* to change to 
accomodate OGR, WMT or some other component?  For a minor
rev, the impact on mapscript is pretty dramatic and not
too compatible with the previous version.  I dont mind
rewriting code in lieu of better methods, functions, etc.
but my opinion, what we got here isnt as elegant as the previous 
version...   I guess we just gotta code with the flow.

Regards,

Chris Stuber (mapsurfer)
Silicon Mapping Solutions, Inc
(410)257-3187



Lowell Filak wrote:
> 
> Actually the result is in $layer->getResult(0) . The
layer->{resultcache} is for doing things like
$result_cache->{numresults}. And you guessed it, the query...() returns
a status.
> I did have a typo in the latest version of the Perl-MapScript docs
that may have confused things but an update should be posted very soon.
> Also an example of a query is due to be posted to the wiki very soon.
(Don't let that stop you from posting your example however).
> Lowell F.
> 
> The following message was sent by imap at chesapeake.net on Wed, 08 May
2002 05:39:25 -0400.
> 
> >
> >
> > Guys, I wanted to contribute some stuff to the Perl MapScript
Wiki,
> > but when I went to test things out, all my query stuff is broken
> > under version 3.5/3.6.
> >
> > Going over some recent emails in the archive,
> > it is my understanding that queryByRect($rect) now returns
> > an integer (I am guessing status) and you have to get the
> > results from the layer->{'resultcache'}.
> >
> > $layer = $querymap->getLayerByName("county");
> > $status = $map->queryByRect($rect);
> > print "status of query: ".$status."\n";
> > $results = $layer->{'resultcache'};
> > print "number of results: ".$results->{'numresults'}."\n";
> >
> > status of query: 1
> > number of results:
> >
> >
> > ------- mapfile ----------
> >
> > LAYER
> >   NAME county
> >   TYPE LINE
> >   STATUS ON
> >   DATA "dtl_cnty"
> >   TEMPLATE dummy
> > END
> >
> >
> > bah...  and queryByPoint() is behaving the same way.
> > Does anybody have an example of queryByRect() and/or
> > queryByPoint() working in perl mapscript?
> >
> > Regards,
> >
> > Chris



More information about the mapserver-users mailing list