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