public function testWGS84ToRT90()
 {
     $wgsPos = null;
     $rtPos = null;
     try {
         $wgsPos = new WGS84Position("N 59º 58' 55.23\" E 017º 50' 06.12\"", WGS84Format::DEGREES_MINUTES_SECONDS);
         $rtPos = new RT90Position($wgsPos, RT90Projection::RT90_2_5_GON_V);
     } catch (ParseException $e) {
         $this->fail($e->getMessage());
     }
     // Conversion values from Lantmateriet.se, they convert from DMS only.
     // Reference: http://www.lantmateriet.se/templates/LMV_Enkelkoordinattransformation.aspx?id=11500
     $xPosFromLM = 6653174.343;
     $yPosFromLM = 1613318.742;
     $lat = (double) round($rtPos->getLatitude() * 1000) / 1000;
     $lon = (double) round($rtPos->getLongitude() * 1000) / 1000;
     $this->assertEquals($lat, $xPosFromLM);
     //fix accuracy: 0.0001d
     $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 RT90ToWGS84($latitude, $longitude)
 {
     $position = new RT90Position($latitude, $longitude);
     $wgsPos = $position->toWGS84();
     return array($wgsPos->getLatitude(), $wgsPos->getLongitude());
 }