Skip to content

Commit

Permalink
Fix 3D support
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdoug committed Jan 3, 2016
1 parent 40e0920 commit f7b24fa
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
27 changes: 24 additions & 3 deletions LatLng.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,28 @@ public function toOSRef()

$coords = $this->toTransverseMercatorEastingNorthing($scale, $E0, $N0, $phi0, $lambda0);

return new OSRef(round($coords['E']), round($coords['N']));
return new OSRef(round($coords['E']), round($coords['N']), $this->h);
}

/**
* Convert this LatLng object into an ITM grid reference
*
* @return ITMRef
*/
public function toITMRef()
{
$this->toWGS84();

$ITM = new ITMRef(0, 0); //dummy to get reference data
$scale = $ITM->getScaleFactor();
$N0 = $ITM->getOriginNorthing();
$E0 = $ITM->getOriginEasting();
$phi0 = $ITM->getOriginLatitude();
$lambda0 = $ITM->getOriginLongitude();

$coords = $this->toTransverseMercatorEastingNorthing($scale, $E0, $N0, $phi0, $lambda0);

return new ITMRef(round($coords['E']), round($coords['N']), $this->h);
}


Expand Down Expand Up @@ -414,7 +435,7 @@ public function toUTMRef()

$UTMZone = $this->getUTMLatitudeZoneLetter($this->lat);

$UTM = new UTMRef(0, 0, $UTMZone, $longitudeZone); //dummy to get reference data
$UTM = new UTMRef(0, 0, 0, $UTMZone, $longitudeZone); //dummy to get reference data
$scale = $UTM->getScaleFactor();
$N0 = $UTM->getOriginNorthing();
$E0 = $UTM->getOriginEasting();
Expand All @@ -427,7 +448,7 @@ public function toUTMRef()
$coords['N'] += 10000000;
}

return new UTMRef(round($coords['E']), round($coords['N']), $UTMZone, $longitudeZone);
return new UTMRef(round($coords['E']), round($coords['N']), $this->h, $UTMZone, $longitudeZone);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions UTMRef.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,16 @@ class UTMRef extends TransverseMercator
*
* @param int $x
* @param int $y
* @param int $z
* @param string $latZone
* @param int $lngZone
*/
public function __construct($x, $y, $latZone, $lngZone)
public function __construct($x, $y, $z, $latZone, $lngZone)
{
$this->latZone = $latZone;
$this->lngZone = $lngZone;

parent::__construct($x, $y, 0, RefEll::wgs84());
parent::__construct($x, $y, $z, RefEll::wgs84());
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/UTMRefTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class UTMRefTest extends \PHPUnit_Framework_TestCase
public function testToString()
{

$UTMRef = new UTMRef(699375, 5713970, 'U', 30);
$UTMRef = new UTMRef(699375, 5713970, 0, 'U', 30);
$expected = "30U 699375 5713970";

self::assertEquals($expected, $UTMRef->__toString());
Expand All @@ -17,7 +17,7 @@ public function testToString()
public function testLatLng()
{

$UTMRef = new UTMRef(699375, 5713970, 'U', 30);
$UTMRef = new UTMRef(699375, 5713970, 0, 'U', 30);
$LatLng = $UTMRef->toLatLng();
$LatLng->toOSGB36();

Expand All @@ -29,7 +29,7 @@ public function testLatLng()
public function testLatLngSouthernHemisphere()
{

$UTMRef = new UTMRef(334786, 6252080, 'H', 56);
$UTMRef = new UTMRef(334786, 6252080, 0, 'H', 56);
$LatLng = $UTMRef->toLatLng();

$expected = "(-33.85798, 151.21404)";
Expand Down

0 comments on commit f7b24fa

Please sign in to comment.