Customizing maps "on the fly"

Daniel Morissette morissette at
Thu Dec 14 11:00:05 EST 2000

Stephan Dunning wrote:
> I would actually like to figure out how to
> store all my raw data in a database (SQL Server in my case), have users
> create a summarized table of data (eg. by state) based on a separate query
> interface, then create a new map "on-the-fly" using this newly created
> tablular data.

I assume that you mean have the attribute information in a SQL
database.  And the georgaphic data would still be in shapefiles, right?

> Is there a way to: 1) "join" this new table to an existing shapefile, or
> create a new shapefile that references this table?
>                   2) use this custom shapefile to then create an "on the
> fly" mapfile to feed mapserver?
>                   3) utilize some kind of a Lookup Table to dynamically
> populate class names for legend labeling?
> I'm set up with PHP3/mapscript and using it in the my site which is
> currently based on the DM Solutions gmap demo.
> I'm running on a Windows NT, IIS sever.

#1, 2, 3 can all be done with PHP MapScript.  You would use the PHP ODBC
module to query your SQL database, and the PHP DBase module to create a
temporary DBF file for MapServer using the result of the query.

It is not possible to join an exsiting .shp file with a .dbf table with
the current MapServer.  However, the trick is to use a unique name for
the DBF table you create, and copy the .shp and .shx to the same
basename as the .dbf (on Unix you could use logical links)... resulting
in a new shapefile dataset.  Then you can feed that into one of your map
layers with the right classes and MapServer will be happy.

This technique was used several times and it works very well.  I'm
almost sure that's the kind of trick JF Doyon's Elections application
used.  We've also launched recently a couple of new application for
Health Canada ( that use a
similar approach to create cloropleth maps for over 100MB of disease
rates data.

BTW, Health Canada also launched a new version of its Fluwatch
application (using PHP MapScript) for the 2000-2001 flu season: 

 Daniel Morissette                morissette at
  Don't put for tomorrow what you can do today, because if 
      you enjoy it today you can do it again tomorrow.

More information about the mapserver-users mailing list