{"id":23291250,"url":"https://github.com/tomasjohansson/sweden_crs_transformations_4typescript","last_synced_at":"2025-04-06T17:45:28.256Z","repository":{"id":57138211,"uuid":"338624965","full_name":"TomasJohansson/sweden_crs_transformations_4typescript","owner":"TomasJohansson","description":"TypeScript library for transformation of geographic coordinates between WGS84 and the Swedish coordinate reference systems SWEREF99 and RT90","archived":false,"fork":false,"pushed_at":"2021-02-17T12:16:35.000Z","size":361,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"typescript_SwedenCrsTransformations","last_synced_at":"2025-03-13T01:08:13.813Z","etag":null,"topics":["coordinate","coordinate-reference-system","coordinates","crs","crs-transformation","crs-transformations","gis","rt90","sweden","swedish","sweref","sweref99","sweref99tm","transform","transformation","transformations","transforms","typescript","typescript-library","wgs84"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TomasJohansson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-02-13T17:07:44.000Z","updated_at":"2023-01-07T17:09:52.000Z","dependencies_parsed_at":"2022-08-25T10:01:22.399Z","dependency_job_id":null,"html_url":"https://github.com/TomasJohansson/sweden_crs_transformations_4typescript","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TomasJohansson%2Fsweden_crs_transformations_4typescript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TomasJohansson%2Fsweden_crs_transformations_4typescript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TomasJohansson%2Fsweden_crs_transformations_4typescript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TomasJohansson%2Fsweden_crs_transformations_4typescript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TomasJohansson","download_url":"https://codeload.github.com/TomasJohansson/sweden_crs_transformations_4typescript/tar.gz/refs/heads/typescript_SwedenCrsTransformations","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247526675,"owners_count":20953141,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["coordinate","coordinate-reference-system","coordinates","crs","crs-transformation","crs-transformations","gis","rt90","sweden","swedish","sweref","sweref99","sweref99tm","transform","transformation","transformations","transforms","typescript","typescript-library","wgs84"],"created_at":"2024-12-20T05:16:26.533Z","updated_at":"2025-04-06T17:45:28.228Z","avatar_url":"https://github.com/TomasJohansson.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sweden_crs_transformations_4typescript\n'sweden_crs_transformations_4typescript' is a TypeScript library ported from the \n[C#.NET library 'sweden_crs_transformations_4net'](https://github.com/TomasJohansson/sweden_crs_transformations_4net/) and the [Dart library 'sweden_crs_transformations_4dart'](https://github.com/TomasJohansson/sweden_crs_transformations_4dart/)\nfor transforming geographic coordinates between the following three kind of CRS (Coordinate Reference Systems): WGS84, SWEREF99 and RT90.\n(13 versions of SWEREF99, and 6 versions of RT90)\n\nThe C#.NET library ('sweden_crs_transformations_4net') is \nbased on [C# library MightyLittleGeodesy](https://github.com/bjornsallarp/MightyLittleGeodesy/) which in turn is based on a [javascript library by Arnold Andreasson](https://latlong.mellifica.se/).\n\nThe main part of 'MightyLittleGeodesy' which has been kept (to the C# library 'sweden_crs_transformations_4net') is the mathematical calculations in the class 'GaussKreuger.cs'.  \nRegarding the port to this 'sweden_crs_transformations_4typescript' then of course there had to be more modifications since TypeScript has differences in syntax compared with C#, although \nthe mathematical logic has still been kept from the original 'MightyLittleGeodesy' class 'GaussKreuger.cs'.\n\n# npm release\n\n```shell-script\npnpm install @programmerare/sweden_crs_transformations\n```\nor\n```shell-script\nnpm install @programmerare/sweden_crs_transformations\n```\n\nThen you can use this kind of code from a TypeScript module:\n```typescript\nimport {CrsProjection, CrsCoordinate} from '@programmerare/sweden_crs_transformations';\nconst coordinate_WGS84_latitude = 59.330231;\nconst coordinate_WGS84_longitude = 18.059196;\n// the below explicit type ': CrsCoordinate' is optional to specify\nconst coordinate_WGS84: CrsCoordinate = CrsCoordinate.createCoordinate(\n    CrsProjection.wgs84,\n    coordinate_WGS84_latitude,      \n    coordinate_WGS84_longitude\n);\n// the below explicit type ': CrsCoordinate' is optional to specify\nconst coordinate_SWEREF99TM: CrsCoordinate = coordinate_WGS84.transform(CrsProjection.sweref_99_tm);\nconsole.log(`SWEREF99TM X: ${coordinate_SWEREF99TM.xLongitude}`);\nconsole.log(`SWEREF99TM Y: ${coordinate_SWEREF99TM.yLatitude}`);\n```\nYou can use almost the same code as above (if you skip the above optional typing) from a JavaScript [Node.js](https://nodejs.org) module, if you are using *\"type\": \"module\"* in your file 'package.json', assuming that you are also using a recent version of '*Node.js*'.  \n(\"type\":\"module\" should work with [Node.js versions 13.2.0 and later](https://nodejs.medium.com/announcing-core-node-js-support-for-ecmascript-modules-c5d6dc29b663))  \nAn alternative for JavaScript, if you are not using *\"type\": \"module\"*  is to use the *require* syntax instead as below:\n\n```javascript\nconst {CrsProjection, CrsCoordinate} = require(\"@programmerare/sweden_crs_transformations\");\n// Above row: if you are NOT using \"type\":\"module\" in your \"package.json\"\n// Below row: if you ARE using \"type\":\"module\" in your \"package.json\"\n//import {CrsProjection, CrsCoordinate} from '@programmerare/sweden_crs_transformations';\n\nconst coordinate_WGS84_latitude = 59.330231;\nconst coordinate_WGS84_longitude = 18.059196;\nconst coordinate_WGS84 = CrsCoordinate.createCoordinate(\n    CrsProjection.wgs84,\n    coordinate_WGS84_latitude,      \n    coordinate_WGS84_longitude\n);\nconst coordinate_SWEREF99TM = coordinate_WGS84.transform(CrsProjection.sweref_99_tm);\nconsole.log(`SWEREF99TM X: ${coordinate_SWEREF99TM.xLongitude}`);\nconsole.log(`SWEREF99TM Y: ${coordinate_SWEREF99TM.yLatitude}`);\n```\n\n[https://www.npmjs.com/package/@programmerare/sweden_crs_transformations](https://www.npmjs.com/package/@programmerare/sweden_crs_transformations)  \n\n\n# How to use this git repository\n\nFurther down in this section you can se a block of commands you can run if you want.  \n\nIt is assumed that you have installed [git](https://git-scm.com/) and [pnpm](https://pnpm.js.org) (and also [npm](https://www.npmjs.com/get-npm) which can be used to [install pnpm](https://pnpm.js.org/en/installation) if you not already have installed pnpm).\n\nBelow are some commands you can use from a command prompt.  \nThe below *\"[YOUR_ROOT_DIRECTORY_FOR_THE_CLONED_GIT_REPOSITORY]\"* represents something like \n*\"/home/tomas/sweden_crs_transformations_4typescript\"* if you would be using Linux with the user name *\"tomas\"* and would create the git clone into that directory.\n\nThe below commands *\"pnpm install\"* installs *\"dependencies\"* and *\"devDependencies\"* defined in *\"package.json\"* into the subdirectories *\"node_modules\"*.  \n(but since **p**npm is used, there will not be as much disk space used as when *npm* is used)\n\nThe below command *\"pnpm run test\"* will run all [TypeScript jest tests](https://jestjs.io/docs/en/getting-started#using-typescript) in the directory \"sweden_crs_transformations_4typescript/*test*\" which are testing the TypeScript code in the directory \"sweden_crs_transformations_4typescript/*src*\".  \nThe directory \"sweden_crs_transformations_4typescript/*src_generated*\" contains code generated from the TypeScript *\"tsc\"* command, e.g. when running the command *\"pnpx tsc\"*.  \nIn other words, the code in the *src* directory is written but the code in *src_generated* is generated and copied from *src*.  \n\nThe below command *\"pnpm run start\"* in the both example modules *\"example_typescript_console\"* and *\"example_javascript_console\"* will simply show how to use the library *\"sweden_crs_transformations_4typescript\"* from a TypeScript module and from a JavaScript module.  \nThey run the same code as is shown here in this github page in the section with code example.  \n\nWhen you have run the below command *\"pnpm install\"* within the module *\"example_javascript_browser_bundle\"*, the result should be a subdirectory *\"node_modules\"* which includes some files referred to from the page \"example_javascript_browser_bundle/*index.htm*\".  \nThen you should be able to open that \"*index.htm*\" file from a web browser, and it is a simple old-fashioned webpage (i.e. *NOT* using any modern frameworks such as React/Angular/Vue) with some javascript code using the generated bundled javascript file.  \n\nSince the *\"prod\"* script in *\"sweden_crs_transformations_4typescript/package.json\"* copies the needed files to *\"github pages\"* of this github repository, you can also see that webpage here:  \n[https://tomasjohansson.github.io/sweden_crs_transformations_4typescript/browser_example/](https://tomasjohansson.github.io/sweden_crs_transformations_4typescript/browser_example/)  \n\nThe below three 'example_' directories are using the npm package ['@programmerare/sweden_crs_transformations'](https://www.npmjs.com/package/@programmerare/sweden_crs_transformations)  \n\n```shell-script\ngit clone https://github.com/TomasJohansson/sweden_crs_transformations_4typescript\n\ncd [YOUR_ROOT_DIRECTORY_FOR_THE_CLONED_GIT_REPOSITORY]\ncd sweden_crs_transformations_4typescript\npnpm install\npnpm run test\n\ncd [YOUR_ROOT_DIRECTORY_FOR_THE_CLONED_GIT_REPOSITORY]\ncd example_typescript_console\npnpm install\npnpm run start\n\ncd [YOUR_ROOT_DIRECTORY_FOR_THE_CLONED_GIT_REPOSITORY]\ncd example_javascript_console\npnpm install\npnpm run start\n\ncd [YOUR_ROOT_DIRECTORY_FOR_THE_CLONED_GIT_REPOSITORY]\ncd example_javascript_browser_bundle\npnpm install\n```\n\nThe code in this library (e.g. using the commands above) has been tested with the following operating systems and versions of *node*, *npm* and *pnpm*:  \n\nWindows 10:  \n\"node -v\" ==\u003e v14.15.4  \n\"npm -v\" ==\u003e 6.14.11  \n\"pnpm -v\" ==\u003e 5.17.1  \n\nLinux Ubuntu 20.04:  \n\"node -v\" ==\u003e v14.15.5  \n\"npm -v\" ==\u003e 6.14.11  \n\"pnpm -v\" ==\u003e 5.17.1  \n\n\n# Implementations in other programming languages\nCurrently I have implemented this TypeScript library also with the following programming languages and github repositories:   \nC#.NET: [sweden_crs_transformations_4net](https://github.com/TomasJohansson/sweden_crs_transformations_4net)   \nDart: [sweden_crs_transformations_4dart](https://github.com/TomasJohansson/sweden_crs_transformations_4dart)   \n\n# Code example using TypeScript \n\n(pasted below from 'example_typescript_console\\src\\index.ts')\n```typescript\nimport {CrsProjection, CrsCoordinate} from 'sweden_crs_transformations_4typescript';\n\n// The location of Stockholm Central Station, according to Eniro:\n    // https://kartor.eniro.se/m/XRCfh\n    // WGS84 decimal (lat, lon)        59.330231, 18.059196\n    // RT90 (northing, easting)        6580994, 1628294\n    // SWEREF99 TM (northing, easting) 6580822, 674032\nconst stockholmCentralStation_WGS84_latitude = 59.330231;\nconst stockholmCentralStation_WGS84_longitude = 18.059196;\n\n// the below explicit type ': CrsCoordinate' is optional to specify\nconst stockholmWGS84: CrsCoordinate = CrsCoordinate.createCoordinate(\n    CrsProjection.wgs84,\n    stockholmCentralStation_WGS84_latitude,      \n    stockholmCentralStation_WGS84_longitude\n);\n\n// the below explicit type ': CrsCoordinate' is optional to specify\nconst stockholmSweref99tm: CrsCoordinate = stockholmWGS84.transform(CrsProjection.sweref_99_tm);\nconsole.log(`stockholmSweref99tm X: ${stockholmSweref99tm.xLongitude}`);\nconsole.log(`stockholmSweref99tm Y: ${stockholmSweref99tm.yLatitude}`);\nconsole.log(`stockholmSweref99tm toString: ${stockholmSweref99tm.toString()}`);\n// Output from the above:\n// stockholmSweref99tm X: 674032.357\n// stockholmSweref99tm Y: 6580821.991\n// stockholmSweref99tm toString: CrsCoordinate [ Y: 6580821.991 , X: 674032.357 , CRS: SWEREF_99_TM ]\n\n// the below explicit type ': Array\u003cCrsProjection\u003e' is optional to specify\nconst allProjections: Array\u003cCrsProjection\u003e = CrsProjection.getAllCrsProjections();\nfor(const crsProjection of allProjections) {\n    console.log(`${stockholmWGS84.transform(crsProjection)}`);\n}\n// Output from the above loop:\n// CrsCoordinate [ Latitude: 59.330231 , Longitude: 18.059196 , CRS: WGS84 ]\n// CrsCoordinate [ Y: 6580821.991 , X: 674032.357 , CRS: SWEREF_99_TM ]\n// CrsCoordinate [ Y: 6595151.116 , X: 494604.69 , CRS: SWEREF_99_12_00 ]\n// CrsCoordinate [ Y: 6588340.147 , X: 409396.217 , CRS: SWEREF_99_13_30 ]\n// CrsCoordinate [ Y: 6583455.373 , X: 324101.998 , CRS: SWEREF_99_15_00 ]\n// CrsCoordinate [ Y: 6580494.921 , X: 238750.424 , CRS: SWEREF_99_16_30 ]\n// CrsCoordinate [ Y: 6579457.649 , X: 153369.673 , CRS: SWEREF_99_18_00 ]\n// CrsCoordinate [ Y: 6585657.12 , X: 366758.045 , CRS: SWEREF_99_14_15 ]\n// CrsCoordinate [ Y: 6581734.696 , X: 281431.616 , CRS: SWEREF_99_15_45 ]\n// CrsCoordinate [ Y: 6579735.93 , X: 196061.94 , CRS: SWEREF_99_17_15 ]\n// CrsCoordinate [ Y: 6579660.051 , X: 110677.129 , CRS: SWEREF_99_18_45 ]\n// CrsCoordinate [ Y: 6581507.028 , X: 25305.238 , CRS: SWEREF_99_20_15 ]\n// CrsCoordinate [ Y: 6585277.577 , X: -60025.629 , CRS: SWEREF_99_21_45 ]\n// CrsCoordinate [ Y: 6590973.148 , X: -145287.219 , CRS: SWEREF_99_23_15 ]\n// CrsCoordinate [ Y: 6598325.639 , X: 1884004.1 , CRS: RT90_7_5_GON_V ]\n// CrsCoordinate [ Y: 6587493.237 , X: 1756244.287 , CRS: RT90_5_0_GON_V ]\n// CrsCoordinate [ Y: 6580994.18 , X: 1628293.886 , CRS: RT90_2_5_GON_V ]\n// CrsCoordinate [ Y: 6578822.84 , X: 1500248.374 , CRS: RT90_0_0_GON_V ]\n// CrsCoordinate [ Y: 6580977.349 , X: 1372202.721 , CRS: RT90_2_5_GON_O ]\n// CrsCoordinate [ Y: 6587459.595 , X: 1244251.702 , CRS: RT90_5_0_GON_O ]\n```\n\n# Code example using JavaScript\n\nThe JavaScript code can be almost exactly the same as the above example with TypeScript, but remove the types.\nSee the example 'example_javascript_console\\src\\index.js'\n\n# Accuracy of the transformations\n\nThis TypeScript library is based on a port of the [C#.NET library 'sweden_crs_transformations_4net'](https://github.com/TomasJohansson/sweden_crs_transformations_4net/) and therefore it is using the same file \"swedish_crs_coordinates.csv\" as the C# library, for the regression testing of this TypeScript implementation.  \nThere are 18 rows with coordinates in that file, and it will lead to 108 transformations being done when executing all TypeScript tests, e.g. with the command 'pnpm run test'.  \nThe coordinate values in the file have been created as median values from six different Java implementations of CRS transformations.  \nFor more information about the origin of the data file being used, please see the webpage linked above for the C# library 'sweden_crs_transformations_4net'.\n\n# License\n\nMIT.  \n'sweden_crs_transformations_4typescript' is ported from the C# library 'sweden_crs_transformations_4net' (and from 'sweden_crs_transformations_4dart')\nwhich is also licensed with MIT since it started as a fork of the C# library 'MightyLittleGeodesy' which is licensed with the MIT license. (see below).  \n[License text for 'sweden_crs_transformations_4typescript'](https://github.com/TomasJohansson/sweden_crs_transformations_4typescript/blob/typescript_SwedenCrsTransformations/LICENSE)\n\n# License for the original C# repository [MightyLittleGeodesy](https://github.com/bjornsallarp/MightyLittleGeodesy/)\n\nThe text below has been copied from the above linked webpage:\n\u003e 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.\n\nThe text below has been copied from [one of the source files for MightyLittleGeodesy](https://github.com/bjornsallarp/MightyLittleGeodesy/blob/83491fc6e7454f5d90d792610b317eca7a332334/MightyLittleGeodesy/Classes/GaussKreuger.cs).\n```C#\n/*\n * MightyLittleGeodesy \n * RT90, SWEREF99 and WGS84 coordinate transformation library\n * \n * Read my blog @ http://blog.sallarp.com\n * \n * \n * Copyright (C) 2009 Björn Sållarp\n * Permission is hereby granted, free of charge, to any person obtaining a copy of this \n * software and associated documentation files (the \"Software\"), to deal in the Software \n * without restriction, including without limitation the rights to use, copy, modify, \n * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to \n * permit persons to whom the Software is furnished to do so, subject to the following \n * conditions:\n * \n * The above copyright notice and this permission notice shall be included in all copies or \n * substantial portions of the Software.\n * \n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING \n * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND \n * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, \n * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, \n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n */\n ```\n# Swedish coordinate reference systems\nThere are two kind of national CRS being used in Sweden:   \nThe old [RT90](https://www.lantmateriet.se/sv/Kartor-och-geografisk-information/gps-geodesi-och-swepos/Referenssystem/Tvadimensionella-system/RT-90/) (six versions for different local regions)    \nThe new [SWEREF99](https://www.lantmateriet.se/sv/Kartor-och-geografisk-information/gps-geodesi-och-swepos/referenssystem/tvadimensionella-system/sweref-99-projektioner/) (thirteen versions, one for the national \"TM\" and twelve local regions)    \n\nThe above links are for pages in Swedish at the website for [Lantmäteriet](https://en.wikipedia.org/wiki/Lantm%C3%A4teriet) which is a swedish authority for mapping.\n\n[https://www.lantmateriet.se/en/about-lantmateriet/about-lantmateriet/](https://www.lantmateriet.se/en/about-lantmateriet/about-lantmateriet/)   \nQuote from the above URL:\n```Text\nWe map the country, demarcate boundaries and help guarantee secure ownership of Sweden’s real property.   \nYou can get more information and documentation on Sweden’s geography and real properties from us.\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomasjohansson%2Fsweden_crs_transformations_4typescript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftomasjohansson%2Fsweden_crs_transformations_4typescript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomasjohansson%2Fsweden_crs_transformations_4typescript/lists"}