Skip to content

Commit

Permalink
npm release 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasJohansson committed Feb 17, 2021
1 parent c55ada8 commit ae4345d
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 30 deletions.
93 changes: 93 additions & 0 deletions sweden_crs_transformations_4typescript/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
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:

```shell-script
pnpm install @programmerare/sweden_crs_transformations
```
or
```shell-script
npm install @programmerare/sweden_crs_transformations
```

Then you can use this kind of code from a TypeScript module:
```typescript
import {CrsProjection, CrsCoordinate} from '@programmerare/sweden_crs_transformations';
const coordinate_WGS84_latitude = 59.330231;
const coordinate_WGS84_longitude = 18.059196;
// the below explicit type ': CrsCoordinate' is optional to specify
const coordinate_WGS84: CrsCoordinate = CrsCoordinate.createCoordinate(
CrsProjection.wgs84,
coordinate_WGS84_latitude,
coordinate_WGS84_longitude
);
// the below explicit type ': CrsCoordinate' is optional to specify
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](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*'.
("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))
An alternative for JavaScript, if you are not using *"type": "module"* is to use the *require* syntax instead as below:

```javascript
const {CrsProjection, CrsCoordinate} = require("@programmerare/sweden_crs_transformations");
// Above row: if you are NOT using "type":"module" in your "package.json"
// Below row: if you ARE using "type":"module" in your "package.json"
//import {CrsProjection, CrsCoordinate} from '@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](https://github.com/TomasJohansson/sweden_crs_transformations_4typescript)

20 coordinate reference systems are supported (WGS84 + 6 RT90 + 13 SWEREF99)
![rt90_sweref](https://github.com/TomasJohansson/sweden_crs_transformations_4typescript/blob/typescript_SwedenCrsTransformations/docs/images/rt90_sweref.png?raw=true)

# License information

MIT.
The mathematical code for the transformations is based on the [C# class GaussKreuger.cs](https://github.com/bjornsallarp/MightyLittleGeodesy/blob/master/MightyLittleGeodesy/Classes/GaussKreuger.cs) in the .NET library [MightyLittleGeodesy](https://github.com/bjornsallarp/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](https://github.com/bjornsallarp/MightyLittleGeodesy/blob/83491fc6e7454f5d90d792610b317eca7a332334/MightyLittleGeodesy/Classes/GaussKreuger.cs).
```C#
/*
* MightyLittleGeodesy
* RT90, SWEREF99 and WGS84 coordinate transformation library
*
* Read my blog @ http://blog.sallarp.com
*
*
* Copyright (C) 2009 Björn Sållarp
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the "Software"), to deal in the Software
* without restriction, including without limitation the rights to use, copy, modify,
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
```
32 changes: 2 additions & 30 deletions sweden_crs_transformations_4typescript/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "@programmerare/sweden_crs_transformations",
"version": "0.9.0",
"version": "1.0.0",
"description": "TypeScript/JavaScript library for transformation of geographic coordinates between WGS84 and the Swedish coordinate reference systems SWEREF99 and RT90",
"main": "./src_generated/src/index.js",
"types": "./src_generated/src/index.d.ts",
"keywords": [
"WGS84", "SWEREF99", "RT90", "crs", "coordinate reference system", "swedish", "sweden"
"WGS84", "SWEREF99", "SWEREF99TM", "RT90", "crs", "swedish", "sweden", "sverige", "svenska"
],
"author": "Tomas Johansson (https://programmerare.com/)",
"homepage": "https://github.com/TomasJohansson/sweden_crs_transformations_4typescript",
Expand All @@ -14,33 +14,5 @@
"url": "https://github.com/TomasJohansson/sweden_crs_transformations_4typescript",
"directory": "sweden_crs_transformations_4typescript"
},
"scripts": {
"TODO": "try to reduce the duplications in these npm scripts e.g. try to reuse the output filename in webpack.config.js",

"babdev": "babel dist/swed_crs_transform_bundled_with_webpack.js --out-file dist/swed_crs_transform_bundled_with_webpack__babel_es5.js",
"babprod": "babel dist/swed_crs_transform_bundled_with_webpack.js --out-file dist/swed_crs_transform_bundled_with_webpack__babel_es5_prod.js --presets minify",
"copy_to_dist": "fse-cli copy dist/swed_crs_transform_bundled_with_webpack__babel_es5_prod.js dist/sweden_crs_transformations_4typescript.min.js",
"copy_to_githubpages_TODO_better": "TODO: improve the script at the below row which copies four files to ../docs/browser_example/ ",
"copy_to_githubpages": "fse-cli copy ../example_javascript_browser_bundle/index.htm ../docs/browser_example/index.htm && fse-cli copy ../example_javascript_browser_bundle/javascript_sample.js ../docs/browser_example/javascript_sample.js && fse-cli copy dist/sweden_crs_transformations_4typescript.min.js ../docs/browser_example/node_modules/sweden_crs_transformations_4typescript/dist/sweden_crs_transformations_4typescript.min.js && fse-cli copy ../example_javascript_browser_bundle/node_modules/core-js-bundle/index.js ../docs/browser_example/node_modules/core-js-bundle/index.js",
"prod": "webpack --mode production && pnpm run babprod && pnpm run copy_to_dist && pnpm run copy_to_githubpages && pnpx tsc",
"dev": "webpack --mode development && pnpm run babdev",
"test": "jest"
},
"devDependencies": {
"@atao60/fse-cli": "^0.0.53",
"@babel/cli": "^7.12.16",
"@babel/core": "^7.12.16",
"@babel/preset-env": "^7.12.16",
"@types/jest": "^26.0.20",
"babel-preset-minify": "^0.5.1",
"jest": "^26.6.3",
"ts-jest": "^26.5.0",
"ts-loader": "^8.0.16",
"ts-node": "^9.1.1",
"typescript": "^4.1.3",
"webpack": "^5.21.2",
"webpack-cli": "^4.5.0",
"webpack-dev-server": "^3.11.2"
},
"license": "MIT"
}

0 comments on commit ae4345d

Please sign in to comment.