1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Geotools library. |
5
|
|
|
* |
6
|
|
|
* (c) Antoine Corcy <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace League\Geotools\Coordinate; |
13
|
|
|
|
14
|
|
|
use League\Geotools\ArrayCollection; |
15
|
|
|
use League\Geotools\Exception\InvalidArgumentException; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @author Gabriel Bull <[email protected]> |
19
|
|
|
*/ |
20
|
|
|
class CoordinateCollection extends ArrayCollection |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var Ellipsoid |
24
|
|
|
*/ |
25
|
|
|
private $ellipsoid; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* CoordinateCollection constructor. |
29
|
|
|
* |
30
|
|
|
* @param CoordinateInterface[] $coordinates |
31
|
|
|
* @param Ellipsoid $ellipsoid |
32
|
|
|
*/ |
33
|
34 |
|
public function __construct(array $coordinates = array(), Ellipsoid $ellipsoid = null) |
34
|
|
|
{ |
35
|
34 |
|
if ($ellipsoid) { |
36
|
4 |
|
$this->ellipsoid = $ellipsoid; |
37
|
34 |
|
} elseif (count($coordinates) > 0) { |
38
|
13 |
|
$this->ellipsoid = reset($coordinates)->getEllipsoid(); |
39
|
|
|
} |
40
|
|
|
|
41
|
34 |
|
$this->checkCoordinatesArray($coordinates); |
42
|
|
|
|
43
|
34 |
|
parent::__construct($coordinates); |
44
|
34 |
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param string $key |
48
|
|
|
* @param CoordinateInterface $value |
49
|
|
|
*/ |
50
|
16 |
|
public function set($key, $value) |
51
|
|
|
{ |
52
|
16 |
|
$this->checkEllipsoid($value); |
53
|
16 |
|
$this->elements[$key] = $value; |
54
|
16 |
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param CoordinateInterface $value |
58
|
|
|
* @return bool |
59
|
|
|
*/ |
60
|
2 |
|
public function add($value) |
61
|
|
|
{ |
62
|
2 |
|
$this->checkEllipsoid($value); |
63
|
2 |
|
$this->elements[] = $value; |
64
|
|
|
|
65
|
2 |
|
return true; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return Ellipsoid |
70
|
|
|
*/ |
71
|
17 |
|
public function getEllipsoid() |
72
|
|
|
{ |
73
|
17 |
|
return $this->ellipsoid; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @param array CoordinateInterface[] $coordinates |
78
|
|
|
*/ |
79
|
34 |
|
private function checkCoordinatesArray(array $coordinates) |
80
|
|
|
{ |
81
|
34 |
|
foreach ($coordinates as $coordinate) { |
82
|
15 |
|
$this->checkEllipsoid($coordinate); |
83
|
|
|
} |
84
|
34 |
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param CoordinateInterface $coordinate |
88
|
|
|
* |
89
|
|
|
* @throws InvalidArgumentException |
90
|
|
|
*/ |
91
|
30 |
|
private function checkEllipsoid(CoordinateInterface $coordinate) |
92
|
|
|
{ |
93
|
30 |
|
if ($this->ellipsoid === null) { |
94
|
17 |
|
$this->ellipsoid = $coordinate->getEllipsoid(); |
95
|
|
|
} |
96
|
|
|
|
97
|
30 |
|
if ($coordinate->getEllipsoid() != $this->ellipsoid) { |
98
|
|
|
throw new InvalidArgumentException("Ellipsoids don't match"); |
99
|
|
|
} |
100
|
30 |
|
} |
101
|
|
|
} |
102
|
|
|
|