[mapserver-users] Shapefiles - different formats?

Hankley, Chip Chip.Hankley at GASAI.Com
Mon Oct 15 12:39:00 EDT 2001


Janet -

Here's a little PHP/MapScript routine (taken almost totally from the mail
archives) that creates three triangles (polylines NOT polygons).

Note that the $shpFname variable would most likely need to be changed,
depending on your setup.

I'm able to view the resulting shapefile in both 3.2a and ArcMap (8.0.2). I
am not creating ANY projection files.

Cheers!

Chip
 
<?
//----------------------------------------------------------
// produce shapefile
//----------------------------------------------------------
$shpFname = "C:\\Inetpub\\wwwroot\\tmp\\shptest";
$shpFile = ms_newShapeFileObj($shpFname, MS_SHP_ARC);
$def =  array(array("PROG_ID", "N", 5, 0));

$dbfFile = dbase_create($shpFname . ".dbf", $def);

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>";

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

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

    // Create shape
    $oShp = ms_newShapeObj(MS_SHP_ARC);
    $oLine = ms_newLineObj();
    //Add some points to the line then close it on itself
    $oLine->addXY($x, $y);  
    $oLine->addXY($x + 10, $y + 10);
    $oLine->addXY($x + 10, $y + 40);
    $oLine->addXY($x, $y);
    $oShp->add( $oLine );
    $shpFile->addShape($oShp);

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



More information about the mapserver-users mailing list