PhP Mapscript

Dan Barron dbarron at DSWLLC.COM
Tue Mar 15 10:44:42 EST 2005


Thomas,

Here's some info to hopefully help you get to drawing your points.  You
need a "dummy" layer in your map file and a point symbol (many ways to draw
a symbol - I show the use of a gif file defined in the sysmbols.list
file).  The PHP I show is excerpts from a much larger script, so I do not
guarantee it will work exactly as written, but should give you an idea of
the basics steps so you can find your way to drawing the point layer in php
mapscript.  This is also from php mapscript that is a couple revs back,
things may have changed slightly in some of these commands, so be sure to
verify them against current php mapscript documentation.

hth,

Dan


<< excerpts from map file >>

symbolset "./symbols/symbols.list"

LAYER
   NAME 'Points'
   TYPE POINT
   STATUS ON
   CLASS
     name 'points'
     style
       SYMBOL 'point'
     end
   END
END


<< excerpt from symbol.list file >>

SYMBOL
   NAME 'point'
   TYPE PIXMAP
   IMAGE 'point.gif'
END


<< excerpt from php mapscript >>

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  * Get the MAPSERVER MAP FILE and create NEW MAP OBJECT
  *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
   $map = ms_newMapObj($mapPath.$mapFile);
   $image=$map->draw();
   $layer =  $map->getLayerByName( "Points" );

   $results = queryDBase( $dbaseInfo, $table, $where, $map );

   // 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, "");
   } //end while()

   $layer->draw($image);
   $image_url_PNG=$image->saveWebImage();


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// queryDBase - query the database for point within the current extent
//
// $dbaseInfo - array holding host, user, pwd, dbase, and table info for
the database query
// $table - table to query for layer in database
// $where - additional where clause info for the select query
// $map - current map object to determine current map extents
//
// returns $result - the query results
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function queryDBase( $dbaseInfo, $table, $where, $map ) {

   $lf = " \n";
   $method = "[queryDBase]";

   // Connect to mySQL database then select the database to use.
   $link = mysql_connect($dbaseInfo["host"], $dbaseInfo["user"],
$dbaseInfo["pwd"] )
     or die("Could not connect to mySQL");
   mysql_select_db($dbaseInfo["dbase"])
     or die("Could not select database");

   // Set query string - query for points only in current extent
   $queryStr = "SELECT * FROM ".$table.
               " WHERE latitude < ".$map->extent->maxy.
               " AND latitude > ".$map->extent->miny.
               " AND longitude < ".$map->extent->maxx.
               " AND longitude > ".$map->extent->minx.
                    $where;

         fwrite( $file, $lf.$method."DEBUG: queryStr= ".$queryStr);

   // perform query, then close database link
         $result = mysql_query($queryStr) or die("Query failed");
         $numRows = mysql_num_rows( $result );
         mysql_close($link);

         return $result;
}




At 03:41 AM 3/15/2005, you wrote:
>Hi Dan,
>
>Firstly forgive me, I found your email in a post from 2003.
>
>Do you have any example of using PHP mapscript to retrieve a list of lat
>longs from a mysql (or any) database and add as a layer to a map file
>?  My expertise is in c, .net and java, so a quick example will save me
>tons of time.
>
>Many Thanks in advance.
>Thomas
>
>Ps
>This is the link I found.
>http://lists.gis.umn.edu/pipermail/mapserver-users/2003-April/003034.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapserver-users/attachments/20050315/e13b6525/attachment.html


More information about the mapserver-users mailing list