|
2 | 2 |
|
3 | 3 | namespace MStaack\LaravelPostgis\Geometries; |
4 | 4 |
|
5 | | -use Countable; |
6 | | -use InvalidArgumentException; |
7 | | - |
8 | | -class MultiLineString extends Geometry implements Countable |
| 5 | +class MultiLineString extends LineStringCollection |
9 | 6 | { |
10 | | - /** |
11 | | - * @var LineString[] |
12 | | - */ |
13 | | - protected $linestrings = []; |
14 | | - |
15 | | - /** |
16 | | - * @param LineString[] $linestrings |
17 | | - */ |
18 | | - public function __construct(array $linestrings) |
19 | | - { |
20 | | - if (count($linestrings) < 1) { |
21 | | - throw new InvalidArgumentException('$linestrings must contain at least one entry'); |
22 | | - } |
23 | | - |
24 | | - $validated = array_filter($linestrings, function ($value) { |
25 | | - return $value instanceof LineString; |
26 | | - }); |
27 | | - |
28 | | - if (count($linestrings) !== count($validated)) { |
29 | | - throw new InvalidArgumentException('$linestrings must be an array of Points'); |
30 | | - } |
31 | | - |
32 | | - $this->linestrings = $linestrings; |
33 | | - } |
34 | | - |
35 | | - public function getLineStrings() |
36 | | - { |
37 | | - return $this->linestrings; |
38 | | - } |
39 | | - |
40 | | - public function is3d() |
41 | | - { |
42 | | - if (count($this->linestrings) === 0) return false; |
43 | | - return $this->linestrings[0]->is3d(); |
44 | | - } |
45 | | - |
46 | 7 | public function toWKT() |
47 | 8 | { |
48 | 9 | $wktType = 'MULTILINESTRING'; |
49 | 10 | if ($this->is3d()) $wktType .= ' Z'; |
50 | 11 | return sprintf('%s(%s)', $wktType, (string)$this); |
51 | 12 | } |
52 | 13 |
|
53 | | - public static function fromString($wktArgument) |
54 | | - { |
55 | | - $str = preg_split('/\)\s*,\s*\(/', substr(trim($wktArgument), 1, -1)); |
56 | | - $linestrings = array_map(function ($data) { |
57 | | - return LineString::fromString($data); |
58 | | - }, $str); |
59 | | - |
60 | | - |
61 | | - return new static($linestrings); |
62 | | - } |
63 | | - |
64 | | - public function __toString() |
65 | | - { |
66 | | - return implode(',', array_map(function (LineString $linestring) { |
67 | | - return sprintf('(%s)', (string)$linestring); |
68 | | - }, $this->getLineStrings())); |
69 | | - } |
70 | | - |
71 | | - public function count() |
72 | | - { |
73 | | - return count($this->linestrings); |
74 | | - } |
75 | | - |
76 | 14 | /** |
77 | 15 | * Convert to GeoJson Point that is jsonable to GeoJSON |
78 | 16 | * |
79 | 17 | * @return \GeoJson\Geometry\MultiLineString |
80 | 18 | */ |
81 | | - public function jsonSerialize() |
| 19 | + public function jsonSerialize(): \GeoJson\Geometry\MultiLineString |
82 | 20 | { |
83 | 21 | $linestrings = []; |
84 | 22 |
|
|
0 commit comments