[mapserver-users] Drawing features dynamically

Dan Barron dbarron at ddive.com
Tue Mar 19 13:02:03 EST 2002


Hi Ricardo,

Below is a function that will take the results from a query to mySQL and 
draw the points on a the specified layer.  I have tested this with up to 
10K points on a W2K machine with mySQL & Apache and it works fine.

Hope this helps.

Dan Barron
Destination Software LLC
San Diego, CA, USA

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// drawPoints - take the database query results and draw the points on the 
map layer
//
// $results - results of the database query
// $layerName - name of the layer to draw on image
//
// return True or False
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function drawPoints( $results, $layerName ) {

   GLOBAL $map;
         GLOBAL $image;

         $layer =  $map->getLayerByName( $layerName );

   // Loop through result of point query and:
   while ($line = mysql_fetch_array($results, MYSQL_ASSOC)) {
                 $pt = ms_newPointObj();
                 $pt->setXY( $line["longitude"], $line["latitude"] );

                 $pt->draw($map, $layer, $image, 0, "TEST");
                 $layer->set('status', MS_ON);
                 $layer->draw($image);
         }

         return True;
}


At 03:57 PM 3/18/2002 -0300, Ricardo Scachetti Pereira wrote:
>     Does anyone know how to draw features (points, lines and polygons)
>dynamically over a base map using Perl or PHP mapscript?
>     I would like to draw data points coming from disparate (remote) data
>sources, which are providing data as a XML documents. Each document can
>contain a large number of features (thousands). I would like to avoid
>writing individual shapefiles for each dataset, just to display them. I
>would like to know if mapserver has any built in mechanism to display
>dynamic features, besides the one described on the CGI documentation
>(which is designed to handle small amounts of data).
>     I've been exploring the pointObj and its methods (especially the
>draw() method), because it seems to be developed to implement the kind
>of feature I'm looking for. However, I couldn't write anything that does
>what I want. Mostly, I get segmentation fault errors. Does anyone know
>any sample scripts that draw points using this object?
>
>Ricardo
>
>
>--
>Ricardo Scachetti Pereira
>Gerente de Pesquisa
>Centro de Referência em Informação Ambiental - CRIA
>http://www.cria.org.br/




More information about the mapserver-users mailing list