/**
  * Create a SWEREF99 position by converting a WGS84 position.
  *
  * @param position WGS84 position to convert
  * @param projection Projection to convert to
  */
 private function SWEREF99PositionPositionProjection(WGS84Position $position, $projection)
 {
     parent::__construct(Grid::SWEREF99);
     $gkProjection = new GaussKreugerProjection();
     $gkProjection->swedish_params($this->getProjectionString($projection));
     list($this->latitude, $this->longitude) = $gkProjection->geodetic_to_grid($position->getLatitude(), $position->getLongitude());
     $this->projection = $projection;
 }
 /**
  * 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 testWGS84Parse()
 {
     // Values from Eniro.se
     $wgsPosDM = null;
     $wgsPosDMs = null;
     try {
         $wgsPosDM = new WGS84Position("N 62º 10.560' E 015º 54.180'", WGS84Format::DEGREES_MINUTES);
         $wgsPosDMs = new WGS84Position("N 62º 10' 33.60\" E 015º 54' 10.80\"", WGS84Format::DEGREES_MINUTES_SECONDS);
     } catch (ParseException $e) {
         $this->fail($e->getMessage());
     }
     $lat = (double) round($wgsPosDM->getLatitude() * 1000) / 1000;
     $lon = (double) round($wgsPosDM->getLongitude() * 1000) / 1000;
     $this->assertEquals(62.176, $lat);
     $this->assertEquals(15.903, $lon);
     $lat_s = (double) round($wgsPosDMs->getLatitude() * 1000) / 1000;
     $lon_s = (double) round($wgsPosDMs->getLongitude() * 1000) / 1000;
     $this->assertEquals(62.176, $lat_s);
     $this->assertEquals(15.903, $lon_s);
 }