[Mapserver-users] another mysql php mapscript question

Vinko Vrsalovic vinko at cprsig.cl
Mon Aug 25 19:29:46 EDT 2003


On Thu, Aug 21, 2003 at 09:23:34AM -0400, Geoffrey Rowland wrote:
> Hello,
> 
> I am using Mapserver 4.0 with php mapscript on a windows machine running 
> IIS 5.  I have rendered several layers.....now I have some information 
> that I store in a mysql table....actually it could even be stored in a 
> text file if that would be easier (less overhead, I know). It has a 
> county name and then a number.  That number is always updated from the 
> web.  One day it may be 10, the next it may be 15.  now, what I am 
> wanting to do is to generate a mapserver layer based on what that number 
> is for each county.  I will color the counties based on what that number 
> is (similar to using graduated colors to render a population layer, 
> except this won't be population).  After I use PHP to connect to mysql 
> and get the information.....what is the next step?  Are there any code 
> examples of something like this floating around?   Is there a specific 
> php mapscript function I should be looking at?

Your question is too broad. You've got several options to do this.

One of them is the following...

Once you've obtained the data you can classify it using expressions
based in the county name (of course, the names in the DB and in the
shapefile must match exactly), and then add styles to each class with
the color you calculated.

A brief example in pseudopseudocode :) would be something like:

<?php
	dl('php_mapscript.so');
	$data = getData(); // $data would be an array with the counties
			   // and values obtained from the DB
	$map = ms_newMapObj(...);
	$lyr = $map->getLayerByName("counties");
	$lyr->set('classitem','COUNTYNAME'); // COUNTYNAME is the row of
					     // the shapefile
					     // with the county names, of course :)
	$colors = calculateColors($data);
	$counties = calculateCounties($data);
	for ($i=0;$i<count($data);$i++) {
		$cla = ms_newClassObj($lyr);
		$cla->setExpression($counties[$i]); 
		$sty = ms_newStyleObj($cla);
		$sty->color->setRGB($colors[$i][0],$colors[$i][1],$colors[$i][2]);
		$sty->outlinecolor->setRGB(...); 
		... // all values, and labels for the class, etc.
	}
	$img = $map->draw();
?>

-- 
Vinko Vrsalovic <el[|- at -|]vinko.cl>
http://www.cprsig.cl



More information about the mapserver-users mailing list