[Mapserver-users] GPS Coordinate Mapping
Homme Zwaagstra
hrz at geodata.soton.ac.uk
Wed Mar 24 01:22:17 PST 2004
On Tue, Mar 23, 2004 at 05:29:17PM -0700, Kasey Kirkham wrote:
> Hi all,
>
> I'm currently working on a GPS-oriented mapping application(with much
> help from Chris over at DM) using mapserver and php/mapscript(4.0.1 and
> 1.177, respectively). I need to be able to select coordinates out of a
> database and plot those coordinates over a map. I can zoom to a given
> extent through mapscript, but I'm at a loss as to how I can draw the
> points on the map. I was referred to this document:
> http://mapserver.gis.umn.edu/cgi-bin/wiki.pl?VirtualSpatialData
> but I would like something that left connecting to the database and
> preparing the points up to me. It might also be necessary to create
> layers with more complex shapes from a variable number of points.
>
> So, what mapscript objects/methods can be used to create shape files(or
> even the "shapes" themselves...) and to add them to the map at execution
> time? Of course, if I'm barking up the wrong tree entirely, some
> redirection would be equally appreciated.
>
> Thanks for you help,
> Kasey Kirkham
>
> Inexo Solutions
> Phoenix, AZ
Other than creating a shapefile from a list of coordinates, the other
way of drawing a point on a map goes something like this (in PHP mapscript):
<?php
$mapObj = ms_newMapObj('my_mapfile.map'); // instantiate the map object
$imageObj = $mapObj->draw(); // get an image representing the current map
$pointObj = ms_newPointObj(); // get a point
// set the X and Y
$x = 400000.0;
$y = 150000.0;
$pointObj->setXY($x, $y);
$layerObj = $mapObj->getLayerByName('my_point_layer'); // get the point layer
$class_index = 0;
$pointObj->draw($mapObj, $layerObj, $imageObj, $class_index, ''); // draw the point
// get the url and print it out
$url = $imageObj->saveWebImage();
$imageObj->free();
print '<img src="'.$url.'" />';
?>
The creation of a point object and drawing should be repeated for each
point you need to draw. If you need labels, check out the
POSTLABELCACHE map attribute for layers and the mapObj drawLabelCache
method.
Kind regards,
Homme Zwaagstra
More information about the MapServer-users
mailing list