/**
  * 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 function testSwerefToWGS84()
 {
     $swePos = new SWEREF99Position(6652797.165, 658185.201);
     $wgsPos = $swePos->toWGS84();
     // String values from Lantmateriet.se, they convert DMS only.
     // Reference: http://www.lantmateriet.se/templates/LMV_Enkelkoordinattransformation.aspx?id=11500
     $latDmsStringFromLM = "N 59º 58' 55,23001\"";
     $lonDmsStringFromLM = "E 17º 50' 6,11997\"";
     $this->assertEquals($latDmsStringFromLM, $wgsPos->latitudeToString(WGS84Format::DEGREES_MINUTES_SECONDS));
     $this->assertEquals($lonDmsStringFromLM, $wgsPos->longitudeToString(WGS84Format::DEGREES_MINUTES_SECONDS));
 }
 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());
 }