1 | <?php |
||
2 | |||
3 | /** |
||
4 | * PHPCoord. |
||
5 | * |
||
6 | * @author Doug Wright |
||
7 | */ |
||
8 | declare(strict_types=1); |
||
9 | |||
10 | namespace PHPCoord\Point; |
||
11 | |||
12 | use DateTimeInterface; |
||
13 | use PHPCoord\CoordinateReferenceSystem\Compound; |
||
14 | use PHPCoord\CoordinateReferenceSystem\Geocentric; |
||
15 | use PHPCoord\CoordinateReferenceSystem\Geographic2D; |
||
16 | use PHPCoord\CoordinateReferenceSystem\Geographic3D; |
||
17 | use PHPCoord\CoordinateReferenceSystem\Projected; |
||
18 | use PHPCoord\CoordinateReferenceSystem\Vertical; |
||
19 | use PHPCoord\CoordinateSystem\Cartesian; |
||
20 | use PHPCoord\Geometry\BoundingArea; |
||
21 | use PHPCoord\Geometry\LinearRing; |
||
22 | use PHPCoord\Geometry\Polygon; |
||
23 | use PHPCoord\Geometry\Position; |
||
24 | use PHPCoord\Geometry\RegionMap; |
||
25 | use PHPCoord\UnitOfMeasure\Length\Length; |
||
26 | |||
27 | use function str_replace; |
||
28 | |||
29 | class UTMPoint extends ProjectedPoint |
||
30 | { |
||
31 | public const HEMISPHERE_NORTH = 'N'; |
||
32 | |||
33 | public const HEMISPHERE_SOUTH = 'S'; |
||
34 | |||
35 | /** |
||
36 | * Zone number. |
||
37 | */ |
||
38 | protected int $zone; |
||
39 | |||
40 | /** |
||
41 | * Hemisphere (N or S). |
||
42 | */ |
||
43 | protected string $hemisphere; |
||
44 | |||
45 | /** |
||
46 | * Base CRS. |
||
47 | * @deprecated use $this->crs->getBaseCRS() |
||
48 | */ |
||
49 | protected Geographic2D|Geographic3D $baseCRS; |
||
50 | 72 | ||
51 | public function __construct(Geographic2D|Geographic3D $crs, Length $easting, Length $northing, int $zone, string $hemisphere, ?DateTimeInterface $epoch = null) |
||
52 | 72 | { |
|
53 | 72 | $this->zone = $zone; |
|
54 | 72 | $this->hemisphere = $hemisphere; |
|
55 | $this->baseCRS = $crs; |
||
0 ignored issues
–
show
|
|||
56 | 72 | ||
57 | 72 | $longitudeOrigin = $zone * 6 - 3; |
|
58 | 54 | if ($hemisphere === self::HEMISPHERE_NORTH) { |
|
59 | 54 | $boundingArea = BoundingArea::createFromPolygons( |
|
60 | 54 | [ |
|
61 | 54 | new Polygon( |
|
62 | 54 | new LinearRing( |
|
63 | 54 | new Position($longitudeOrigin, 0), |
|
64 | 54 | new Position($longitudeOrigin, 90), |
|
65 | 54 | new Position($longitudeOrigin + 6, 90), |
|
66 | 54 | new Position($longitudeOrigin + 6, 0), |
|
67 | 54 | new Position($longitudeOrigin, 0), |
|
68 | 54 | ) |
|
69 | 54 | ), |
|
70 | 54 | ], |
|
71 | 54 | RegionMap::REGION_GLOBAL |
|
72 | 54 | ); |
|
73 | $derivingConversion = 'urn:ogc:def:coordinateOperation:EPSG::' . ($zone + 16000); |
||
74 | 18 | } else { |
|
75 | 18 | $boundingArea = BoundingArea::createFromPolygons( |
|
76 | 18 | [ |
|
77 | 18 | new Polygon( |
|
78 | 18 | new LinearRing( |
|
79 | 18 | new Position($longitudeOrigin, -90), |
|
80 | 18 | new Position($longitudeOrigin, 0), |
|
81 | 18 | new Position($longitudeOrigin + 6, 0), |
|
82 | 18 | new Position($longitudeOrigin + 6, -90), |
|
83 | 18 | new Position($longitudeOrigin, -90), |
|
84 | 18 | ) |
|
85 | 18 | ), |
|
86 | 18 | ], |
|
87 | 18 | RegionMap::REGION_GLOBAL |
|
88 | 18 | ); |
|
89 | $derivingConversion = 'urn:ogc:def:coordinateOperation:EPSG::' . ($zone + 16100); |
||
90 | } |
||
91 | 72 | ||
92 | $srid = 'urn:ogc:def:crs,' . str_replace('urn:ogc:def:', '', $crs->getSRID()) . ',' . str_replace('urn:ogc:def:', '', Cartesian::EPSG_2D_AXES_EASTING_NORTHING_E_N_ORIENTATIONS_EAST_NORTH_UOM_M) . ',' . str_replace('urn:ogc:def:', '', $derivingConversion); |
||
93 | 72 | ||
94 | 72 | $projectedCRS = new Projected( |
|
95 | 72 | $srid, |
|
96 | 72 | Cartesian::fromSRID(Cartesian::EPSG_2D_AXES_EASTING_NORTHING_E_N_ORIENTATIONS_EAST_NORTH_UOM_M), |
|
97 | 72 | $crs->getDatum(), |
|
98 | 72 | $boundingArea, |
|
99 | 72 | "{$crs->getName()} / UTM zone {$zone}{$hemisphere}", |
|
100 | 72 | $crs, |
|
101 | 72 | $derivingConversion |
|
102 | ); |
||
103 | 72 | ||
104 | parent::__construct($projectedCRS, $easting, $northing, null, null, $epoch, null); |
||
105 | } |
||
106 | 18 | ||
107 | public function getZone(): int |
||
108 | 18 | { |
|
109 | return $this->zone; |
||
110 | } |
||
111 | 18 | ||
112 | public function getHemisphere(): string |
||
113 | 18 | { |
|
114 | return $this->hemisphere; |
||
115 | } |
||
116 | |||
117 | public function getBaseCRS(): Geographic2D|Geographic3D |
||
118 | { |
||
119 | return $this->crs->getBaseCRS(); |
||
120 | } |
||
121 | 36 | ||
122 | public function convert(Compound|Geocentric|Geographic2D|Geographic3D|Projected|Vertical $to, bool $ignoreBoundaryRestrictions = false): Point |
||
123 | 36 | { |
|
124 | return $this->asGeographicPoint()->convert($to, $ignoreBoundaryRestrictions); |
||
125 | } |
||
126 | 27 | ||
127 | public function calculateDistance(Point $to): Length |
||
128 | 27 | { |
|
129 | 9 | if ($this->crs == $to->getCRS()) { |
|
130 | return parent::calculateDistance($to); |
||
131 | } |
||
132 | 18 | ||
133 | return $this->asGeographicPoint()->calculateDistance($to); |
||
134 | } |
||
135 | 18 | ||
136 | public function __toString(): string |
||
137 | 18 | { |
|
138 | return $this->getZone() . $this->getHemisphere() . ' ' . (int) $this->easting->getValue() . ' ' . (int) $this->northing->getValue(); |
||
139 | } |
||
140 | } |
||
141 |
This property has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.