[Mapserver-users] Re: Implementing querying functionality using Perl MapScript

Eric Bridger eric at gomoos.org
Tue Jul 15 04:30:06 PDT 2003


You can find XBase here:
http://search.cpan.org/author/JANPAZ/DBD-XBase-0.234/lib/XBase.pm  
You will need to install it. The mapserver install does not do this for
you.

The version shouldn't matter. As explained below, Mapserver's query
results will give you the index into the dbf file.

I think I recall some users having problems using the DBF functions in
Perl/Mapscript.  I too, always use XBase. E.g.

 my $datafile = $layerObj->{data};
 # To get the attributes open the dbf file.
        
 my $dbfile = $datafile . '.dbf';
 my $hDBF = new XBase "$dbfile" or die XBase->errstr;
 my @row = $hDBF->get_record($rec_no) or warn $hDBF->errstr . "\n";

Eric


On Tue, 2003-07-15 at 14:09, pkishor_98 wrote:
> --- In mapserver-users at yahoogroups.com, AMC Story <s9646183 at s...> wrote:
> > Thanks, I'll try to be a bit more specific this time :)
> 
> good. often we get vague-ish questions, and it is almost impossible for anyone to 
> answer them. it seems obvious on hindsight, but most of us are likely working in 
> environments different from that of the person asking the question -- it is simply a 
> waste of bandwidth and energy trying to "imagine" what the problem might be. 
> anyway, ;-)
> 
> 
> > 
> > Basically, I'd like to be able to select a point object from the map, and then 
> > display a new pop-up box, which would give the user all the information about 
> > that point feature which is stored in the dbf file, and perhaps also include a 
> > map in this pop up window which would highlight the selected feature in a 
> > different colour or with a different symbol.  Not quite sure how to do the pop-
> > up box thing yet, but I seem to remember some tips on this in the archive, so 
> > I'll look at that once I've figured out how to do the basics.
> 
> pop-up is a javascript or basic html question. Use js to create a new window, or use 
> "target=_blank" on a link to open a new window.
> 
> for a map being displayed in the pop-up, see the itasca demo. It does it very well.
> 
> first concentrate on getting it all to work in a regular html window. Once it works 
> there, you can always convert it into a pop-up or a frames-based app.
> 
> > 
> > So far, I've got to the point where I can display the shapeindex of the 
> > selected point, 
> > 
> > ie. $rec_no = $result_feature->{shapeindex};
> > 
> > but I'm now struggling to work out how to access the attributes of the feature 
> > in the dbf file with that record number.  In some of the examples, the XBase 
> > module is used.  I don't seem to be able to access this (and I've tried xdb and 
> > Xbase too) but I could possibly get it installed if it's necessary.
> 
> I have used Xbase like so
> 
> ##############################
> my $table = new Xbase;
> 
> $table->open_dbf($shapefile . '.dbf') or die Xbase->errstr;
> ##############################
> 
> but there are more detailed examples available. Just read the docs for Xbase.
> 
> In concept, you will use the shapeindex to grab the specific record. The shapeindex 
> indicates the row in the dbf table. Keep in mind, the first row in the dbf table is the 
> header row... the names of the columns. The second row corresponds to the first 
> shapeindex, etc.
> 
> > 
> > I was wondering though whether I could use methods of the DBFInfo class or some 
> > of the miscellaneous functions such as msDBFReadStringAttribute which I saw 
> > listed on the Perl MapScript Reference some time ago, but which now seem to 
> > have disappeared.  Are these still supported, and is there any documentation 
> > somewhere for them?
> 
> Yes, you can use the DBF functions in Perl/Mapscript. I haven't... I just use the Xbase 
> module. Make sure you have the latest version, and read the docs. You can also use 
> XBase... the syntax is slightly different.
> 
> > 
> > 
> > Quoting pkishor_98 <pkishor at g...>:
> > 
> > > --- In mapserver-users at yahoogroups.com, AMC Story <s9646183 at s...>
> > > wrote:
> > > > Hi there everyone,
> > > > 
> > > > I've been using Perl MapScript to develop the interface 
> > > > of my application, and  am now wanting to implement the 
> > > > querying functionality that I had going with 
> > > > the old mapserver CGI version, but now with MapScript.  
> > > 
> > > could you elaborate more on --
> > > 
> > > - what have you already developed with Perl/Mapscript; and
> > > - what you mean by "querying functionality"
> > > 
> > > Until you do that, I am going to assume you mean identifying a feature
> > > based on the user's mouse-click.
> > > 
> > > > I was wondering if there are any examples of the code
> > > > needed to do this, as I can't seem to find 
> > > > anything more than very brief (and apparently incorrect!) 
> > > > snippets in the 
> > > > archives.  
> > > 
> > > which archives did you look at? There are several very nice examples
> > > on the wiki, and in the Perl/Mapscript docs. The best, most complete
> > > example is the mapquakes.pl script. It shows you the building blocks.
> > > 
> > > Briefly... you capture the mouse clicks and use them to create the new
> > > map envelope and generate a new image. If you are querying... you once
> > > again use the mouse clicks to get the shapeindex and then get its
> > > associated attribute data from either the <shape>.dbf or a related
> > > external database table. Keep in mind, the mouse clicks would be
> > > imagespace, and will have to be converted to geographic space before
> > > doing anything with them.
> > > 
> > > There are definitely fewer ready-to-use, code capsules for
> > > Perl/Mapscript, and some of us have talked about remedying the
> > > situation. Most Perl/Mapscript users, however, have found the existing
> > > examples quite helpful in guiding them and setting them on the correct
> > > path to developing their own code. Each application is different, and
> > > it is hard to provide a demo that will work for everyone.
> > > 
> > > Please look at the above mentioned examples on the wiki, and then if
> > > you have specific questions come and ask us. One of us will be able to
> > > help you.
> > > 
> > > 
> > > 
> > > _______________________________________________
> > > Mapserver-users mailing list
> > > Mapserver-users at l...
> > > http://lists.gis.umn.edu/mailman/listinfo/mapserver-users
> > > 
> > _______________________________________________
> > Mapserver-users mailing list
> > Mapserver-users at l...
> > 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