Skip to content

Commit

Permalink
Simplify/unify grid implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdoug committed Oct 9, 2021
1 parent b7cee81 commit 48e916b
Show file tree
Hide file tree
Showing 29 changed files with 589 additions and 1,044 deletions.
12 changes: 6 additions & 6 deletions docs/coordinate_conversions_hard_compound.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ Geographic2D with Height Offsets
Length $geoidUndulation
); // returns a new GeographicPoint
Geographic3D to Geographic2D+GravityRelatedHeight (GTX)
-------------------------------------------------------
Geographic3D to Geographic2D+GravityRelatedHeight From Grid (geographic)
------------------------------------------------------------------------
The following grid file types are supported: ``.gtx`` (``GTXGrid``), ``.mnt/.tac`` from IGN France (``IGNFHeightGrid``) and ``.txt`` from IGN Spain (``IGNESHeightGrid``)

.. code-block:: php
$point = CompoundPoint::create(...);
$newPoint = $point->geographic3DTo2DPlusGravityHeightGTX(
$newPoint = $point->geographic3DTo2DPlusGravityHeightFromGrid(
Geographic3D $to,
GTXGrid $geoidHeightCorrectionModelFile
GeographicGeoidHeightGrid $geoidHeightCorrectionModelFile
); // returns a new GeographicPoint
Geographic3D to Geographic2D+GravityRelatedHeight (OSGM-GB)
Expand All @@ -33,6 +34,5 @@ Geographic3D to Geographic2D+GravityRelatedHeight (OSGM-GB)
$point = CompoundPoint::create(...);
$newPoint = $point->geographic3DTo2DPlusGravityHeightOSGM15(
Geographic3D $to,
OSTNOSGM15Grid $geoidHeightCorrectionModelFile,
string $EPSGCodeForInterpolationCRS
OSTNOSGM15Grid $geoidHeightCorrectionModelFile
); // returns a new GeographicPoint
70 changes: 22 additions & 48 deletions docs/coordinate_conversions_hard_geographic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -189,20 +189,6 @@ Geocentric translation
Length $zAxisTranslation
); // returns a new GeographicPoint
Geocentric translation by grid interpolation (IGNF)
---------------------------------------------------

.. code-block:: php
$point = GeographicPoint::create(...);
$newPoint = $point->geocentricTranslationByGridInterpolationIGNF(
Geographic $to,
IGNFGeocentricTranslationGrid $geocentricTranslationFile,
string $EPSGCodeForInterpolationCRS,
string $EPSGCodeForStandardCT,
bool $inReverse
); // returns a new GeographicPoint
Geographic <=> geocentric conversion
------------------------------------

Expand Down Expand Up @@ -238,15 +224,16 @@ Geographic2D with Height Offsets
Length $geoidUndulation
); // returns a new CompoundPoint
Geographic3D to Geographic2D+GravityRelatedHeight (GTX)
Geographic3D to Geographic2D+GravityRelatedHeight From Grid
-----------------------------------------------------------
The following grid file types are supported: ``.gtx`` (``GTXGrid``), ``.mnt/.tac`` from IGN France (``IGNFHeightGrid``) and ``.txt`` from IGN Spain (``IGNESHeightGrid``)

.. code-block:: php
$point = GeographicPoint::create(...);
$newPoint = $point->geographic3DTo2DPlusGravityHeightGTX(
$newPoint = $point->geographic3DTo2DPlusGravityHeightFromGrid(
Compound $to,
GTXGrid $geoidHeightCorrectionModelFile
GeographicGeoidHeightGrid $geoidHeightCorrectionModelFile
); // returns a new CompoundPoint
Geographic3D to Geographic2D+GravityRelatedHeight (OSGM-GB)
Expand All @@ -257,19 +244,19 @@ Geographic3D to Geographic2D+GravityRelatedHeight (OSGM-GB)
$point = GeographicPoint::create(...);
$newPoint = $point->geographic3DTo2DPlusGravityHeightOSGM15(
Compound $to,
OSTNOSGM15Grid $geoidHeightCorrectionModelFile,
string $EPSGCodeForInterpolationCRS
OSTNOSGM15Grid $geoidHeightCorrectionModelFile
); // returns a new CompoundPoint
Geographic3D to GravityRelatedHeight (GTX)
Geographic3D to GravityRelatedHeight From Grid
----------------------------------------------
The following grid file types are supported: ``.gtx`` (``GTXGrid``), ``.mnt/.tac`` from IGN France (``IGNFHeightGrid``) and ``.txt`` from IGN Spain (``IGNESHeightGrid``)

.. code-block:: php
$point = GeographicPoint::create(...);
$newPoint = $point->geographic3DToGravityHeightGTX(
$newPoint = $point->geographic3DTo2DPlusGravityHeightFromGrid((
Vertical $to,
GTXGrid $geoidHeightCorrectionModelFile
GeographicGeoidHeightGrid $geoidHeightCorrectionModelFile
); // returns a new VerticalPoint
Geographic3D to GravityRelatedHeight (OSGM-GB)
Expand Down Expand Up @@ -687,20 +674,6 @@ Molodensky-Badekas Position Vector transformation
Length $ordinate3OfEvaluationPoint
); // returns a new GeographicPoint
NADCON5
-------

.. code-block:: php
$point = GeographicPoint::create(...);
$newPoint = $point->NADCON5(
Geographic $to,
NADCON5Grid $latitudeDifferenceFile,
NADCON5Grid $longitudeDifferenceFile,
?NADCON5Grid $ellipsoidalHeightDifferenceFile,
bool $inReverse
); // returns a new GeographicPoint
New Zealand Map Grid
--------------------

Expand All @@ -715,18 +688,6 @@ New Zealand Map Grid
Length $falseNorthing
); // returns a new ProjectedPoint
NTv2
----

.. code-block:: php
$point = GeographicPoint::create(...);
$newPoint = $point->NTv2(
Geographic $to,
NTv2Grid $latitudeAndLongitudeDifferenceFile,
bool $inReverse
); // returns a new GeographicPoint
Oblique Stereographic
---------------------

Expand All @@ -742,6 +703,19 @@ Oblique Stereographic
Length $falseNorthing
); // returns a new ProjectedPoint
Offsets From Grid
-----------------
The following grid file types are supported: ``.gsb`` (``NTv2Grid``), ``.txt/.mnt/.tac`` from IGN France (``IGNFGeocentricTranslationGrid``) and ``.b`` from NOAA (``NADCON5Grids``)

.. code-block:: php
$point = GeographicPoint::create(...);
$newPoint = $point->offsetsFromGrid(
Geographic $to,
GeographicGrid $offsetsFile,
bool $inReverse
); // returns a new GeographicPoint
OSTN15 (Ordnance Survey National Transformation)
------------------------------------------------

Expand Down
22 changes: 12 additions & 10 deletions docs/coordinate_conversions_hard_vertical.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@ Height <=> Depth reversal
Vertical $to
); // returns a new VerticalPoint
Vertical Offset
---------------
Offset
------

.. code-block:: php
$point = VerticalPoint::create(...);
$newPoint = $point->verticalOffset(
$newPoint = $point->offset(
Vertical $to,
Length $verticalOffset
); // returns a new VerticalPoint
Vertical Offset and Slope
-------------------------
Offset and Slope
----------------

.. code-block:: php
$point = VerticalPoint::create(...);
$newPoint = $point->verticalOffsetAndSlope(
$newPoint = $point->offsetAndSlope(
Vertical $to,
Angle $ordinate1OfEvaluationPoint,
Angle $ordinate2OfEvaluationPoint,
Expand All @@ -38,15 +38,17 @@ Vertical Offset and Slope
GeographicPoint $horizontalPoint
); // returns a new VerticalPoint
Vertical Offset by Grid Interpolation (GTX)
-------------------------------------------
Offset From Grid File
---------------------

The following grid file types are supported: ``.gtx`` (``GTXGrid``), ``.mnt/.tac`` from IGN France (``IGNFHeightGrid``) and ``.txt`` from IGN Spain (``IGNESHeightGrid``)

.. code-block:: php
$point = VerticalPoint::create(...);
$newPoint = $point->verticalOffsetGTX(
$newPoint = $point->offsetFromGrid(
Vertical $to,
GTXGrid $verticalOffsetFile,
GeographicGeoidHeightGrid $offsetsFile,
bool $inReverse,
GeographicPoint $horizontalPoint
); // returns a new VerticalPoint
Expand Down
52 changes: 7 additions & 45 deletions src/CompoundPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
use DateTimeInterface;
use PHPCoord\CoordinateOperation\AutoConversion;
use PHPCoord\CoordinateOperation\ConvertiblePoint;
use PHPCoord\CoordinateOperation\GTXGrid;
use PHPCoord\CoordinateOperation\IGNESHeightGrid;
use PHPCoord\CoordinateOperation\IGNFHeightGrid;
use PHPCoord\CoordinateOperation\GeographicGeoidHeightGrid;
use PHPCoord\CoordinateOperation\OSTNOSGM15Grid;
use PHPCoord\CoordinateReferenceSystem\Compound;
use PHPCoord\CoordinateReferenceSystem\CoordinateReferenceSystem;
Expand Down Expand Up @@ -190,8 +188,7 @@ public function geographic2DWithHeightOffsets(
*/
public function geographic3DTo2DPlusGravityHeightOSGM15(
Geographic3D $to,
OSTNOSGM15Grid $geoidHeightCorrectionModelFile,
string $EPSGCodeForInterpolationCRS
OSTNOSGM15Grid $geoidHeightCorrectionModelFile
): GeographicPoint {
$osgb36NationalGrid = Projected::fromSRID(Projected::EPSG_OSGB36_BRITISH_NATIONAL_GRID);
$etrs89NationalGrid = new Projected(
Expand All @@ -206,58 +203,23 @@ public function geographic3DTo2DPlusGravityHeightOSGM15(
return GeographicPoint::create(
$this->horizontalPoint->getLatitude(),
$this->horizontalPoint->getLongitude(),
$this->verticalPoint->getHeight()->add($geoidHeightCorrectionModelFile->getVerticalAdjustment($projected)),
$this->verticalPoint->getHeight()->add($geoidHeightCorrectionModelFile->getHeightAdjustment($projected)),
$to,
$this->getCoordinateEpoch()
);
}

/**
* Geog3D to Geog2D+GravityRelatedHeight (gtx).
* Geog3D to Geog2D+GravityRelatedHeight.
*/
public function geographic3DTo2DPlusGravityHeightGTX(
public function geographic3DTo2DPlusGravityHeightFromGrid(
Geographic3D $to,
GTXGrid $geoidHeightCorrectionModelFile,
string $EPSGCodeForInterpolationCRS
GeographicGeoidHeightGrid $geoidHeightCorrectionModelFile
): GeographicPoint {
return GeographicPoint::create(
$this->horizontalPoint->getLatitude(),
$this->horizontalPoint->getLongitude(),
$this->verticalPoint->getHeight()->add($geoidHeightCorrectionModelFile->getAdjustment($this->horizontalPoint)),
$to,
$this->getCoordinateEpoch()
);
}

/**
* Geog3D to Geog2D+GravityRelatedHeight (IGNES).
*/
public function geographic3DTo2DPlusGravityHeightIGNES(
Geographic3D $to,
IGNESHeightGrid $geoidHeightCorrectionModelFile,
string $EPSGCodeForInterpolationCRS
): GeographicPoint {
return GeographicPoint::create(
$this->horizontalPoint->getLatitude(),
$this->horizontalPoint->getLongitude(),
$this->verticalPoint->getHeight()->add($geoidHeightCorrectionModelFile->getAdjustment($this->horizontalPoint)),
$to,
$this->getCoordinateEpoch()
);
}

/**
* Geog3D to Geog2D+GravityRelatedHeight (IGNF).
*/
public function geographic3DTo2DPlusGravityHeightIGNF(
Geographic3D $to,
IGNFHeightGrid $geoidHeightCorrectionModelFile,
string $EPSGCodeForInterpolationCRS
): GeographicPoint {
return GeographicPoint::create(
$this->horizontalPoint->getLatitude(),
$this->horizontalPoint->getLongitude(),
$this->verticalPoint->getHeight()->add($geoidHeightCorrectionModelFile->getAdjustment($this->horizontalPoint)),
$this->verticalPoint->getHeight()->add($geoidHeightCorrectionModelFile->getHeightAdjustment($this->horizontalPoint)),
$to,
$this->getCoordinateEpoch()
);
Expand Down
10 changes: 5 additions & 5 deletions src/CoordinateOperation/BilinearInterpolation.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ trait BilinearInterpolation
protected float $columnGridInterval;
protected float $rowGridInterval;

public function interpolateBilinear(
public function interpolate(
float $x,
float $y
): array {
$corners = $this->getCornersForBilinear($x, $y);
$corners = $this->getCorners($x, $y);

$dx = $corners['lowerRight']->getX() === $corners['lowerLeft']->getX() ? 0 : (($x - $corners['lowerLeft']->getX()) / ($corners['lowerRight']->getX() - $corners['lowerLeft']->getX()));
$dy = $corners['upperLeft']->getY() === $corners['lowerLeft']->getY() ? 0 : (($y - $corners['lowerLeft']->getY()) / ($corners['upperLeft']->getY() - $corners['lowerLeft']->getY()));
$dx = $corners['lowerRight']->getX() === $corners['lowerLeft']->getX() ? 0 : (($x - $corners['lowerLeft']->getX()) / $this->columnGridInterval);
$dy = $corners['upperLeft']->getY() === $corners['lowerLeft']->getY() ? 0 : (($y - $corners['lowerLeft']->getY()) / $this->rowGridInterval);

$interpolations = [];
for ($i = 0, $count = count($corners['lowerLeft']->getValues()); $i < $count; ++$i) {
Expand Down Expand Up @@ -59,7 +59,7 @@ private function interpolateLinear(float $p, float $valueAt0, float $valueAt1):
/**
* @return GridValues[]
*/
private function getCornersForBilinear(float $x, float $y): array
private function getCorners(float $x, float $y): array
{
$xIndex = (int) (($x - $this->startX) / $this->columnGridInterval);
$yIndex = (int) (($y - $this->startY) / $this->rowGridInterval);
Expand Down
Loading

0 comments on commit 48e916b

Please sign in to comment.