Obs: Detta innehåll finns inte tillgängligt på svenska. Därför ser du engelska versionen. Om du tycker att denna sida borde översättas till svenska, kan du skriva till oss på support.trafiklab.se.

Om du vill se webbsidan på engelska, klicka här.

The old trafikverkets API, and some other Swedish datasets as well, make use of the SWEREF99 coordinate system. This is Swedens national coordinate system, and can only be used in and around Sweden. In order to use these coordinates together with software that works with the WGS84 coordinate system, or in order to combine data with other data that uses the WGS84 coordinate system, conversion is needed.

Converting SWEREF99 to WGS84

In order to convert SWEREF99 coordinates to WGS84, a Gauss-Kreuger projection is used.

The following parameters are used when converting to/from sweref 99 tm:

1axis = 6378137;
2flattening = 003352810681182319D;
3central_meridian = 15;
4scale = 0.9996D;
5false_northing = 0;
6false_easting = 500000;

The complete projection looks like this

 1e2 = this.flattening * (2 - this.flattening)
 2n = this.flattening / (2 - this.flattening)
 3a_roof = this.axis / (1 + n) * (1 + n * n / 4 + n * n * n * n / 64)
 4delta1 = n / 2 - 2 * n * n / 3 + 37 * n * n * n / 96 - n * n * n * n / 360
 5delta2 = n * n / 48 + n * n * n / 15 - 437 * n * n * n * n / 1440
 6delta3 = 17 * n * n * n / 480 - 37 * n * n * n * n / 840
 7delta4 = 4397 * n * n * n * n / 161280
 8Astar = e2 + e2 * e2 + e2 * e2 * e2 + e2 * e2 * e2 * e2
 9Bstar = -(7 * e2 * e2 + 17 * e2 * e2 * e2 + 30 * e2 * e2 * e2 * e2) / 6
10Cstar = (224 * e2 * e2 * e2 + 889 * e2 * e2 * e2 * e2) / 120
11Dstar = -(4279 * e2 * e2 * e2 * e2) / 1260
12deg_to_rad = 017453292519943295D
13lambda_zero = this.central_meridian * deg_to_rad
14xi = (x - this.false_northing) / (this.scale * a_roof)
15eta = (y - this.false_easting) / (this.scale * a_roof)
16xi_prim = xi - delta1 * sin(2 * xi) * cosh(2 * eta) - delta2 * sin(4 * xi) * cosh(4 * eta) - delta3 * sin(6 * xi) * cosh(6 * eta) - delta4 * sin(8 * xi) * cosh(8 * eta)
17eta_prim = eta - delta1 * cos(2 * xi) * sinh(2 * eta) - delta2 * cos(4 * xi) * sinh(4 * eta) - delta3 * cos(6 * xi) * sinh(6 * eta) - delta4 * cos(8 * xi) * sinh(8 * eta)
18phi_star = Math.asin(sin(xi_prim) / cosh(eta_prim))
19delta_lambda = atan(sinh(eta_prim) / cos(xi_prim))
20lon_radian = lambda_zero + delta_lambda
21lat_radian = phi_star + sin(phi_star) * cos(phi_star) * (Astar + Bstar * sin(phi_star)^2 + Cstar * sin(phi_star)^4 + Dstar * sin(phi_star)^6)
22longitude = lat_radian * 180 / 3.141592653589793D
23latitude = lon_radian * 180 / 3.141592653589793D

Since this conversion is quite complicated, we recommend you use a library to do the heavy lifting.

Libraries

There are multiple libraries which you can use to convert coordinates from SWEREF99 to WGS84:

Check the licenses and don’t forget to give credit where credit is due when using one of them.

Further reading

You can read more about SWEREF99 at lantmäteriverkets website (Swedish) (English) or on Wikipedia (Swedish).