[Mapserver-users] create and display point obj on the fly

Lionel Bargeot l.bargeot at educagri.fr
Mon Feb 3 15:47:51 EST 2003


Hi

I run mapserver 3.6.4 with php_mapscript and php 4.2.3

I have a database of 3000 point (agriculture school in France), and I
would like to produce approriate maps of special requests on the
database (a postgresql database).
I have a shapefile of my points with a unique identifier of the point in
the attribute dbf file.

I've tried to produce results with the setExpression method on a class.
It works but it's very long. For hundred points (resulting from a query)
I have to wait a minute to display the map. Of course, during this time,
mapserver compare each Id of the dbf file to the result of the query.
More I have results, more my Expression string applied to the class is
long, more I have to wait.

So I'm looking for another solution. I bielived that produce a single
class with a simple expression for each result could work, but there is
a limitation on the number of class I can produce in Mapserver, isn't it
? (~50).

So my last chance is perhap's to store X Y coordinates in the database,
add them with a SQL join query to the result, and produce dinamicaly
points on the fly. I've tried something like this

-----------------------------------
// first I use a defined mapfile with no layer in
$map = ms_newMapObj("etc/etabagri.map");
// I create a layer
$layer_req=ms_newLayerObj($map);
$layer_req->set(name, "requete");
$layer_req->set(status, MS_ON);
$layer_req->set(name, "requete");
$layer_req->set(type, POINT);
// I create a class in this layer
$class_req=ms_newClassObj($layer_req);
$class_req->set(name, "requete2");
$class_req->set(status, MS_ON);
$class_req->set(symbol, "tent");
$class_req->set(symbolname, "tent");
$class_req->set(size, 12);
$class_req->set(color, $map->addColor(255, 255, 0));
// I create an image of the curent map at this state
$image=$map->draw();
// I connect to the pg database and apply a query
$conn = pg_connect("dbname host user password port");
$Query="select * from coord LIMIT 100";
//where coord is a table with ID, X, Y fields
// for testing, I limit the record output to 100
$Res = pg_exec ($conn, $Query); $iNbr = pg_numrows($Res);
// for each point in the result I try to draw it on image
for ($i = 0; $i < $iNbr; $i++) {
	$Lign = pg_fetch_array($Res, $i); 
	$pointobj = ms_newPointObj();
	$pointobj->setXY($Lign["X"],$Lign["Y"],$Lign["ID"]);
	$pointobj->draw($map,$layer_req,$image,$class_req, $string);
	$pointobj->free();
}
--------------------------------------
But nothing appears. I verifyed query results in an html table, it's ok.
I've tried with a single point, it doesn't work.

Has someone already tryed to do something like this ? Have i to create a
shapfile of each result and then display it ? Can I produce a map of
point without create/use a shapefile ?


Thanks any help

Lionel

-- 
AgrogeomaTIC
CNERTA-ENESAD, 4 rue champs-prevois, batiment grand-champs, 21000 Dijon
03.80.77.28.49
http://stb.educagri.fr




More information about the mapserver-users mailing list