TypeScript library for transformation of geographic coordinates between WGS84 and the Swedish coordinate reference systems SWEREF99 and RT90.
How to use the library
Install the module into your TypeScript (or JavaScript) module:
pnpm install @programmerare/sweden_crs_transformations
or
npm install @programmerare/sweden_crs_transformations
Then you can use this kind of code from a TypeScript module:
import {CrsProjection, CrsCoordinate} from '@programmerare/sweden_crs_transformations';
const coordinate_WGS84_latitude = 59.330231;
const coordinate_WGS84_longitude = 18.059196;
const coordinate_WGS84: CrsCoordinate = CrsCoordinate.createCoordinate(
CrsProjection.wgs84,
coordinate_WGS84_latitude,
coordinate_WGS84_longitude
);
const coordinate_SWEREF99TM: CrsCoordinate = coordinate_WGS84.transform(CrsProjection.sweref_99_tm);
console.log(`SWEREF99TM X: ${coordinate_SWEREF99TM.xLongitude}`);
console.log(`SWEREF99TM Y: ${coordinate_SWEREF99TM.yLatitude}`);
You can use almost the same code as above (if you skip the above optional typing) from a JavaScript Node.js module, if you are using "type": "module" in your file 'package.json', assuming that you are also using a recent version of 'Node.js'.
("type":"module" should work with Node.js versions 13.2.0 and later)
An alternative for JavaScript, if you are not using "type": "module" is to use the require syntax instead as below:
const {CrsProjection, CrsCoordinate} = require("@programmerare/sweden_crs_transformations");
const coordinate_WGS84_latitude = 59.330231;
const coordinate_WGS84_longitude = 18.059196;
const coordinate_WGS84 = CrsCoordinate.createCoordinate(
CrsProjection.wgs84,
coordinate_WGS84_latitude,
coordinate_WGS84_longitude
);
const coordinate_SWEREF99TM = coordinate_WGS84.transform(CrsProjection.sweref_99_tm);
console.log(`SWEREF99TM X: ${coordinate_SWEREF99TM.xLongitude}`);
console.log(`SWEREF99TM Y: ${coordinate_SWEREF99TM.yLatitude}`);
It is also possible to use a javascript bundle from within a webpage.
See the github webpage for more information
20 coordinate reference systems are supported (WGS84 + 6 RT90 + 13 SWEREF99)

License information
MIT.
The mathematical code for the transformations is based on the C# class GaussKreuger.cs in the .NET library MightyLittleGeodesy
The text below has been copied from the above linked 'MightyLittleGeodesy' webpage:
The calculations in this library is based on the excellent javascript library by Arnold Andreasson which is published under the Creative Commons license. However, as agreed with mr Andreasson, MightyLittleGeodesy is now licensed under the MIT license.
The text below has been copied from one of the source files for MightyLittleGeodesy.