[Mapserver-users] Coloring shapefile layer according to DB query

Steve Lime steve.lime at dnr.state.mn.us
Fri Oct 10 13:11:54 PDT 2003


An increasingly popular topic these days.

There is no way with CGI MapServer to link the two for map creation.
Your best bet
would be to create a custom shapefile that combines the base shapefile
and the MySQL
database. You can use MapScript and the DBD drivers for MySQL and XBase
to do this
pretty easily. The psuedo code is something like:

- copy the base shapefile to a new file
- open the new shapefile DBF file
- add the new columns
- open the connection to MySQL
- for each shape select the corresponding MySQL row
  - copy the content from MySQL to the DBF file
- close everything

Really shouldn't be more that 20 lines.

If done properly you could run this script every so often to sync the
2
datasets using cron. The advantage of this approach is that it gives
you a dataset 
optimized for map making. The real time joins are certainly doable but
would absolutely
kill performance- that's why they're not supported.

If your MySQL data is not changing every few seconds then this approach
should work
quite well. Postgres/PostGIS is of no help unless you want to move
everything into it and
not use MySQL.

Steve

Stephen Lime
Data & Applications Manager

Minnesota DNR
500 Lafayette Road
St. Paul, MN 55155
651-297-2937

>>> "Matthew Haines" <mhaines94108 at hotmail.com> 10/10/2003 2:20:18 PM
>>>

I have a shapefile for the tax lots in Manhattan (New York City) and I
have 
a lot of information about the individual tax lots in a MySQL database.
 I 
would like to generate maps where I color the tax lots according to the
data 
in the MySQL database.

Just as an example, I have a table that tells me how many residential
units 
have been built on a particular tax lot.  I might like to color the map
by 
population density so that single family dwellings are light red, 2-4
family 
buildings are medium red, and 5+ family apartment buildings are dark
red.

Is there any way to do this without loading the shapefile polygons into
the 
database?  I've had several thoughts, but they seem impractical ...

=> I could use Perl MapScript to write a program that would scan the
entire 
database table and assign tax lots to different layers ... but there
are 
100,000 tax lots in Manhattan and that might take a long time.

=> I could try to get put the data into the shapefile ... but how?  I
don't 
have any commercial mapping software for working with shapefiles.  Is
there 
a utility to do this?  Also that makes my data hard to update.

=> Is there a MAP file command to load data from a database and somehow
join 
it to the shapefile on the fly so I can define layers based on it?

I'm hesitant to mess with MySQL, if only for fear of breaking my
existing 
applications.  The documentation indicates that the MySQL connector is

buggy.

What's the best way to go about this?  Do I have to install
PostgreSQL?

Pointers much appreciated,

Matthew

Matthew

_________________________________________________________________
Share your photos without swamping your Inbox.  Get Hotmail Extra
Storage 
today! http://join.msn.com/?PAGE=features/es 

_______________________________________________
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