[Mapserver-users] plot a point on map

Van Ulden, Joost jvanulde at nrcan.gc.ca
Wed Jan 8 13:32:39 EST 2003


This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01C2B744.53168880
Content-Type: text/plain;
	charset="iso-8859-1"

There are many ways to do this from my experience, but here is an example of
how we did it using php.  Essentially we query a database(MSSQL) for some
points based on some criteria(a comma delimited string called $icon_id) that
we set in the page.  Then we create a array of points and write them to the
layer (points) specified in the mapfile.  
 
There may be an easier way to do this.  I hope this helps.
 
Regards,
 
Joost
 
 
 
// Mapfile snippet
 
LAYER
  NAME 'points'
  TYPE POINT
  STATUS DEFAULT
  SYMBOLSCALE 50000
  TEMPLATE void
  CLASS
    OUTLINECOLOR 255 89 89
    COLOR 0 102 51
    SYMBOL 'cultural site'
    SIZE 10
    MAXSIZE 25
    MINSIZE 10
  END
END
 
 
// Start PHP template code
 
// BUILD POINT OBJECT ARRAY FROM THE DATABASE FOR POINTS YOU WANT TO
DYNAMICALLY DISPLAY
 
// database connection parameters
$hostname = "foo";
$username = "foo";
$password = "foo";
$dbName = "GBDL";
 
// associative array to contain the point data
$points = array(); 
 
MSSQL_CONNECT($hostname,$username,$password) or DIE("DATABASE FAILED TO
RESPOND.");
mssql_select_db($dbName) or DIE("Table unavailable");
 
// convert icon_id string to array
$iconArray = explode(",",$icon_id);
  
// loop through the iconArray and build the select statement
$selStmt = "";
for ($rec=0; $rec < sizeof($iconArray); $rec++) {
  if ($rec==sizeof($iconArray)-1){ 
    $selStmt = $selStmt." con_id = ".$iconArray[$rec];
  } else {
    $selStmt = $selStmt." con_id = ".$iconArray[$rec]." OR";
  }
}
// end loop to build select statement
if ( strlen($selStmt) != 0){
  $query = "SELECT con_id, occ_id, story_x, story_y FROM getMapServerStories
WHERE ".$selStmt;
 
 $result = MSSQL_QUERY($query);
 
  $number = MSSQL_NUM_ROWS($result);
 
  if ($number > 0) {
    while (($row = mssql_fetch_array($result, MSSQL_ASSOC))) {
     $points[$row['occ_id']]['story_x'] = $row['story_x'];
     $points[$row['occ_id']]['story_y'] = $row['story_y'];
   }
  }
}
 
// FINISHED BUILDING POINT OBJECT ARRAY
 
// START GENERATING YOUR DYNAMIC POINT LAYER

//  get a layer object representing your pointlayer
$layerObj = $map->getLayerByName("points");
 
// get a class object representing the first class in the layer
$classObj = $layerObj->getClass(0); 
 
// create a new point object to hold the X Y data
$pointObj = ms_newPointObj(); 
 
//iterate through the point data retreived from the database
foreach ($points as $occ_id => $coordinates) {
 
 //set the X Y values of the point object
 $pointObj->setXY($coordinates['story_x'], $coordinates['story_y']); 
 
 // draw the point on the image, using the id attribute to label it
 $pointObj->draw($map, $layerObj, $image, 0, $occ_id); 
}
 
// FINISHED GENERATING THE DYNAMIC POINT LAYER

-----Original Message-----
From: nida Khan [mailto:nida at webstar.co.uk]
Sent: Wednesday, January 08, 2003 6:16 AM
To: mapserver-users at lists.gis.umn.edu
Subject: [Mapserver-users] plot a point on map


Hi everyone,
 
I have a table with x and y coordinate in two integer fields.
I could'nt find any example to plot a point using these x and y coordinates
from the table.
 
I will appreciate if you could point me to right documentation or example.
 
Many Thanks
Nida Khan.
 


------_=_NextPart_001_01C2B744.53168880
Content-Type: text/html;
	charset="iso-8859-1"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">


<META content="MSHTML 6.00.2800.1126" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><SPAN class=004301818-08012003><FONT face=Arial color=#0000ff size=2>There 
are many ways to do this from my experience, but here is an example of how we 
did it using php.&nbsp; Essentially we query a database(MSSQL) for some points 
based on some criteria(a&nbsp;comma delimited 
string&nbsp;called&nbsp;$icon_id)&nbsp;that we set&nbsp;in the page.&nbsp; Then 
we create a array of points and write them to the layer (points) specified in 
the mapfile.&nbsp; </FONT></SPAN></DIV>
<DIV><SPAN class=004301818-08012003><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=004301818-08012003><FONT face=Arial color=#0000ff size=2>There 
may be an easier way to do this.&nbsp; I hope this helps.</FONT></SPAN></DIV>
<DIV><SPAN class=004301818-08012003><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=004301818-08012003><FONT face=Arial color=#0000ff 
size=2>Regards,</FONT></SPAN></DIV>
<DIV><SPAN class=004301818-08012003><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=004301818-08012003><FONT face=Arial color=#0000ff 
size=2>Joost</FONT></SPAN></DIV>
<DIV><SPAN class=004301818-08012003><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=004301818-08012003><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=004301818-08012003><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=004301818-08012003><FONT face=Arial color=#0000ff size=2>// 
Mapfile snippet</FONT></SPAN></DIV>
<DIV><SPAN class=004301818-08012003><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=004301818-08012003><FONT face=Arial color=#0000ff 
size=2>LAYER<BR>&nbsp; NAME 'points'<BR>&nbsp; TYPE POINT<BR>&nbsp; STATUS 
DEFAULT<BR>&nbsp; SYMBOLSCALE 50000<BR>&nbsp; TEMPLATE void<BR>&nbsp; 
CLASS<BR>&nbsp;&nbsp;&nbsp; OUTLINECOLOR 255 89 89<BR>&nbsp;&nbsp;&nbsp; COLOR 0 
102 51<BR>&nbsp;&nbsp;&nbsp; SYMBOL 'cultural site'<BR>&nbsp;&nbsp;&nbsp; SIZE 
10<BR>&nbsp;&nbsp;&nbsp; MAXSIZE 25<BR>&nbsp;&nbsp;&nbsp; MINSIZE 10<BR>&nbsp; 
END<BR>END</FONT></SPAN></DIV>
<DIV><SPAN class=004301818-08012003><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=004301818-08012003><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=004301818-08012003><FONT face=Arial color=#0000ff size=2>// 
Start PHP template code</FONT></SPAN></DIV>
<DIV><SPAN class=004301818-08012003><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=004301818-08012003><FONT face=Arial color=#0000ff size=2>// 
BUILD POINT OBJECT ARRAY FROM THE DATABASE FOR POINTS YOU WANT TO DYNAMICALLY 
DISPLAY</FONT></SPAN></DIV>
<DIV>&nbsp;</DIV>
<DIV><SPAN class=004301818-08012003><FONT face=Arial color=#0000ff size=2>// 
database connection parameters<BR>$hostname = "foo";<BR>$username = 
"foo";<BR>$password = "foo";<BR>$dbName = "GBDL";</FONT></SPAN></DIV>
<DIV>&nbsp;</DIV>
<DIV><SPAN class=004301818-08012003><FONT face=Arial color=#0000ff size=2>// 
associative array to contain the point data<BR>$points = array(); 
</FONT></SPAN></DIV>
<DIV>&nbsp;</DIV>
<DIV><SPAN class=004301818-08012003><FONT face=Arial color=#0000ff 
size=2>MSSQL_CONNECT($hostname,$username,$password) or DIE("DATABASE FAILED TO 
RESPOND.");<BR>mssql_select_db($dbName) or DIE("Table 
unavailable");</FONT></SPAN></DIV>
<DIV>&nbsp;</DIV>
<DIV><SPAN class=004301818-08012003><FONT face=Arial color=#0000ff size=2>// 
convert icon_id string to array<BR>$iconArray = 
explode(",",$icon_id);<BR>&nbsp;&nbsp;<BR>// loop through the iconArray and 
build the select statement<BR>$selStmt = "";<BR>for ($rec=0; $rec &lt; 
sizeof($iconArray); $rec++) {<BR>&nbsp; if ($rec==sizeof($iconArray)-1){ 
<BR>&nbsp;&nbsp;&nbsp; $selStmt = $selStmt." con_id = 
".$iconArray[$rec];<BR>&nbsp; } else {<BR>&nbsp;&nbsp;&nbsp; $selStmt = 
$selStmt." con_id = ".$iconArray[$rec]." OR";<BR>&nbsp; }<BR>}<BR>// end loop to 
build select statement<BR>if ( strlen($selStmt) != 0){<BR>&nbsp; $query = 
"SELECT con_id, occ_id, story_x, story_y FROM getMapServerStories WHERE 
".$selStmt;<BR>&nbsp;<BR>&nbsp;$result = 
MSSQL_QUERY($query);</FONT></SPAN></DIV>
<DIV>&nbsp;</DIV>
<DIV><SPAN class=004301818-08012003><FONT face=Arial color=#0000ff size=2>&nbsp; 
$number = MSSQL_NUM_ROWS($result);</FONT></SPAN></DIV>
<DIV>&nbsp;</DIV>
<DIV><SPAN class=004301818-08012003><FONT face=Arial color=#0000ff size=2>&nbsp; 
if ($number &gt; 0) {<BR>&nbsp;&nbsp;&nbsp; while (($row = 
mssql_fetch_array($result, MSSQL_ASSOC))) {<BR>&nbsp;&nbsp;&nbsp;&nbsp; 
$points[$row['occ_id']]['story_x'] = 
$row['story_x'];<BR>&nbsp;&nbsp;&nbsp;&nbsp; $points[$row['occ_id']]['story_y'] 
= $row['story_y'];<BR>&nbsp;&nbsp; }<BR>&nbsp; }<BR>}</FONT></SPAN></DIV>
<DIV>&nbsp;</DIV>
<DIV><SPAN class=004301818-08012003><FONT face=Arial color=#0000ff size=2>// 
FINISHED BUILDING POINT OBJECT ARRAY</FONT></SPAN></DIV>
<DIV><SPAN class=004301818-08012003><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=004301818-08012003><FONT face=Arial color=#0000ff size=2>// 
START GENERATING YOUR DYNAMIC POINT LAYER</FONT></SPAN></DIV>
<DIV><SPAN class=004301818-08012003><FONT face=Arial color=#0000ff 
size=2><BR>//&nbsp; get a layer object representing your pointlayer<BR>$layerObj 
= $map-&gt;getLayerByName("points");</FONT></SPAN></DIV>
<DIV>&nbsp;</DIV>
<DIV><SPAN class=004301818-08012003><FONT face=Arial color=#0000ff size=2>// get 
a class object representing the first class in the layer<BR>$classObj = 
$layerObj-&gt;getClass(0); </FONT></SPAN></DIV>
<DIV>&nbsp;</DIV>
<DIV><SPAN class=004301818-08012003><FONT face=Arial color=#0000ff size=2>// 
create a new point object to hold the X Y data<BR>$pointObj = ms_newPointObj(); 
</FONT></SPAN></DIV>
<DIV>&nbsp;</DIV>
<DIV><SPAN class=004301818-08012003><FONT face=Arial color=#0000ff 
size=2>//iterate through the point data retreived from the database<BR>foreach 
($points as $occ_id =&gt; $coordinates) {<BR>&nbsp;<BR>&nbsp;//set the X Y 
values of the point object<BR>&nbsp;$pointObj-&gt;setXY($coordinates['story_x'], 
$coordinates['story_y']); <BR>&nbsp;<BR>&nbsp;// draw the point on the image, 
using the id attribute to label it<BR>&nbsp;$pointObj-&gt;draw($map, $layerObj, 
$image, 0, $occ_id); <BR>}</FONT></SPAN></DIV>
<DIV>&nbsp;</DIV>
<DIV><SPAN class=004301818-08012003><FONT face=Arial color=#0000ff size=2>// 
FINISHED GENERATING THE DYNAMIC POINT LAYER</FONT></SPAN></DIV>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
  <DIV class=OutlookMessageHeader dir=ltr align=left><FONT face=Tahoma 
  size=2>-----Original Message-----<BR><B>From:</B> nida Khan 
  [mailto:nida at webstar.co.uk]<BR><B>Sent:</B> Wednesday, January 08, 2003 6:16 
  AM<BR><B>To:</B> mapserver-users at lists.gis.umn.edu<BR><B>Subject:</B> 
  [Mapserver-users] plot a point on map<BR><BR></FONT></DIV>
  <DIV><FONT size=2>Hi everyone,</FONT></DIV>
  <DIV><FONT size=2></FONT>&nbsp;</DIV>
  <DIV><FONT size=2>I have a table with x and y coordinate in two integer 
  fields.</FONT></DIV>
  <DIV><FONT size=2>I could'nt find any example to plot a point using these x 
  and y coordinates from the table.</FONT></DIV>
  <DIV><FONT size=2></FONT>&nbsp;</DIV>
  <DIV><FONT size=2>I will appreciate if you could point me to right 
  documentation or example.</FONT></DIV>
  <DIV><FONT size=2></FONT>&nbsp;</DIV>
  <DIV><FONT size=2>Many Thanks</FONT></DIV>
  <DIV><FONT size=2>Nida Khan.</FONT></DIV>
  <DIV>&nbsp;</DIV></BLOCKQUOTE></BODY></HTML>

------_=_NextPart_001_01C2B744.53168880--



More information about the mapserver-users mailing list