[mapserver-users] queryByAttribute()
kenboss
kenboss at dilbert.dnr.state.mn.us
Fri Apr 26 11:53:03 PDT 2002
Steve's point about setting the map extent for the area you want to search is a valid and useful one.
For the actual querying, try something like:
$layer->{status} = $mapscript::MS_ON; # if it's not on already
$class = new classObj($layer); # if you don't have one already
$layer->{template} = $template; # if you don't have one (or a class template) already
$layer->{filteritem} = "SOMEITEM";
$layer->setFilter("\"$var\""); # Assuming you're matching on a string
$rv = $layer->queryByAttributes($map, $mapscript::MS_MULTIPLE); # or MS_SINGLE
$rv == $mapscript::MS_SUCCESS or warn "No match found";
then get your results like:
for ($i=0; $i<$layer->{resultcache}->{numresults}; $i++) {
$result = $layer->getResult($i);
... (do something with the result)
}
See also:
http://mapserver.gis.umn.edu/wilma/mapserver-users/0203/msg00413.html
for some hints on how to use queryByAttributes with logical expressions.
--Ken Boss
> OK, does anyone know how queryByAttribute() is supposed to be used?
>
> I put my guess below, but I haven't tried it, and Stefano has been
> trying to get an answer on this for a few days without much success.
>
> -Steve
>
> Daniel Morissette wrote:
> >
> > Steve,
> >
> > I believe what you suggest should work in MapScript, but I never used
> > queryByAttribute() myself so I can't confirm anything. About the
> > ITEMQUERY and ITEMNQUERY CGI modes, I never used them directly so I
> > can't tell you much about them either
> >
> > Seems that you touched an area of MapServer that I'm less familiar
> > with... you may have more luck asking Steve Lime, or by Emailing the
> > list directly... :)
> >
> > Daniel
> >
> > Stephen Woodbridge wrote:
> > >
> > > Stefano,
> > >
> > > This might work for you, but I think (but I am not sure) that you can do
> > > the same thing in Mapscript by:
> > >
> > > 1) set the extents to the area you want to search
> > > 1a) make sure you have TEMPLATE defined for the layers you want to query
> > > 2) set the filteritem to the query you want to perform
> > > (this is the step I am guessing, otherwise I'm not sure how
> > > you would specify what the queryByAttribute query would be.)
> > > 3) call queryByAtrribute(mode) where mode = MS_SINGLE or MS_MULTILE
> > > 4) use getNumResult() and getResult(index) to fetch results.
> > >
> > > I think this is equivalent to ITEMQUERY and ITEMNQUERY
> > >
> > > Dan, can you confirm this for us?
> > >
> > > -Steve W.
> > >
> > > Stefano Bonnin wrote:
> > > >
> > > > Hi,
> > > >
> > > > I have just looked at this examples:
> > > >
> > > > http://maps.dnr.state.mn.us/mapserver_demos/tests/itemquery/test.html
> > > >
> > > > they use mapserver cgi functionality.
> > > >
> > > > ITEMQUERY and ITEMNQUERY are the right parameters for me. I think.
> > > >
> > > > What do you think about this way?
> > > > In my application I use Mapscript but only for this query I could use this
> > > > method.
> > > >
> > > > Stefano B.
> > > >
> > > > ----- Original Message -----
> > > > From: "Stephen Woodbridge" <woodbri at swoodbridge.com>
> > > > To: "Stefano Bonnin" <shpr at libero.it>
> > > > Cc: <mapserver-users at lists.gis.umn.edu>
> > > > Sent: Friday, April 26, 2002 2:10 PM
> > > > Subject: Re: [mapserver-users] Street Searching
> > > >
> > > > > Stefano,
> > > > >
> > > > > I wrote a separate CGI program to do this. You could write it in C or
> > > > > Perl or whatever. It does the address lookup by scanning the approprate
> > > > > shape files and when it has a result it sends a client redirect to the
> > > > > browser to get it to load the map with the Lat/Long result for the
> > > > > search results.
> > > > >
> > > > > I think you will find this much easier to do if you think about doing it
> > > > > outside of mapserver/mapscript and only send the final result to get
> > > > > mapserver to display the answer.
> > > > >
> > > > > -Steve W.
> > > > >
> > > > > Stefano Bonnin wrote:
> > > > > >
> > > > > > Hi,
> > > > > >
> > > > > > I have to develop a Street Searching function where
> > > > > >
> > > > > > the user can insert City and Street ( and number) and the application
> > > > must
> > > > > > display the map centered on this street.
> > > > > >
> > > > > > How can I do that with mapserver?
> > > > > > Can you give me an Hint in order to do this.
> > > > > >
> > > > > > I read the PHP Map/documentation but I did't find any query of this
> > > > type.
> > > > > > My personal solution is the following:
> > > > > >
> > > > > > with a PHP application I get the user input (Street and City) and I
> > > > query to
> > > > > > the database in order to find the object ID, then, I "say" to mapserver
> > > > to
> > > > > > create a map with this object ....
> > > > > >
> > > > > > Someone can say me if this is a possible solution or if there are a more
> > > > > > simple solution?
> > > > > >
> > > > > > Thanks.
> > > > > >
> > > > > > Stefano B.
> > > > > >
> > > > > > ---
> > > > > > Outgoing mail is certified Virus Free. (FLASHH!)
> > > > > > Checked by AVG anti-virus system (http://www.grisoft.com).
> > > > > > Version: 6.0.350 / Virus Database: 196 - Release Date: 17/04/02
> > > >
> > > > ---
> > > > Outgoing mail is certified Virus Free. (FLASHH!)
> > > > Checked by AVG anti-virus system (http://www.grisoft.com).
> > > > Version: 6.0.350 / Virus Database: 196 - Release Date: 17/04/02
More information about the MapServer-users
mailing list