forked from MapServer/MapServer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_writeshape.phtml
More file actions
56 lines (41 loc) · 1.35 KB
/
test_writeshape.phtml
File metadata and controls
56 lines (41 loc) · 1.35 KB
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>";
?>