[mapserver-users] RE: Mapserver getExtent

Puneet Kishor pkishor at GeoAnalytics.com
Mon Nov 12 18:32:54 EST 2001


Erwin,

Please see my answer below. I am cc-ing this to the entire list so others
may benefit from it also.

> -----Original Message-----
> From: Consult IT!, E. Perik [mailto:pxp at xs4all.nl]
> Sent: Monday, November 12, 2001 5:13 PM
> To: Puneet Kishor
> Subject: Mapserver getExtent
> 
> 
> Hello Puneet,
> 
> i saw your question regarding getting the extents of a queried shape.
> 
> Have you solved this problem? hop you did, because i could 
> youse some help
> on that.
> I have a form-list with all cities of a dbase database. When 
> user selects a
> citie, the queried citie is highlighted.
> 
> What i want to do (with PHP and mapscript) is to zoom in on 
> that city. Have
> tried for ages, but never succeeded.



Here's the general concept --

1. You have to find the index of the shape that belongs to the feature you
have selected. For example, if you have selected City eq "Delft", then you
have to find the index of the shape in the cities layer that represents
"Delft".

2. Once you have found the index then it is merely a matter of creating a
new shapeobject with that shapeindex, and finding its mapextent. The problem
is getting the index of the shape.

3. The index of the shape is the same as the row number of the city record
in the corresponding .dbf file (remember, all shape files are made up of
.shp, .shx, .dbf and whatnot... the .shp stores the actual geometry while
the .dbf stores the attributes... they are linked by the shapeindex which is
the same as the row number of the corresponding record in the .dbf file.)

4. .dbf files are really primitive. They have an absolute sort order that is
hard-coded in the way the file is written. You have to somehow query the
.dbf file for City eq "Delft" and get the row number of the that record. You
can use the Xbase module in PHP to do that. I have not done that. Instead, I
imported the .dbf file into a MySQL table and created a new field called
row_id. I populated the row_id with the corresponding row number in the .dbf
file. Keep in mind, the .dbf file is indexed from 0, however, the first row
contains the row headers (the field names). Now I simply query the MySQL
table for City eq "Delft" and get its row_id.

5. The advantage of doing it the way I do it is that it is really fast... no
mucking around with .dbf and Xbase. The downside is that if my shapefile
were to ever change then I would have to purge my MySQL table and re-import.
Not a problem for me at this time.

6. If you are using the Xbase module then your Xbase query will return the
row number somehow or the other... I haven't done this but others have
assured that it is indeed so.

> 
> Do you have an example of your version. It would really help.
> 


I do have, and I have been promising the list that I am going to make it all
available. Except, I have been so madly beseiged with another client project
that I haven't had the time to package the scripts and the data in a way
that not only does it make sense to other coders/users but it also doesn't
make the client (for whom I did the PHP/Mapserver project) unhappy by
violating their secrecy, privacy, etc.

In other words, I will have all the scripts and sample data available for
everyone's perusing pleasure sooner or later, but I don't right now.

Otoh, if any of the above is confusing, just let me know I will be happy to
guide you further.

Good luck,

pk/



More information about the mapserver-users mailing list