File: test_writeshape.phtml

package info (click to toggle)
mapserver 5.6.5-2%2Bsqueeze3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 15,900 kB
  • ctags: 25,593
  • sloc: ansic: 201,813; cpp: 49,629; cs: 11,792; python: 5,233; perl: 3,249; sh: 1,199; makefile: 884; lex: 592; java: 466; xml: 373; yacc: 334; tcl: 158; ruby: 53
file content (56 lines) | stat: -rwxr-xr-x 1,379 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?
//
// 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>";



?>