Skip to content

Commit

Permalink
Correct the decoding of sexagesimal DMS degree fractional components. F…
Browse files Browse the repository at this point in the history
…ixes #39
  • Loading branch information
dvdoug committed Oct 22, 2021
1 parent 082a0c5 commit f9b860c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/UnitOfMeasure/Angle/Degree.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use function str_pad;
use const STR_PAD_RIGHT;
use function str_replace;
use function strlen;
use function strpos;

class Degree extends Angle
Expand Down Expand Up @@ -147,9 +148,9 @@ private static function fromRegex(string $angle, string $regex): self

$degrees = ($angleParts['degrees'] * 1);
$degrees += (($angleParts['arcminutes'] ?? 0) / 60);
$degrees += (($angleParts['fractionarcminutes'] ?? 0) / 60 / 100);
$degrees += isset($angleParts['fractionarcminutes']) ? ($angleParts['fractionarcminutes'] / 60 / 10 ** (strlen($angleParts['fractionarcminutes']))) : 0;
$degrees += (($angleParts['arcseconds'] ?? 0) / 3600);
$degrees += (($angleParts['fractionarcseconds'] ?? 0) / 3600 / 100);
$degrees += isset($angleParts['fractionarcseconds']) ? ($angleParts['fractionarcseconds'] / 3600 / 10 ** (strlen($angleParts['fractionarcseconds']))) : 0;

if ($angleParts['negative'] ?? '' || in_array($angleParts['hemisphere'] ?? [], ['S', 'W'], true)) {
$degrees *= -1;
Expand Down
10 changes: 10 additions & 0 deletions tests/CoordinateOperation/AutoConversionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,16 @@ public function testNAD27ToNAD83Canada(): void
}
}

public function testAmersfoortRDNewToWGS84(): void
{
$from = ProjectedPoint::createFromEastingNorthing(new Metre(86058.2205), new Metre(445832.8025), Projected::fromSRID(Projected::EPSG_AMERSFOORT_RD_NEW));
$toCRS = Geographic2D::fromSRID(Geographic2D::EPSG_WGS_84);
$to = $from->convert($toCRS);

self::assertEqualsWithDelta(51.996591992, $to->getLatitude()->asDegrees()->getValue(), 0.0000001);
self::assertEqualsWithDelta(4.383328547, $to->getLongitude()->asDegrees()->getValue(), 0.0000001);
}

/**
* @group integration
* @dataProvider EPSGConcatenatedOperations
Expand Down
6 changes: 6 additions & 0 deletions tests/UnitOfMeasure/Angle/DegreeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,12 @@ public function testSexagesimalDMS(): void
self::assertEquals(35.5, $original->getValue());
}

public function testSexagesimalDMSFractionalSeconds(): void
{
$original = Degree::fromSexagesimalDMS('52.0922178');
self::assertEqualsWithDelta(0.910296727, $original->asRadians()->getValue(), 0.000000001);
}

public function testSexagesimalDMSNegative(): void
{
$original = Degree::fromSexagesimalDMS('-35.3');
Expand Down

0 comments on commit f9b860c

Please sign in to comment.