Drawing the point on the map and adding it to shapefile

Camden Daily cdaily at GMAIL.COM
Thu Mar 31 10:29:19 EST 2005


Here's some example code of how I create a shapefile from my database
information.  It's probably not exactly what you need, but it'll give
you a good start.  Note that if you want to interact with .dbf files
in PHP, you'll need to compile PHP with the --enable-dbase option.

In this snippet, I create a new shapefile and dbf file, but you could
probably just as easily open existing ones.

$shapefile = ms_newShapefileObj("fire_station", MS_SHP_POINT);
$dbffile = dbase_create("fire_station.dbf", array(array("NAME", "C",
50), array("ADDRESS", "C", 50)));

$sql = "SELECT DISTINCT fire_station.name, address.street_1,
address.longitude, address.latitude
          FROM fire_station
          JOIN address ON address_id=address.id";

$rs = $db->execute($sql);

foreach($rs as $result) {
  $point = ms_newPointObj();
  $point->setXY($result[2], $result[3]);
  $shapefile->addPoint($point);
  dbase_add_record($dbffile, array($result[0], $result[1]));
}

$shapefile->free();



More information about the mapserver-users mailing list