dynamic point generation with php-mapscript
Dan Taylor
logicalgenetics at GMAIL.COM
Fri Apr 15 04:55:01 PDT 2005
This is how I do it. Very basic though...
function addpoints($map, $name, $points, $r, $g, $b, $symbol,
$font_face, $font_size)
{
// Create a layer
$layer = ms_newLayerObj($map);
$layer->set("type", MS_LAYER_POINT);
$layer->set("name", $name);
$layer->set("status", MS_ON);
// Create the default class and set up label
$cl = ms_newClassObj($layer);
$cl->set("status", MS_ON);
$cl->label->set("size", $font_size);
$cl->label->set("type", "MS_TRUETYPE");
$cl->label->set("font", $font_face);
$cl->label->set("position", MS_LC);
$cl->label->color->setRGB($r, $g, $b);
$cl->label->outlinecolor->setRGB(0, 0, 0);
// Create and set up style
$sty = ms_newStyleObj($cl);
$sty->set("symbolname", $symbol);
$sty->color->setRGB($r, $g, $b);
$sty->outlinecolor->setRGB(0, 0, 0);
// Add points
for($i = 0; $i < sizeof($points); $i++)
{
$point = ms_newPointObj();
$point->setXY($points[$i]->x, $points[$i]->y);
$line = ms_newLineObj();
$line->add($point);
$shape = ms_newShapeObj(MS_SHAPE_POINT);
$shape->add($line);
$shape->set("text", $points[$i]->text);
$layer->addFeature($shape);
}
}
Dan
On 4/15/05, Gavin Simpson <gavin.simpson at ucl.ac.uk> wrote:
> Wouter Schaubroeck wrote:
> > Hi,
> >
> > I was wondering if anyone would know some good examples of generating
> > dynamic points with php mapscript? For example: just pulling the points
> > from (in my case: a MySQL db) a database and displaying them without a
> > shape file? And is it possible to do queries on that layer, or
> > displaying the attribute data? I assume not, because there's no
> > associated dbf file.
> >
> > Best regards,
> >
> > Wouter Schaubroeck
> >
> >
>
> See the PHP/Mapscript WIKI - which has such an example:
>
> http://mapserver.gis.umn.edu/cgi-bin/wiki.pl?PHPMapScriptAddPoint
>
> Querying that layer is more problematic. You need to create a shapeObj
> and addFeature()'s to that shapeObj etc:
>
> http://mapserver.gis.umn.edu/cgi-bin/wiki.pl?PerlMapScriptExamples42ex1
> shows you how to do this with Perl which is easily translated to PHP (I
> did it yesterday but my code is in a mess of other trial stuff just
> now), with one major exception! PHP/Mapscript is broken at the moment
> and you can't set the index of a shapeObj added to a layer (it needs to
> be numeric, integer, incrementing in steps of 1 - so not a arbitrary
> ordering of ID's from a mysql table index, currently it returns -1
> error), which you need to have queryByPoint do anything useful etc. See:
> http://mapserver.gis.umn.edu/bugs/show_bug.cgi?id=806
>
> A patch has been accepted for this bug so you can download a nightly or
> the cvs of mapserver (or replace php_mapscript.c in the tarball of
> mapserver4.4.2 with the one in that bug report) and roll your own
> php_mapscript.so.
>
> After a few errors I have just gotten this compiling as well (a
> nightly), so maybe I can query that layer after all... :-)
>
> Please note - I'm a mapserver virgin so I've been bumbling through this
> for only a day or so - feel free to email me further about this but I
> can't guarantee I'll be able to help much beyond providing some very
> early php code.
>
> 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.
> %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
>
--
Dan Taylor
Software Development Engineer, JTL Systems Ltd
PhD Student, Reading University, UK
http://www.logicalgenetics.com
More information about the MapServer-users
mailing list