1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* PHPCoord. |
4
|
|
|
* |
5
|
|
|
* @author Doug Wright |
6
|
|
|
*/ |
7
|
|
|
declare(strict_types=1); |
8
|
|
|
|
9
|
|
|
namespace PHPCoord\CoordinateOperation; |
10
|
|
|
|
11
|
|
|
use PHPCoord\CoordinateReferenceSystem\Geographic2D; |
12
|
|
|
use PHPCoord\CoordinateReferenceSystem\Geographic3D; |
13
|
|
|
use PHPCoord\GeographicPoint; |
14
|
|
|
use PHPCoord\UnitOfMeasure\Length\Metre; |
15
|
|
|
|
16
|
|
|
use function abs; |
17
|
|
|
|
18
|
|
|
class IGNFGeocentricTranslationGrid extends GeographicGrid |
19
|
|
|
{ |
20
|
|
|
use IGNFGrid; |
21
|
|
|
|
22
|
4 |
|
public function applyForwardAdjustment(GeographicPoint $point, Geographic2D|Geographic3D $to): GeographicPoint |
23
|
|
|
{ |
24
|
4 |
|
[$tx, $ty, $tz] = $this->getValues($point->getLongitude()->asDegrees()->getValue(), $point->getLatitude()->asDegrees()->getValue()); |
25
|
|
|
|
26
|
4 |
|
return $point->geocentricTranslation( |
27
|
|
|
$to, |
28
|
|
|
$tx, |
29
|
|
|
$ty, |
30
|
|
|
$tz, |
31
|
|
|
); |
32
|
|
|
} |
33
|
|
|
|
34
|
2 |
|
public function applyReverseAdjustment(GeographicPoint $point, Geographic2D|Geographic3D $to): GeographicPoint |
35
|
|
|
{ |
36
|
2 |
|
$adjustment = [new Metre(0), new Metre(0), new Metre(0)]; |
37
|
2 |
|
$latitude = $point->getLatitude(); |
38
|
2 |
|
$longitude = $point->getLongitude(); |
39
|
|
|
|
40
|
|
|
do { |
41
|
2 |
|
$prevAdjustment = $adjustment; |
42
|
2 |
|
$adjustment = $this->getValues($longitude->asDegrees()->getValue(), $latitude->asDegrees()->getValue()); |
43
|
2 |
|
$newPoint = $point->geocentricTranslation( |
44
|
|
|
$to, |
45
|
2 |
|
$adjustment[0]->multiply(-1), |
46
|
2 |
|
$adjustment[1]->multiply(-1), |
47
|
2 |
|
$adjustment[2]->multiply(-1), |
48
|
|
|
); |
49
|
|
|
|
50
|
2 |
|
$latitude = $newPoint->getLatitude(); |
51
|
2 |
|
$longitude = $newPoint->getLongitude(); |
52
|
2 |
|
} while (abs($adjustment[0]->subtract($prevAdjustment[0])->getValue()) > self::ITERATION_CONVERGENCE && abs($adjustment[1]->subtract($prevAdjustment[1])->getValue()) > self::ITERATION_CONVERGENCE && abs($adjustment[2]->subtract($prevAdjustment[2])->getValue()) > self::ITERATION_CONVERGENCE); |
53
|
|
|
|
54
|
2 |
|
return $newPoint; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @return Metre[] |
59
|
|
|
*/ |
60
|
4 |
|
public function getValues(float $x, float $y): array |
61
|
|
|
{ |
62
|
4 |
|
$offsets = $this->interpolate($x, $y); |
63
|
|
|
|
64
|
4 |
|
return [new Metre($offsets[0]), new Metre($offsets[1]), new Metre($offsets[2])]; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|