[mapserver-users] help with dynamic layer
Lowell Filak
lfilak at medinaco.org
Mon Jul 29 06:47:11 PDT 2002
DATA should not need defined directly in the mapfile but rather via mapscript once the value of DATA is actually known. The mapfile could contain a place-holder for the layer but that is not required either as it can all be done directly from within mapscript.
Lowell F.
The following message was sent by Dylan Keon <keon at nacse.org> on Fri, 26 Jul 2002 12:16:44 -0700.
> Thanks! That did the trick.
>
> One more question...It seems like the other way to add a dynamic layer
> is to actually generate a new shapefile (and dbf file) from the database
> query resultset, add it to a map object, and draw it. Is one method
> more robust than the other? Any reason to not do it the way I'm doing
> it, other than the "obscuring" problem you mentioned?
>
> I think the shapefile-generation method is what Lowell was hinting at.
> In that case, you would need DATA defined for that layer in your map
> file (right?)
>
> Thanks,
> Dylan
>
> woodbri at swoodbridge.com wrote:
> > Dylan,
> >
> > Try something like this:
> >
> > // MapObj and ImageObj settings
> > $map_path="/www/gis/mapfiles/";
> > $map = ms_newMapObj($map_path."test.map");
> > $img = $map->draw();
> >
> > $layer = $map->getLayerByName("sites2");
> > $layer->set('status', MS_ON);
> > for ($i=0; $i<$rows; ++$i) {
> > $row = pg_fetch_row($result, $i);
> > // echo "Record $i: UTM_E $row[0], UTM_N $row[1]<br>";
> > $pt = ms_newPointObj();
> > $pt->setXY($row[0],$row[1]);
> > $pt->draw($map, $layer, $img, 0, "TEST");
> > }
> >
> > $img_url=$img->saveWebImage(MS_PNG,1,1,0);
> >
> > When you are using this style of adding objects to the map
> > dynamically you have to draw the map first THEN add you dynamic data
> > on top of the already rendered map.
> >
> > This method has the problem that if you have a high density of
> > objects to add to the map it can obscure the underlining map. You
> > also might want to set LABELCACHE FALSE for the layer.
> >
> > -Steve
> >
> > On 26 Jul 2002 at 11:29, Lowell.Filak wrote:
> >
> >
> >>I think there may be a couple of things missing.
> >>I don't see where the "data" value is set for the layer & I don't see
> >>where the addPoint is being done to add the point(s) to the data shapefile
> >>before rendering the layer.
> >>Lowell F.
> >>
> >>On Thu, 25 Jul 2002, Dylan Keon wrote:
> >>
> >>
> >>>Hi,
> >>>
> >>>I'm trying to create a dynamic point layer using PHP Mapscript. A
> >>>simple query to a Postgres database returns the UTM coordinates. That
> >>>part works fine. What isn't working is the rendering of the layer. I
> >>>read through the various "dynamic layer" posts in the archives, but
> >>>still couldn't figure it out. This is my first Mapscript attempt :-)
> >>>I'm sure it's a simple error (or errors) on my part.
> >>>
> >>>The PHP code, map file, and error messages are below. Any tips would be
> >>>great. Thanks!
> >>>
> >>>Dylan
> >>>
> >>>###################### PHP and HTML code ######################
> >>><?php
> >>>
> >>>dl('php_mapscript.so');
> >>>
> >>>// db connect parameters
> >>>$host = "localhost";
> >>>$user = "xxxxx";
> >>>$pass = "xxxxx";
> >>>$db = "xxxxx";
> >>>
> >>>// open a connection to the db server
> >>>$connection = pg_connect("host=$host dbname=$db user=$user password=$pass");
> >>>
> >>>if (!$connection) {
> >>> die("Could not open connection to database server");
> >>>}
> >>>
> >>>// generate and execute the query
> >>>$query = "SELECT utm_e, utm_n FROM sites";
> >>>$result = pg_exec($connection, $query) or die("Error in query: $query. "
> >>>. pg_last_error($connection));
> >>>
> >>>// get the number of rows in the resultset
> >>>$rows = pg_numrows($result);
> >>>
> >>>// MapObj and ImageObj settings
> >>>$map_path="/www/gis/mapfiles/";
> >>>$map = ms_newMapObj($map_path."test.map");
> >>>$img = $map->prepareImage();
> >>>
> >>>// get dummy layer
> >>>$layer = $map->getLayerByName("sites2");
> >>>
> >>>// loop through resultset, generating points
> >>>for ($i=0; $i<$rows; ++$i) {
> >>> $row = pg_fetch_row($result, $i);
> >>>// echo "Record $i: UTM_E $row[0], UTM_N $row[1]<br>";
> >>> $pt = ms_newPointObj();
> >>> $pt->setXY($row[0],$row[1]);
> >>> $pt->draw($map, $layer, $img, 0, "TEST");
> >>> $layer->set('status', MS_ON);
> >>> $layer->draw($img);
> >>>}
> >>>
> >>>// create web image
> >>>$img=$map->draw();
> >>>$img_url=$img->saveWebImage(MS_PNG,1,1,0);
> >>>
> >>>// close database connection
> >>>pg_close($connection);
> >>>
> >>>?>
> >>>
> >>><html>
> >>><head>
> >>><title>Test Map</title>
> >>></head>
> >>><body>
> >>><table align="center">
> >>><tr><td>
> >>><input type="image" name="test_map" src="<?php echo $img_url?>">
> >>></td></tr>
> >>></table>
> >>></body>
> >>></html>
> >>>################################################################
> >>>
> >>>########################### map file ###########################
> >>>NAME TEST
> >>>SIZE 600 400
> >>>STATUS ON
> >>>SYMBOLSET "/www/gis/symbols/symbols.sym"
> >>>EXTENT 370000 4640000 1011000 5130000 #minx miny maxx maxy
> >>>UNITS METERS
> >>>SHAPEPATH "/usr/local/gis_data/state"
> >>>IMAGETYPE PNG
> >>>
> >>>WEB
> >>> IMAGEPATH "/www/tmp/"
> >>> IMAGEURL "/tmp/"
> >>>END
> >>>
> >>>LAYER
> >>> NAME boundary
> >>> DATA bnd
> >>> TYPE polygon
> >>> STATUS DEFAULT
> >>> CLASS
> >>> NAME "State boundary"
> >>> OUTLINECOLOR 0 0 0
> >>> COLOR -1 -1 -1
> >>> END
> >>>END
> >>>
> >>>LAYER
> >>> NAME sites2
> >>> TYPE POINT
> >>> STATUS OFF
> >>> CLASS
> >>> COLOR 255 255 0
> >>> OUTLINECOLOR 0 0 0
> >>> SYMBOL 7
> >>> SIZE 8
> >>> END
> >>>END
> >>>
> >>>END
> >>>################################################################
> >>>
> >>>####################### Error messages #########################
> >>>Warning: MapServer Error in msGetBitmapFont(): Invalid bitmap font. Must
> >>>be one of tiny, small, medium, large or giant. in
> >>>/usr/local/etc/httpd/htdocs/test.php on line 47
> >>>
> >>>Fatal error: Call to a member function on a non-object in
> >>>/usr/local/etc/httpd/htdocs/test.php on line 48
> >>>################################################################
> >>>
> >>
> >>
> >
> >
>
>
> --
> ************************************************
> Dylan Keon
> GIS/Database Research Specialist
> Northwest Alliance for Computational
> Science and Engineering (NACSE)
> Oregon State University
> Corvallis, OR 97331
> keon at nacse.org (541) 737-6608
> ************************************************
More information about the MapServer-users
mailing list