drawing points from mysql with php/mapscript

Gavin Simpson gavin.simpson at UCL.AC.UK
Mon Dec 5 09:59:09 PST 2005


On Mon, 2005-12-05 at 11:37 -0500, Mark Brooks wrote:
> I'm trying to draw points from a MySQL database onto a map with 
> PHP/Mapscript.  I found no clear examples online and so far have had 
> little luck at being successful.  Does anyone out there have any 
> examples you could share?
<snip>
> And a watered-down snippet from my php code to draw the dynamic points 
> from mysql:
> 
> $image = $map->draw();
> $this_layer = $map->getLayerByName('sites');
> $this_layer->set('status', MS_ON);
> //query database for points
> $query = "select bla bla";
> $sresult = mysql_query($query);
> // loop through database results, adding the new point to the layer
> while ($site = mysql_fetch_assoc($sresult)){
> 	$mypoint = ms_newPointObj();
> 	$mypoint->setXY($site['lat'],$site['lon']);
> 	$mypoint->draw($map,$this_layer,$image,0,$site['name']);		}
<snip>
> 
> What am I missing?

Does this help?

$layer = $map->getLayerByName("samples");

for ($i = 0; $row = mysql_fetch_array($samplesQuery); $i++)
	{
		$pt = ms_newPointObj();
		$pt->setXY($row["fullEasting"], $row["fullNorthing"]);
		$line = ms_newLineObj();
		$line->add($pt);
		$shape = ms_newShapeObj(MS_SHAPE_POINT);
		$shape->add($line);
		$shape->set("index", $i);
		$shape->set("text", $row["siteCode"]);
		$layer->addFeature($shape);
		$pt->draw($map, $layer, $image, 0, $row["siteCode"]);
	}

You first create a point, then a lineObj to hold the point, then a
shapeObj of type MS_SHAPE_POINT and add the lineObj to the shapeObj,
then add the shapeObj to a layer, then draw the point on the named
layer/map/image.

The above example shows these steps - I wanted this in a for loop with
an index so I could set the index for each point and I also set the text
for each point so i can retrieve info later.

HTH,

G

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
Gavin Simpson                     [T] +44 (0)20 7679 5522
ENSIS Research Fellow             [F] +44 (0)20 7679 7565
ENSIS Ltd. & ECRC                 [E] gavin.simpsonATNOSPAMucl.ac.uk
UCL Department of Geography       [W] http://www.ucl.ac.uk/~ucfagls/cv/
26 Bedford Way                    [W] http://www.ucl.ac.uk/~ucfagls/
London.  WC1H 0AP.
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%



More information about the MapServer-users mailing list