ShapefileObj ?

Daniel Morissette danmo at videotron.ca
Wed Aug 23 15:42:42 EDT 2000


"Doyon, Jean-Francois" wrote:
> 
> Hello everyone, it's me again :)
> 
> I was wondering if the the ms_newShapefileObj (PHP/Mapscript) only supports
> shapes .(shp,.shx), or also attributes (.dbf) ?
> 

Hello JF, me again!  :)

MapServer concentrates on the geographical stuff... you have to use the
PHP DBase module to create your DBF file.  On Windows there is a
PHP3_DBASE.DLL that you can load, and on Unix you have to configure PHP
with the --with-dbase switch before you compile it.

> 
> And even then, when I add a shape, I won't know or have the index value, so
> that maybe I could use the PHP
> built in DBase routines to handle the attribute part ... Meaning I can't
> maintain the relationship between a shape
> and it's attributes ...
> 

It's simple... every time you write a shape, write a record to the DBF
file and you'll be OK.

> Has anybody come across this type of scenario ? Any suggestions on how best
> to proceed ?

I attached at the end of this message a small PHP script that creates a
SHP file and the corresponding DBF records.

(Humm... I think this could be a nice one to include in the examples
directory in the PHP source code distribution... I'll add it now.)

-- 
------------------------------------------------------------
 Daniel Morissette                       danmo at videotron.ca
              http://pages.infinit.net/danmo/
------------------------------------------------------------
  Don't put for tomorrow what you can do today, because if 
      you enjoy it today you can do it again tomorrow.
-------------- next part --------------
<?

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

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



?>
 






More information about the mapserver-users mailing list