1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace PrinsFrank\PhpGeoSVG\Geometry\Position; |
5
|
|
|
|
6
|
|
|
use PrinsFrank\PhpGeoSVG\Exception\InvalidPositionException; |
7
|
|
|
|
8
|
|
|
class Position |
9
|
|
|
{ |
10
|
|
|
public const MIN_LONGITUDE = -180; |
11
|
|
|
public const MAX_LONGITUDE = 180; |
12
|
|
|
public const LONGITUDE_THRESHOLD = 1; |
13
|
|
|
public const TOTAL_LONGITUDE = self::MAX_LONGITUDE - self::MIN_LONGITUDE; |
14
|
|
|
|
15
|
|
|
public const MIN_LATITUDE = -90; |
16
|
|
|
public const MAX_LATITUDE = 90; |
17
|
|
|
public const LATITUDE_THRESHOLD = 1; |
18
|
|
|
public const TOTAL_LATITUDE = self::MAX_LATITUDE - self::MIN_LATITUDE; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* The coordinate reference system for all GeoJSON coordinates is a |
22
|
|
|
* geographic coordinate reference system, using the World Geodetic |
23
|
|
|
* System 1984 (WGS 84) [WGS84] datum, with longitude and latitude units |
24
|
|
|
* of decimal degrees. This is equivalent to the coordinate reference |
25
|
|
|
* system identified by the Open Geospatial Consortium (OGC) URN |
26
|
|
|
* urn:ogc:def:crs:OGC::CRS84. An OPTIONAL third-position element SHALL |
27
|
|
|
* be the height in meters above or below the WGS 84 reference |
28
|
|
|
* ellipsoid. In the absence of elevation values, applications |
29
|
|
|
* sensitive to height or depth SHOULD interpret positions as being at |
30
|
|
|
* local ground or sea level |
31
|
|
|
* |
32
|
|
|
* @throws InvalidPositionException |
33
|
|
|
*/ |
34
|
6 |
|
public function __construct(public float $longitude, public float $latitude, public ?float $elevation = null) |
35
|
|
|
{ |
36
|
6 |
|
if ($this->longitude > (static::MAX_LONGITUDE + static::LONGITUDE_THRESHOLD) || $this->longitude < (static::MIN_LONGITUDE - static::LONGITUDE_THRESHOLD)) { |
37
|
2 |
|
throw new InvalidPositionException('The longitude should be between ' . static::MIN_LONGITUDE . ' and ' . static::MAX_LONGITUDE . ', "' . $this->longitude . '" provided.'); |
38
|
|
|
} |
39
|
|
|
|
40
|
4 |
|
if ($this->latitude > (static::MAX_LATITUDE + static::LATITUDE_THRESHOLD) || $this->latitude < (static::MIN_LATITUDE - static::LATITUDE_THRESHOLD)) { |
41
|
2 |
|
throw new InvalidPositionException('The latitude should be between ' . static::MIN_LATITUDE . ' and ' . static::MAX_LATITUDE . ', "' . $this->latitude . '" provided.'); |
42
|
|
|
} |
43
|
2 |
|
} |
44
|
|
|
|
45
|
1 |
|
public function hasElevation(): bool |
46
|
|
|
{ |
47
|
1 |
|
return $this->elevation !== null && $this->elevation !== 0.0; |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|