[Mapserver-users] plot a point on map
Van Ulden, Joost
jvanulde at nrcan.gc.ca
Wed Jan 8 10:32:39 PST 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. 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. </FONT></SPAN></DIV>
<DIV><SPAN class=004301818-08012003><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=004301818-08012003><FONT face=Arial color=#0000ff size=2>There
may be an easier way to do this. I hope this helps.</FONT></SPAN></DIV>
<DIV><SPAN class=004301818-08012003><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </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> </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> </DIV>
<DIV><SPAN class=004301818-08012003><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=004301818-08012003><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </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> </DIV>
<DIV><SPAN class=004301818-08012003><FONT face=Arial color=#0000ff
size=2>LAYER<BR> NAME 'points'<BR> TYPE POINT<BR> STATUS
DEFAULT<BR> SYMBOLSCALE 50000<BR> TEMPLATE void<BR>
CLASS<BR> OUTLINECOLOR 255 89 89<BR> COLOR 0
102 51<BR> SYMBOL 'cultural site'<BR> SIZE
10<BR> MAXSIZE 25<BR> MINSIZE 10<BR>
END<BR>END</FONT></SPAN></DIV>
<DIV><SPAN class=004301818-08012003><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=004301818-08012003><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </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> </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> </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> </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> </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> </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> <BR>// loop through the iconArray and
build the select statement<BR>$selStmt = "";<BR>for ($rec=0; $rec <
sizeof($iconArray); $rec++) {<BR> if ($rec==sizeof($iconArray)-1){
<BR> $selStmt = $selStmt." con_id =
".$iconArray[$rec];<BR> } else {<BR> $selStmt =
$selStmt." con_id = ".$iconArray[$rec]." OR";<BR> }<BR>}<BR>// end loop to
build select statement<BR>if ( strlen($selStmt) != 0){<BR> $query =
"SELECT con_id, occ_id, story_x, story_y FROM getMapServerStories WHERE
".$selStmt;<BR> <BR> $result =
MSSQL_QUERY($query);</FONT></SPAN></DIV>
<DIV> </DIV>
<DIV><SPAN class=004301818-08012003><FONT face=Arial color=#0000ff size=2>
$number = MSSQL_NUM_ROWS($result);</FONT></SPAN></DIV>
<DIV> </DIV>
<DIV><SPAN class=004301818-08012003><FONT face=Arial color=#0000ff size=2>
if ($number > 0) {<BR> while (($row =
mssql_fetch_array($result, MSSQL_ASSOC))) {<BR>
$points[$row['occ_id']]['story_x'] =
$row['story_x'];<BR> $points[$row['occ_id']]['story_y']
= $row['story_y'];<BR> }<BR> }<BR>}</FONT></SPAN></DIV>
<DIV> </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> </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>// get a layer object representing your pointlayer<BR>$layerObj
= $map->getLayerByName("points");</FONT></SPAN></DIV>
<DIV> </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->getClass(0); </FONT></SPAN></DIV>
<DIV> </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> </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 => $coordinates) {<BR> <BR> //set the X Y
values of the point object<BR> $pointObj->setXY($coordinates['story_x'],
$coordinates['story_y']); <BR> <BR> // draw the point on the image,
using the id attribute to label it<BR> $pointObj->draw($map, $layerObj,
$image, 0, $occ_id); <BR>}</FONT></SPAN></DIV>
<DIV> </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> </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> </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> </DIV>
<DIV><FONT size=2>Many Thanks</FONT></DIV>
<DIV><FONT size=2>Nida Khan.</FONT></DIV>
<DIV> </DIV></BLOCKQUOTE></BODY></HTML>
------_=_NextPart_001_01C2B744.53168880--
More information about the MapServer-users
mailing list