public function testWGS84ToSweref()
 {
     $wgsPos = new WGS84Position();
     $wgsPos->setLatitudeFromString("N 59º 58' 55.23\"", WGS84Format::DEGREES_MINUTES_SECONDS);
     $wgsPos->setLongitudeFromString("E 017º 50' 06.12\"", WGS84Format::DEGREES_MINUTES_SECONDS);
     $rtPos = new SWEREF99Position($wgsPos, SWEREFProjection::SWEREF_99_TM);
     // Conversion values from Lantmateriet.se, they convert from DMS only.
     // Reference: http://www.lantmateriet.se/templates/LMV_Enkelkoordinattransformation.aspx?id=11500
     $xPosFromLM = 6652797.165;
     $yPosFromLM = 658185.201;
     $lat = (double) round($rtPos->getLatitude() * 1000) / 1000;
     $lon = (double) round($rtPos->getLongitude() * 1000) / 1000;
     $this->assertEquals($lat, $xPosFromLM);
     $this->assertEquals($lon, $yPosFromLM);
 }
 /**
  * Format coordinates
  *
  * @param  float  $lat    Latitude
  * @param  float  $lon    Longitude
  * @param  string $format Format
  *
  * @return array          X, Y or lat, lon
  */
 public static function format($lat, $lon, $format)
 {
     $wgs84 = new WGS84Position($lat, $lon);
     switch ($format) {
         case 'wgs84_dms':
             return array($wgs84->latitudeToString(WGS84Format::DEGREES_MINUTES_SECONDS), $wgs84->longitudeToString(WGS84Format::DEGREES_MINUTES_SECONDS));
         case 'wgs84_dm':
             return array($wgs84->latitudeToString(WGS84Format::DEGREES_MINUTES), $wgs84->longitudeToString(WGS84Format::DEGREES_MINUTES));
         case 'wgs84_dd':
         case 'wgs84_decimal':
             return array($wgs84->latitudeToString(WGS84Format::DEGREES), $wgs84->longitudeToString(WGS84Format::DEGREES));
         case 'rt90':
             $rtPos = new RT90Position($wgs84, RT90Projection::RT90_2_5_GON_V);
             $x = (double) round($rtPos->getLatitude() * 1000) / 1000;
             $y = (double) round($rtPos->getLongitude() * 1000) / 1000;
             return array($x, $y);
         case 'sweref99':
             $rtPos = new SWEREF99Position($wgs84, SWEREFProjection::SWEREF_99_TM);
             $x = (double) round($rtPos->getLatitude() * 1000) / 1000;
             $y = (double) round($rtPos->getLongitude() * 1000) / 1000;
             return array($x, $y);
     }
 }
 public static function WGS84ToSWEREF99($latitude, $longitude)
 {
     $position = new WGS84Position($latitude, $longitude);
     $rtPos = new SWEREF99Position($position, SWEREFProjection::SWEREF_99_TM);
     return array($rtPos->getLatitude(), $rtPos->getLongitude());
 }