[mapserver-users] RE: QuerybyAttributes examples

Puneet Kishor pkishor at GeoAnalytics.com
Thu Oct 10 12:53:14 EDT 2002


On Wednesday, October 9, 2002, at 10:36  PM, YC Nyon wrote:

> I have a massive business directory in MySQL database. Using 
> PHP, dynamic queries can be made. What i want to implement is for 
> the user to click "View Map" button on the results and zoom to the 
> location of the business. Currently, i have MS-PHP running doing the 
> zoom/pan stuff.
>  
> Looking at the documentation, QuerybyAttributes seems to be the method 
> to use. In Mysql, I can add a column to store the record-id which can 
> be passed to MS-PHP. Not too sure how to go about it. Can someone 
> share their code snippets on this function.
>

dunno about QueryByAttributes, but the general approach using the above 
idea would be like so...

1. create a table in MySQL called shpdbf (call it whatever, this is 
just an example).
2. import the shapfile.dbf into the new table (make sure you don't 
import the first row, because that contains the field names).
3. create a column called "shprowid" in table "shpdbf".
4. update "shprowid" to the actual row_id.

keep in mind, shape indexes are base 1. MySQL records retrieved in an 
array are base 0. As long as you remember that, there will be no 
confusion.

Now, when you query the business directory, you can retrieve the 
corresponding "shprowid" from the "shpdbf" table in MySQL. That value 
is the index of the feature you want to zoom to. No more querying teh 
shapefile.dbf at all. Everything is super fast.

The only problem. If you update the shapefile (geometrically speaking), 
its indexes go out of whack. So, you would have to re-sync the MySQL 
table "shpdbf" with the shapefile.dbf.

All that said, that is, I hope, what you were asking.

;-)





More information about the mapserver-users mailing list