@ulrik.ek/wgs84 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -20
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# wgs84
|
|
2
2
|
|
|
3
3
|
## Introduction
|
|
4
4
|
|
|
@@ -7,48 +7,44 @@ A tiny library fully implemented in Typescript to handle WGS84 coordinates in Ge
|
|
|
7
7
|
- Parses and gives output in GeoJson using the [Point definition](https://en.wikipedia.org/wiki/GeoJSON). If you already have imported the typescript definition for Point in the geojson package you can use that (that is what I do in unit testing). Otherwise you can import `Point` from this package.
|
|
8
8
|
- No dependencies to other NPM modules.
|
|
9
9
|
- The math is based on [Aviation Formulary V1.47 by Ed Williams](https://edwilliams.org/avform147.htm#flat).
|
|
10
|
-
- Functions will throw `Error` if fed impossible values, e.g. incorrectly formatted GeoJSON or lat >= 90 degrees (math will not work!).
|
|
10
|
+
- Functions will throw `Error` if fed impossible values, e.g. incorrectly formatted GeoJSON or lat >= 90 degrees (math will not work!). _Make sure to handle that!_
|
|
11
11
|
|
|
12
12
|
## Getting Started
|
|
13
13
|
|
|
14
14
|
Include in your project as any other NPM package
|
|
15
15
|
|
|
16
|
-
> npm install @
|
|
16
|
+
> npm install @ulrik.ek/wgs84
|
|
17
17
|
|
|
18
18
|
## Usage
|
|
19
19
|
|
|
20
20
|
```typescript
|
|
21
|
-
import
|
|
22
|
-
bearing,
|
|
23
|
-
distance,
|
|
24
|
-
distanceEast,
|
|
25
|
-
distanceNorth,
|
|
26
|
-
distanceUp,
|
|
27
|
-
point,
|
|
28
|
-
Point,
|
|
29
|
-
pointEast,
|
|
30
|
-
pointNorth,
|
|
31
|
-
pointUp
|
|
32
|
-
} from '@UEk/wgs84';
|
|
21
|
+
import * as wgs84 from '@ulrik.ek/wgs84';
|
|
33
22
|
|
|
34
23
|
// helper function to construct a GeoJSON Point
|
|
35
24
|
const lat = 15;
|
|
36
25
|
const lon = 25;
|
|
37
|
-
const p: Point = point(lat, lon);
|
|
26
|
+
const p: wgs84.Point = wgs84.point(lat, lon);
|
|
38
27
|
|
|
39
28
|
// Getting a new point 100m north and 200m east of the first point
|
|
40
|
-
const p1: Point = pointEastOf(
|
|
29
|
+
const p1: wgs84.Point = wgs84.pointEastOf(wgs84.pointNorthOf(p, 100), 200);
|
|
41
30
|
const newLat = p1.coordinates[1]; // GeoJSON uses [lon, lat] order!
|
|
42
31
|
const newLon = p1.coordinates[0];
|
|
32
|
+
console.log(`lat=${newLat}, lon=${newLon}`);
|
|
43
33
|
|
|
44
34
|
// get the distance along north between the 2 points
|
|
45
|
-
|
|
46
|
-
|
|
35
|
+
console.log(`distance along north=${wgs84.distanceNorth(p, p1)}`);
|
|
36
|
+
console.log(`distance along east=${wgs84.distanceEast(p, p1)}`);
|
|
47
37
|
```
|
|
48
38
|
|
|
39
|
+
This will produce the following output
|
|
40
|
+
|
|
41
|
+
> lat=15.000903761214213, lon=25.001859599546577
|
|
42
|
+
> distance along north=99.99999999991357
|
|
43
|
+
> distance along east=200.00084005143466
|
|
44
|
+
|
|
49
45
|
## Documention
|
|
50
46
|
|
|
51
|
-
[Typedoc](doc
|
|
47
|
+
[Typedoc](https://github.com/UEk/wgs84/blob/main/doc/modules.md)
|
|
52
48
|
|
|
53
49
|
# Build and Test
|
|
54
50
|
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ulrik.ek/wgs84",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Basic library for computing small distances between WGS84 coordinates using a flat earth approximation.",
|
|
5
|
-
"author": "Ulrik E",
|
|
5
|
+
"author": "Ulrik E.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"directories": {
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"clean": "npx shx rm -rf ./coverage/ ./report/ ./dist/",
|
|
21
21
|
"build": "tsc --build tsconfig.json",
|
|
22
22
|
"test": "npm run clean && npx jest --clearCache && jest --verbose --coverage --color --modulePathIgnorePatterns=./dist/ && npm run build",
|
|
23
|
+
"run_example": "npx ts-node example/index.ts",
|
|
23
24
|
"type_doc": "npx typedoc --plugin typedoc-plugin-markdown --out doc src/index.ts --excludeNotDocumented"
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|