drawing points from mysql with php/mapscript

Skalski Artur - askals Artur.Skalski at ACXIOM.COM
Mon Dec 5 09:47:42 PST 2005


hi Mark

Currently I'm working on the same issue,
If You draw ponits from any data base like that you will not ba able to query them like the regular point layer, so if You want to query them you should use ogr 
    http://ogr.maptools.org/drv_vrt.html
    http://mapserver.gis.umn.edu/cgi-bin/wiki.pl?VirtualSpatialData,

any way this is how I have solved the problem of generating dynamic poinst from db:

mapfile layer:
LAYER
    NAME selpoint
    TYPE POINT
    STATUS ON
    #TRANSPARENCY 40
   CLASS
       NAME "0"
       STYLE
         COLOR 0 0 180
          SYMBOL 'C:\Inetpub\wwwroot\mapserver\sopot\etc\tutaj.gif'
       END
   END 
END 

and the php code:
{
	$MinX = doubleval($HTTP_FORM_VARS["minx"]);
	$MinY = doubleval($HTTP_FORM_VARS["miny"]);
        	$MaxX = doubleval($HTTP_FORM_VARS["maxx"]); 
        	$MaxY = doubleval($HTTP_FORM_VARS["maxy"]);

	$_POST['ArrX'] = array(4340433.22, 4340245.38, 4342358.58); (the search results are stored in the array)
	$_POST['ArrY'] = array(6037766.72, 6038377.20, 6037602.36);

SetMapExtents($MinX, $MinY, $MaxX, $MaxY); //it will not zoom the map out when you add them dymnamicaly, otherwise it does, a least in my case
		for($i=0; $i<count($_POST['ArrX']); $i++)
		{
			$spoint = ms_newPointObj();
    			$spoint->setXY($_POST['ArrX'][$i], $_POST['ArrY'][$i]);

			$slayer = $gpoMap->getLayerByName(selpoint);
		
			$sline = ms_newLineObj();
    			$sline->add($spoint);

			$sshape = ms_newShapeObj(MS_SHAPE_POINT);
    			$sshape->add($sline);
		
			$slayer->addFeature($sshape);
		}


}

and that's it

hope it helps

regards

Artur Skalski


-----Original Message-----
From: UMN MapServer Users List [mailto:MAPSERVER-USERS at LISTS.UMN.EDU]On Behalf Of Mark Brooks
Sent: Monday, December 05, 2005 5:38 PM
To: MAPSERVER-USERS at LISTS.UMN.EDU
Subject: [UMN_MAPSERVER-USERS] drawing points from mysql with php/mapscript


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?

Here is part of my mapfile, which sets up an empty layer for the sites I 
want to draw on the map....
LAYER
	NAME sites
	TYPE POINT
	STATUS DEFAULT
	CLASS
	   NAME 'Project Sites'
	   COLOR 150 150 150
	   SYMBOL 'circle'
	   SIZE 10
	   LABEL
	      TYPE truetype
	      FONT "arial"
	      SIZE 10
	      POSITION UC
	      COLOR 150 150 150
	   END
	END
END


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']);		}


My site points are latitude,longitude.  When I do all this, I only get 
ONE point drawn on my map.  There are dozens of points but only one gets 
plotted, and I'm not entirely certain that it truly is a point from my 
database.  I even hardcoded several different coordinates but only one 
dot appears on my map.

What am I missing?


-- 

   Mark Brooks
   Meteorologist
   State Climate Office of North Carolina
   Box 7236, NC State University
   Raleigh, NC 27695-7236

   E-mail:  mark_brooks at ncsu.edu
   Phone:  919.515.1446
   Fax:  919.515.1441
*************************************************************************
The information contained in this communication is confidential, is
intended only for the use of the recipient named above, and may be
legally privileged.

If the reader of this message is not the intended recipient, you are 
hereby notified that any dissemination, distribution or copying of this
communication is strictly prohibited.

If you have received this communication in error, please resend this
communication to the sender and delete the original message or any copy
of it from your computer system.

Thank you.
*************************************************************************



More information about the MapServer-users mailing list