1
|
|
|
<?php |
2
|
|
|
use ShapeFile\ShapeFile; |
3
|
|
|
use ShapeFile\ShapeRecord; |
4
|
|
|
|
5
|
|
|
class ShapeFileTest extends PHPUnit_Framework_TestCase |
|
|
|
|
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* Tests loading of a file |
9
|
|
|
* |
10
|
|
|
* @param string $filename Name of file |
11
|
|
|
* @param integer $records Expected number of records |
12
|
|
|
* @param integer $parts Expected number of parts in first record |
13
|
|
|
* |
14
|
|
|
* @return void |
15
|
|
|
* |
16
|
|
|
* @dataProvider provideFiles |
17
|
|
|
*/ |
18
|
|
|
public function testLoad($filename, $records, $parts) |
19
|
|
|
{ |
20
|
|
|
$shp = new ShapeFile(1); |
21
|
|
|
$shp->loadFromFile($filename); |
22
|
|
|
$this->assertEquals($records, count($shp->records)); |
23
|
|
|
if (!is_null($parts)) { |
24
|
|
|
$this->assertEquals($parts, count($shp->records[0]->SHPData["parts"])); |
25
|
|
|
} |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Data provider for file loading tests. |
30
|
|
|
* |
31
|
|
|
* @return array |
32
|
|
|
*/ |
33
|
|
|
public function provideFiles() |
34
|
|
|
{ |
35
|
|
|
return array( |
36
|
|
|
array('data/capitals.*', 652, null), |
37
|
|
|
array('data/mexico.*', 32, 3), |
38
|
|
|
array('data/Czech_Republic_AL2.*', 1, 1), |
39
|
|
|
); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Tests creating file |
44
|
|
|
* |
45
|
|
|
* @return void |
46
|
|
|
*/ |
47
|
|
|
public function testCreate() |
48
|
|
|
{ |
49
|
|
|
$shp = new ShapeFile(1); |
50
|
|
|
|
51
|
|
|
$record0 = new ShapeRecord(1); |
52
|
|
|
$record0->addPoint(array("x" => 482131.764567, "y" => 2143634.39608)); |
53
|
|
|
|
54
|
|
|
$record1 = new ShapeRecord(1); |
55
|
|
|
$record1->addPoint(array("x" => 472131.764567, "y" => 2143634.39608)); |
56
|
|
|
|
57
|
|
|
$record2 = new ShapeRecord(1); |
58
|
|
|
$record2->addPoint(array("x" => 492131.764567, "y" => 2143634.39608)); |
59
|
|
|
|
60
|
|
|
$shp->addRecord($record0); |
61
|
|
|
$shp->addRecord($record1); |
62
|
|
|
$shp->addRecord($record2); |
63
|
|
|
|
64
|
|
|
$shp->setDBFHeader( |
65
|
|
|
array( |
66
|
|
|
array('ID', 'N', 8, 0), |
67
|
|
|
array('DESC', 'C', 50, 0) |
68
|
|
|
) |
69
|
|
|
); |
70
|
|
|
|
71
|
|
|
$shp->records[0]->DBFData['ID'] = '1'; |
72
|
|
|
$shp->records[0]->DBFData['DESC'] = 'AAAAAAAAA'; |
73
|
|
|
|
74
|
|
|
$shp->records[1]->DBFData['ID'] = '2'; |
75
|
|
|
$shp->records[1]->DBFData['DESC'] = 'BBBBBBBBBB'; |
76
|
|
|
|
77
|
|
|
$shp->records[2]->DBFData['ID'] = '3'; |
78
|
|
|
$shp->records[2]->DBFData['DESC'] = 'CCCCCCCCCCC'; |
79
|
|
|
|
80
|
|
|
$shp->saveToFile('./data/test_shape.*'); |
81
|
|
|
|
82
|
|
|
$shp = new ShapeFile(1); |
83
|
|
|
$shp->loadFromFile('./data/test_shape.*'); |
84
|
|
|
$this->assertEquals(3, count($shp->records)); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.