<?
//
// This example script shows how MapScript and the PHP DBase module
// can be used to create new Shapefile datasets.
//
// The optional DBase module must be loaded for this to work:
//  - On Windows, use dl("php3_dbase.dll")
//  - On Unix, configure PHP with the --with-dbase switch and recompile it.
//

// Load MapScript
dl("php_mapscript.so");

//----------------------------------------------------------
// produce shapefile
//----------------------------------------------------------

function createPoint( $x, $y, $programId )
{
    GLOBAL $shpFile, $dbfFile;

    // Create shape
    $oShp = ms_newShapeObj(MS_SHP_POINT);
    $oLine = ms_newLineObj();
    $oLine->addXY($x, $y);
    $oShp->add( $oLine );
    $shpFile->addShape($oShp);

    // Write attribute record
    dbase_add_record($dbfFile, array($programId));
}

$shpFname = "/tmp/shptest";
$shpFile = ms_newShapeFileObj( $shpFname, MS_SHP_POINT);
$dbfFile = dbase_create( $shpFname.".dbf", array(array("PROG_ID", "N", 5, 0)));

createPoint( 12, 34, 111);
createPoint( 22, 14, 222);
createPoint( 10, 20, 333);

echo "Shapes Created.<BR>";

//----------------------------------------------------------
// done... cleanup
//----------------------------------------------------------

$shpFile->free();
echo "Shape File ($shpFname) closed.<BR>";

dbase_close($dbfFile);
echo "Dbase file closed.<BR>";



?>
 
