[mapserver-users] help with dynamic layer

Dylan Keon keon at nacse.org
Thu Jul 25 13:58:28 EDT 2002


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
################################################################




More information about the mapserver-users mailing list