Skip to content

Commit

Permalink
Add php methods to calculate RD coordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
Hipska committed Jun 22, 2022
1 parent ffcbcba commit 10be266
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 1.6.0 - 2022-06-22
### Added
- PHP methods to calculate RD (Rijksdriehoek) coordinates

## 1.5.0 - 2021-07-02
### Changed
- Improved CSV export compatibility.
Expand Down
80 changes: 80 additions & 0 deletions main.sv-geolocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,77 @@ public function getLongitude()
{
return $this->fLongitude;
}

/**
* Calculate the X coordinate in the Rijksdriehoek (RD) system
*
* @since 1.6.0
* @return float
*/
public function getRijksdriehoekX()
{
static $aPQR = [
[0,1,190094.945],
[1,1,-11832.228],
[2,1,-114.221],
[0,3,-32.391],
[1,0,-0.705],
[3,1,-2.34],
[1,3,-0.608],
[0,2,-0.008],
[2,3,0.148],
];

$fX = 155E3;
$oRijksdriehoekReference = static::getRijksdriehoekReference();
$oD = new static(
0.36 * ($this->getLatitude() - $oRijksdriehoekReference->getLatitude()),
0.36 * ($this->getLongitude() - $oRijksdriehoekReference->getLongitude())
);

foreach ($aPQR as list($iP, $iQ, $fR))
{
$fX += $fR * pow($oD->getLatitude(), $iP) * pow($oD->getLongitude(), $iQ);
}

return $fX;
}

/**
* Calculate the Y coordinate in the Rijksdriehoek (RD) system
*
* @since 1.6.0
* @return float
*/
public function getRijksdriehoekY()
{
static $aPQS = [
[1, 0, 309056.544],
[0, 2, 3638.893],
[2, 0, 73.077],
[1, 2, -157, 984],
[3, 0, 59.788],
[0, 1, 0.433],
[2, 2, -6.439],
[1, 1, -0.032],
[0, 4, 0.092],
[1, 4, -0.054]
];

$fY = 463E3;
$oRijksdriehoekReference = static::getRijksdriehoekReference();
$oD = new static(
0.36 * ($this->getLatitude() - $oRijksdriehoekReference->getLatitude()),
0.36 * ($this->getLongitude() - $oRijksdriehoekReference->getLongitude())
);

foreach ($aPQS as list($iP, $iQ, $fS))
{
$fY += $fS * pow($oD->getLatitude(), $iP) * pow($oD->getLongitude(), $iQ);
}

return $fY;
}

public function __toString()
{
Expand All @@ -253,4 +324,13 @@ public function jsonSerialize() {
'lng' => $this->fLongitude,
);
}

/**
* @since 1.6.0
* @return static
*/
public static function getRijksdriehoekReference()
{
return new static(52.1551744, 5.38720621);
}
}
2 changes: 1 addition & 1 deletion module.sv-geolocation.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

SetupWebPage::AddModule(
__FILE__, // Path to the current file, all other file names are relative to the directory containing this file
'sv-geolocation/1.5.0',
'sv-geolocation/1.6.0',
array(
// Identification
//
Expand Down

0 comments on commit 10be266

Please sign in to comment.