@mailwoman/spatial 10.0.0 → 10.1.0
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 +2 -2
- package/lib/bbox.ts +41 -34
- package/lib/coordinate/bounds.ts +2 -2
- package/lib/coordinate/formats.ts +10 -27
- package/lib/distance.ts +53 -27
- package/lib/feature.ts +2 -2
- package/lib/geometries/point.ts +41 -33
- package/lib/geometries/polygon.ts +24 -128
- package/lib/geometries/ring-blob.ts +33 -130
- package/lib/google/place-id.ts +4 -2
- package/lib/h3/cell.ts +21 -76
- package/lib/h3/coverage.ts +11 -7
- package/lib/h3/interior-cells.ts +13 -34
- package/lib/h3/polygon-cells.ts +59 -165
- package/lib/{h3/index.ts → h3.ts} +1 -1
- package/lib/index.ts +5 -5
- package/lib/objects.ts +6 -6
- package/lib/open-location-code.ts +11 -42
- package/lib/osgb36.ts +28 -187
- package/lib/polyline.ts +5 -3
- package/lib/position.ts +18 -2
- package/lib/projection/transform.ts +39 -40
- package/lib/{projection/index.ts → projection.ts} +1 -1
- package/lib/well-known-text.ts +8 -8
- package/out/bbox.d.ts +17 -14
- package/out/bbox.d.ts.map +1 -1
- package/out/bbox.js +32 -23
- package/out/bbox.js.map +1 -1
- package/out/coordinate/bounds.d.ts +2 -2
- package/out/coordinate/bounds.js +2 -2
- package/out/coordinate/formats.d.ts +8 -11
- package/out/coordinate/formats.d.ts.map +1 -1
- package/out/coordinate/formats.js +10 -27
- package/out/coordinate/formats.js.map +1 -1
- package/out/distance.d.ts +48 -25
- package/out/distance.d.ts.map +1 -1
- package/out/distance.js +53 -27
- package/out/distance.js.map +1 -1
- package/out/feature.d.ts +2 -2
- package/out/feature.d.ts.map +1 -1
- package/out/geometries/point.d.ts +30 -22
- package/out/geometries/point.d.ts.map +1 -1
- package/out/geometries/point.js +35 -29
- package/out/geometries/point.js.map +1 -1
- package/out/geometries/polygon.d.ts +23 -122
- package/out/geometries/polygon.d.ts.map +1 -1
- package/out/geometries/polygon.js +13 -41
- package/out/geometries/polygon.js.map +1 -1
- package/out/geometries/ring-blob.d.ts +23 -109
- package/out/geometries/ring-blob.d.ts.map +1 -1
- package/out/geometries/ring-blob.js +29 -115
- package/out/geometries/ring-blob.js.map +1 -1
- package/out/{geometries/index.js → geometries.d.ts} +1 -1
- package/out/geometries.d.ts.map +1 -0
- package/out/{geometries/index.d.ts → geometries.js} +1 -1
- package/out/geometries.js.map +1 -0
- package/out/google/place-id.d.ts +4 -2
- package/out/google/place-id.d.ts.map +1 -1
- package/out/google/place-id.js.map +1 -1
- package/out/{google/index.d.ts → google.d.ts} +1 -1
- package/out/google.d.ts.map +1 -0
- package/out/{google/index.js → google.js} +1 -1
- package/out/google.js.map +1 -0
- package/out/h3/cell.d.ts +19 -73
- package/out/h3/cell.d.ts.map +1 -1
- package/out/h3/cell.js +20 -63
- package/out/h3/cell.js.map +1 -1
- package/out/h3/coverage.d.ts +11 -7
- package/out/h3/coverage.d.ts.map +1 -1
- package/out/h3/coverage.js +11 -7
- package/out/h3/coverage.js.map +1 -1
- package/out/h3/interior-cells.d.ts +9 -28
- package/out/h3/interior-cells.d.ts.map +1 -1
- package/out/h3/interior-cells.js +13 -32
- package/out/h3/interior-cells.js.map +1 -1
- package/out/h3/polygon-cells.d.ts +28 -120
- package/out/h3/polygon-cells.d.ts.map +1 -1
- package/out/h3/polygon-cells.js +48 -146
- package/out/h3/polygon-cells.js.map +1 -1
- package/out/{h3/index.d.ts → h3.d.ts} +2 -2
- package/out/h3.d.ts.map +1 -0
- package/out/{h3/index.js → h3.js} +2 -2
- package/out/h3.js.map +1 -0
- package/out/index.d.ts +5 -5
- package/out/index.d.ts.map +1 -1
- package/out/index.js +5 -5
- package/out/index.js.map +1 -1
- package/out/objects.d.ts +6 -6
- package/out/open-location-code.d.ts +11 -22
- package/out/open-location-code.d.ts.map +1 -1
- package/out/open-location-code.js +9 -40
- package/out/open-location-code.js.map +1 -1
- package/out/osgb36.d.ts +21 -97
- package/out/osgb36.d.ts.map +1 -1
- package/out/osgb36.js +12 -165
- package/out/osgb36.js.map +1 -1
- package/out/polyline.d.ts +5 -3
- package/out/polyline.d.ts.map +1 -1
- package/out/polyline.js +5 -3
- package/out/polyline.js.map +1 -1
- package/out/position.d.ts +16 -2
- package/out/position.d.ts.map +1 -1
- package/out/position.js.map +1 -1
- package/out/projection/transform.d.ts +30 -27
- package/out/projection/transform.d.ts.map +1 -1
- package/out/projection/transform.js +14 -16
- package/out/projection/transform.js.map +1 -1
- package/out/{projection/index.d.ts → projection.d.ts} +2 -2
- package/out/projection.d.ts.map +1 -0
- package/out/{projection/index.js → projection.js} +2 -2
- package/out/projection.js.map +1 -0
- package/out/{regions/index.js → regions.d.ts} +1 -1
- package/out/regions.d.ts.map +1 -0
- package/out/{regions/index.d.ts → regions.js} +1 -1
- package/out/regions.js.map +1 -0
- package/out/tools/ogr/stream.d.ts +21 -11
- package/out/tools/ogr/stream.d.ts.map +1 -1
- package/out/tools/ogr/stream.js +16 -9
- package/out/tools/ogr/stream.js.map +1 -1
- package/out/tools/{ogr/index.d.ts → ogr.d.ts} +14 -11
- package/out/tools/ogr.d.ts.map +1 -0
- package/out/tools/{ogr/index.js → ogr.js} +18 -14
- package/out/tools/ogr.js.map +1 -0
- package/out/tools/tsconfig.tsbuildinfo +1 -0
- package/out/tsconfig.test.tsbuildinfo +1 -1
- package/out/well-known-text.d.ts +8 -8
- package/out/well-known-text.js +7 -7
- package/package.json +35 -127
- package/{lib/tools → tools}/ogr/stream.ts +25 -14
- package/{lib/tools/ogr/index.ts → tools/ogr.ts} +25 -19
- package/out/geometries/index.d.ts.map +0 -1
- package/out/geometries/index.js.map +0 -1
- package/out/google/index.d.ts.map +0 -1
- package/out/google/index.js.map +0 -1
- package/out/h3/index.d.ts.map +0 -1
- package/out/h3/index.js.map +0 -1
- package/out/projection/index.d.ts.map +0 -1
- package/out/projection/index.js.map +0 -1
- package/out/regions/index.d.ts.map +0 -1
- package/out/regions/index.js.map +0 -1
- package/out/tools/ogr/index.d.ts.map +0 -1
- package/out/tools/ogr/index.js.map +0 -1
- /package/lib/{geometries/index.ts → geometries.ts} +0 -0
- /package/lib/{google/index.ts → google.ts} +0 -0
- /package/lib/{regions/index.ts → regions.ts} +0 -0
|
@@ -2,51 +2,29 @@
|
|
|
2
2
|
* @copyright Sister Software
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
|
-
*
|
|
6
|
-
* Open Location Code (plus code) decode + nearest-recovery — the coordinate system Google Maps
|
|
7
|
-
* prints on every place card, which makes it a first-class user register in countries with sparse
|
|
8
|
-
* street addressing (the Nicaraguan board rows arrived exactly this way). Pure arithmetic over the
|
|
9
|
-
* published spec (https://github.com/google/open-location-code/blob/main/docs/specification.md);
|
|
10
|
-
* no dependency, no I/O.
|
|
11
|
-
*
|
|
12
|
-
* A FULL code (8 digits, a `+`, then 2–3 more) decodes directly. A SHORT code (2–6 leading digits
|
|
13
|
-
* removed, e.g. `VFQ6+92P`) is only meaningful near a reference point — the removed prefix is
|
|
14
|
-
* recovered from the reference, then the candidate cell is shifted by whole prefix-resolutions if
|
|
15
|
-
* a neighboring cell sits closer (the spec's `recoverNearest`). The reference in an address is the
|
|
16
|
-
* RESOLVED LOCALITY, which is why the geocode wiring recovers after the admin walk.
|
|
17
|
-
*/
|
|
18
|
-
/**
|
|
19
|
-
* The 20-character OLC digit set. Deliberately excludes letters that read as words or digits (no A/E/I/L/N/O/S/T…), so
|
|
20
|
-
* a matched token is very unlikely to be ordinary text.
|
|
21
5
|
*/
|
|
22
6
|
const OLC_ALPHABET = "23456789CFGHJMPQRVWX";
|
|
23
7
|
const OLC_DIGIT_VALUE = new Map([...OLC_ALPHABET].map((c, i) => [c, i]));
|
|
24
|
-
/**
|
|
25
|
-
* Degree width of each pair-position, most significant first: the pair at index i spans `20^(2-i)` degrees. Ten pair
|
|
26
|
-
* digits (five lat/lon pairs) take a cell to 1/400° ≈ 275 m; grid digits refine further.
|
|
27
|
-
*/
|
|
28
8
|
const PAIR_RESOLUTIONS = [20, 1, 1 / 20, 1 / 400, 1 / 8000];
|
|
29
|
-
/**
|
|
30
|
-
* Grid refinement past ten digits: each digit subdivides the cell into 4 columns × 5 rows.
|
|
31
|
-
*/
|
|
32
9
|
const GRID_COLUMNS = 4;
|
|
33
10
|
const GRID_ROWS = 5;
|
|
34
11
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
12
|
+
* Returns true for a full plus code of exactly 8 digits, `+`, and 2 or 3 digits.
|
|
13
|
+
*
|
|
14
|
+
* It rejects the padded and longer forms the spec allows, since addresses use only the 10–11 digit form.
|
|
37
15
|
*/
|
|
38
16
|
export function isFullPlusCode(token) {
|
|
39
17
|
return /^[23456789CFGHJMPQRVWX]{8}\+[23456789CFGHJMPQRVWX]{2,3}$/i.test(token);
|
|
40
18
|
}
|
|
41
19
|
/**
|
|
42
|
-
*
|
|
43
|
-
*
|
|
20
|
+
* Returns true for a short plus code with 2, 4 or 6 digits before the `+`,
|
|
21
|
+
* such as the `VFQ6+92P` form Google prints on place cards.
|
|
44
22
|
*/
|
|
45
23
|
export function isShortPlusCode(token) {
|
|
46
24
|
return /^[23456789CFGHJMPQRVWX]{2,6}\+[23456789CFGHJMPQRVWX]{2,3}$/i.test(token) && token.indexOf("+") % 2 === 0;
|
|
47
25
|
}
|
|
48
26
|
/**
|
|
49
|
-
*
|
|
27
|
+
* Decodes a full plus code to its cell, returning null for anything {@link isFullPlusCode} rejects.
|
|
50
28
|
*/
|
|
51
29
|
export function decodePlusCode(code) {
|
|
52
30
|
if (!isFullPlusCode(code))
|
|
@@ -56,7 +34,6 @@ export function decodePlusCode(code) {
|
|
|
56
34
|
let lonLo = -180;
|
|
57
35
|
let latSpan = 400;
|
|
58
36
|
let lonSpan = 400;
|
|
59
|
-
// The first ten digits arrive in (lat, lon) pairs.
|
|
60
37
|
const pairCount = Math.min(digits.length, 10);
|
|
61
38
|
for (let i = 0; i < pairCount; i += 2) {
|
|
62
39
|
const resolution = PAIR_RESOLUTIONS[i / 2];
|
|
@@ -65,7 +42,6 @@ export function decodePlusCode(code) {
|
|
|
65
42
|
latSpan = resolution;
|
|
66
43
|
lonSpan = resolution;
|
|
67
44
|
}
|
|
68
|
-
// Grid refinement: each further digit indexes a 4×5 (columns × rows) subdivision.
|
|
69
45
|
for (let i = 10; i < digits.length; i++) {
|
|
70
46
|
const value = OLC_DIGIT_VALUE.get(digits[i]);
|
|
71
47
|
latSpan /= GRID_ROWS;
|
|
@@ -80,10 +56,6 @@ export function decodePlusCode(code) {
|
|
|
80
56
|
lonSpanDeg: lonSpan,
|
|
81
57
|
};
|
|
82
58
|
}
|
|
83
|
-
/**
|
|
84
|
-
* Encode the pair digits of a coordinate to `length` digits (length ≤ 10, even) — the prefix implementation
|
|
85
|
-
* {@link recoverNearestPlusCode} needs; not a general encoder.
|
|
86
|
-
*/
|
|
87
59
|
function encodePairDigits(lat, lon, length) {
|
|
88
60
|
let latVal = Math.min(Math.max(lat + 90, 0), 180 - 1e-12);
|
|
89
61
|
let lonVal = lon + 180;
|
|
@@ -100,9 +72,9 @@ function encodePairDigits(lat, lon, length) {
|
|
|
100
72
|
return out;
|
|
101
73
|
}
|
|
102
74
|
/**
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
75
|
+
* Recovers a short plus code to the matching cell nearest a reference coordinate,
|
|
76
|
+
* following the spec's `recoverNearest`.
|
|
77
|
+
* It returns null for an invalid short code.
|
|
106
78
|
*/
|
|
107
79
|
export function recoverNearestPlusCode(shortCode, refLat, refLon) {
|
|
108
80
|
if (!isShortPlusCode(shortCode))
|
|
@@ -113,9 +85,6 @@ export function recoverNearestPlusCode(shortCode, refLat, refLon) {
|
|
|
113
85
|
const candidate = decodePlusCode(prefix + upper);
|
|
114
86
|
if (!candidate)
|
|
115
87
|
return null;
|
|
116
|
-
// The prefix pins the cell modulo its own resolution; the nearest bearer of the short code may sit
|
|
117
|
-
// one prefix-cell away (the reference near a cell edge). Shift by whole prefix-resolutions, never
|
|
118
|
-
// past the poles.
|
|
119
88
|
const LAT_MIN = -90;
|
|
120
89
|
const LAT_MAX = 90;
|
|
121
90
|
const prefixResolution = PAIR_RESOLUTIONS[missing / 2 - 1];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"open-location-code.js","sourceRoot":"","sources":["../lib/open-location-code.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"open-location-code.js","sourceRoot":"","sources":["../lib/open-location-code.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,YAAY,GAAG,sBAAsB,CAAA;AAE3C,MAAM,eAAe,GAAG,IAAI,GAAG,CAAiB,CAAC,GAAG,YAAY,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;AAExF,MAAM,gBAAgB,GAAG,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,IAAI,CAAU,CAAA;AAEpE,MAAM,YAAY,GAAG,CAAC,CAAA;AACtB,MAAM,SAAS,GAAG,CAAC,CAAA;AAanB;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,KAAa;IAC3C,OAAO,2DAA2D,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;AAC/E,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,KAAa;IAC5C,OAAO,6DAA6D,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;AACjH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,IAAY;IAC1C,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAA;IACtC,MAAM,MAAM,GAAG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A;AACd,CAAC"}
|
package/out/osgb36.d.ts
CHANGED
|
@@ -2,124 +2,48 @@
|
|
|
2
2
|
* @copyright Sister Software.
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
|
-
*
|
|
6
|
-
* OSGB36 / British National Grid (EPSG:27700) → WGS84 (EPSG:4326).
|
|
7
|
-
*
|
|
8
|
-
* Ordnance Survey ships its open products in eastings/northings on the National Grid, not in
|
|
9
|
-
* degrees — Code-Point Open, OS Open UPRN, OS Open Names all do. Nothing else in the repo speaks
|
|
10
|
-
* that coordinate system, so this module is the one place that converts it, and it lives in
|
|
11
|
-
* `@mailwoman/spatial` because that is the math home (`projection.ts` names the datums; this file
|
|
12
|
-
* moves between two of them).
|
|
13
|
-
*
|
|
14
|
-
* Two steps, both from OS's own "A Guide to Coordinate Systems in Great Britain":
|
|
15
|
-
*
|
|
16
|
-
* 1. **Inverse transverse Mercator (Redfearn's series)** — National Grid E/N → OSGB36 geodetic
|
|
17
|
-
* lat/lon on the Airy 1830 ellipsoid. This step is EXACT to well below a millimetre; it is
|
|
18
|
-
* plain map-projection algebra with no empirical content, and {@link osgb36GridToAiryLatLon}
|
|
19
|
-
* reproduces the guide's Annexe C.2 worked example to **1.3e-5 arc-seconds (~0.4 mm)**, which
|
|
20
|
-
* is that example's own published rounding rather than our error.
|
|
21
|
-
* 2. **Seven-parameter Helmert** — Airy-1830 geodetic → geocentric cartesian → rotate/scale/shift
|
|
22
|
-
* → WGS84 (GRS80) geodetic. This step is APPROXIMATE, and that is the whole accuracy story
|
|
23
|
-
* below. Against the guide's own Annexe D Helmert worked example — which uses this same
|
|
24
|
-
* transform, so it tests the implementation and not the approximation — the round trip lands
|
|
25
|
-
* **8.4 mm** out, i.e. the published DMS rounding plus the ignored ellipsoidal height.
|
|
26
|
-
*
|
|
27
|
-
* ## Accuracy: ±5 m, measured, and why we accept it
|
|
28
|
-
*
|
|
29
|
-
* OSGB36 is a 1936 theodolite triangulation, not a geocentric datum. Its distortions relative to
|
|
30
|
-
* WGS84 are irregular across GB — a couple of metres of local warp that no rigid-body transform can
|
|
31
|
-
* absorb. OS's exact answer is **OSTN15**, a published ~1.5 MB grid of per-cell E/N shifts; the
|
|
32
|
-
* seven-parameter Helmert implemented here is OS's own documented approximation to it, which the
|
|
33
|
-
* guide rates at "up to 3.5 m (95%)".
|
|
34
|
-
*
|
|
35
|
-
* MEASURED against OS's official 40-point OSTN15/OSGM15 test set (`OSTN15_OSGM15_TestInput_*`, the
|
|
36
|
-
* developer-pack vectors, joining each point's published OSGB36 E/N to its published ETRS89 lat/lon):
|
|
37
|
-
*
|
|
38
|
-
* | p50 | p90 | p95 | max | mean |
|
|
39
|
-
* | ------ | ------ | ------ | ------ | ------ |
|
|
40
|
-
* | 1.74 m | 3.23 m | 4.18 m | 4.91 m | 1.94 m |
|
|
41
|
-
*
|
|
42
|
-
* All 40 land under 5 m. The worst are exactly where OS warns the datum thins out — TP31 St Kilda
|
|
43
|
-
* (4.91 m), TP01 Scilly (4.72 m), TP32 Outer Hebrides (4.18 m); the mainland points sit near 1–2 m.
|
|
44
|
-
* p95 runs a little above the guide's 3.5 m because we discard ellipsoidal height (see
|
|
45
|
-
* {@link osgb36AiryToWGS84}), and because two of the three worst points are offshore rocks where
|
|
46
|
-
* "OSGB36 does not exist" in OS's own words.
|
|
47
|
-
*
|
|
48
|
-
* We take that error deliberately, because of what the coordinates are FOR. A Code-Point Open
|
|
49
|
-
* centroid is the mean position of a postcode unit's delivery points snapped to the nearest real
|
|
50
|
-
* address — the unit itself spans tens to hundreds of metres, and the resolver uses the centroid to
|
|
51
|
-
* pick a locality and rank candidates within a few hundred metres. A 2 m datum error is one to two
|
|
52
|
-
* orders of magnitude below the quantity being represented. Nothing downstream reads a postcode
|
|
53
|
-
* centroid at metre precision.
|
|
54
|
-
*
|
|
55
|
-
* **Do not use this module for anything that does.** Surveying, cadastral work, or any consumer
|
|
56
|
-
* comparing our coordinates against another OSGB36-derived dataset at sub-10 m tolerance needs
|
|
57
|
-
* OSTN15, which means shipping the shift grid. If that day comes, the swap point is
|
|
58
|
-
* {@link osgb36AiryToWGS84} — swap the Helmert for a grid interpolation and the projection step
|
|
59
|
-
* above it is unchanged.
|
|
60
|
-
*
|
|
61
|
-
* @see https://www.ordnancesurvey.co.uk/documents/resources/guide-coordinate-systems-great-britain.pdf
|
|
62
5
|
*/
|
|
63
|
-
import type { Coordinates2D } from "#position";
|
|
64
|
-
/**
|
|
65
|
-
* A geodetic position on an unspecified ellipsoid, in degrees. Which ellipsoid is the caller's business — the whole
|
|
66
|
-
* point of this module is that the same numbers mean different places on Airy 1830 and on GRS80.
|
|
67
|
-
*/
|
|
68
|
-
export interface GeodeticLatLon {
|
|
69
|
-
/**
|
|
70
|
-
* Latitude in decimal degrees, positive north.
|
|
71
|
-
*/
|
|
72
|
-
latitude: number;
|
|
73
|
-
/**
|
|
74
|
-
* Longitude in decimal degrees, positive east.
|
|
75
|
-
*/
|
|
76
|
-
longitude: number;
|
|
77
|
-
}
|
|
6
|
+
import type { Coordinates2D, GeoCoordinate } from "#position";
|
|
78
7
|
/**
|
|
79
|
-
* A position on the British National Grid, in
|
|
8
|
+
* A position on the British National Grid, in meters.
|
|
80
9
|
*/
|
|
81
10
|
export interface NationalGridPoint {
|
|
82
11
|
/**
|
|
83
|
-
*
|
|
12
|
+
* Distance east in meters.
|
|
13
|
+
* Valid GB values run roughly from 0 to 700,000.
|
|
84
14
|
*/
|
|
85
15
|
easting: number;
|
|
86
16
|
/**
|
|
87
|
-
*
|
|
17
|
+
* Distance north in meters.
|
|
18
|
+
* Valid GB values run roughly from 0 to 1,300,000.
|
|
88
19
|
*/
|
|
89
20
|
northing: number;
|
|
90
21
|
}
|
|
91
22
|
/**
|
|
92
|
-
*
|
|
93
|
-
*
|
|
23
|
+
* Converts a National Grid easting and northing to OSGB36 latitude and longitude
|
|
24
|
+
* on the Airy 1830 ellipsoid, without a datum shift.
|
|
94
25
|
*
|
|
95
|
-
*
|
|
96
|
-
* so it is NOT a WGS84 coordinate and must not be handed to anything expecting one; feed it to
|
|
97
|
-
* {@link osgb36AiryToWGS84}. Exported separately so the projection can be tested against OS's worked example
|
|
98
|
-
* independently of the Helmert, which is the only way to tell a projection bug from a datum-shift bug.
|
|
26
|
+
* Pass the result to {@link osgb36AiryToWGS84} to get WGS84 coordinates.
|
|
99
27
|
*/
|
|
100
|
-
export declare function osgb36GridToAiryLatLon({ easting, northing }: NationalGridPoint):
|
|
28
|
+
export declare function osgb36GridToAiryLatLon({ easting, northing }: NationalGridPoint): GeoCoordinate;
|
|
101
29
|
/**
|
|
102
|
-
*
|
|
30
|
+
* Converts OSGB36 latitude and longitude on Airy 1830 to WGS84 with the seven-parameter
|
|
31
|
+
* Helmert transform, accurate to about 5 m.
|
|
103
32
|
*
|
|
104
|
-
*
|
|
105
|
-
* Heights are not modelled: the input is treated as sitting on the Airy ellipsoid and the output's ellipsoidal height
|
|
106
|
-
* is discarded. For a horizontal postcode centroid that costs well under a metre; for anything vertical it is wrong by
|
|
107
|
-
* the ~50 m geoid–ellipsoid separation over GB, so this function does not pretend to return a height.
|
|
33
|
+
* The transform ignores height, so use the result for horizontal positions only.
|
|
108
34
|
*/
|
|
109
|
-
export declare function osgb36AiryToWGS84({ latitude, longitude }:
|
|
35
|
+
export declare function osgb36AiryToWGS84({ latitude, longitude }: GeoCoordinate): GeoCoordinate;
|
|
110
36
|
/**
|
|
111
|
-
*
|
|
112
|
-
*
|
|
37
|
+
* Converts a British National Grid (EPSG:27700) easting and northing to WGS84
|
|
38
|
+
* (EPSG:4326) latitude and longitude, accurate to about 5 m across GB.
|
|
113
39
|
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
* Open uses exactly that to mean "no coordinate available" (its 865 positional-quality-90 rows). Callers must filter
|
|
117
|
-
* those rows themselves — a zero here is a legitimate coordinate, so this module cannot tell the difference.
|
|
40
|
+
* It converts `{ easting: 0, northing: 0 }` like any other point, so callers must
|
|
41
|
+
* filter out Code-Point Open's zero placeholder rows.
|
|
118
42
|
*/
|
|
119
|
-
export declare function osgb36ToWGS84(point: NationalGridPoint):
|
|
43
|
+
export declare function osgb36ToWGS84(point: NationalGridPoint): GeoCoordinate;
|
|
120
44
|
/**
|
|
121
|
-
*
|
|
122
|
-
*
|
|
45
|
+
* Converts a National Grid point to WGS84 in GeoJSON `[longitude, latitude]` order,
|
|
46
|
+
* matching {@link Coordinates2D}.
|
|
123
47
|
*/
|
|
124
48
|
export declare function osgb36ToCoordinates2D(point: NationalGridPoint): Coordinates2D;
|
|
125
49
|
//# sourceMappingURL=osgb36.d.ts.map
|
package/out/osgb36.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"osgb36.d.ts","sourceRoot":"","sources":["../lib/osgb36.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"osgb36.d.ts","sourceRoot":"","sources":["../lib/osgb36.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AA4C7D;;GAEG;AACH,MAAM,WAAW,iBAAiB;IACjC;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAA;IAEf;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAA;CAChB;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,iBAAiB,GAAG,aAAa,CAmE9F;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,aAAa,GAAG,aAAa,CA0CvF;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,iBAAiB,GAAG,aAAa,CAErE;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,iBAAiB,GAAG,aAAa,CAI7E"}
|
package/out/osgb36.js
CHANGED
|
@@ -2,175 +2,34 @@
|
|
|
2
2
|
* @copyright Sister Software.
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
|
-
*
|
|
6
|
-
* OSGB36 / British National Grid (EPSG:27700) → WGS84 (EPSG:4326).
|
|
7
|
-
*
|
|
8
|
-
* Ordnance Survey ships its open products in eastings/northings on the National Grid, not in
|
|
9
|
-
* degrees — Code-Point Open, OS Open UPRN, OS Open Names all do. Nothing else in the repo speaks
|
|
10
|
-
* that coordinate system, so this module is the one place that converts it, and it lives in
|
|
11
|
-
* `@mailwoman/spatial` because that is the math home (`projection.ts` names the datums; this file
|
|
12
|
-
* moves between two of them).
|
|
13
|
-
*
|
|
14
|
-
* Two steps, both from OS's own "A Guide to Coordinate Systems in Great Britain":
|
|
15
|
-
*
|
|
16
|
-
* 1. **Inverse transverse Mercator (Redfearn's series)** — National Grid E/N → OSGB36 geodetic
|
|
17
|
-
* lat/lon on the Airy 1830 ellipsoid. This step is EXACT to well below a millimetre; it is
|
|
18
|
-
* plain map-projection algebra with no empirical content, and {@link osgb36GridToAiryLatLon}
|
|
19
|
-
* reproduces the guide's Annexe C.2 worked example to **1.3e-5 arc-seconds (~0.4 mm)**, which
|
|
20
|
-
* is that example's own published rounding rather than our error.
|
|
21
|
-
* 2. **Seven-parameter Helmert** — Airy-1830 geodetic → geocentric cartesian → rotate/scale/shift
|
|
22
|
-
* → WGS84 (GRS80) geodetic. This step is APPROXIMATE, and that is the whole accuracy story
|
|
23
|
-
* below. Against the guide's own Annexe D Helmert worked example — which uses this same
|
|
24
|
-
* transform, so it tests the implementation and not the approximation — the round trip lands
|
|
25
|
-
* **8.4 mm** out, i.e. the published DMS rounding plus the ignored ellipsoidal height.
|
|
26
|
-
*
|
|
27
|
-
* ## Accuracy: ±5 m, measured, and why we accept it
|
|
28
|
-
*
|
|
29
|
-
* OSGB36 is a 1936 theodolite triangulation, not a geocentric datum. Its distortions relative to
|
|
30
|
-
* WGS84 are irregular across GB — a couple of metres of local warp that no rigid-body transform can
|
|
31
|
-
* absorb. OS's exact answer is **OSTN15**, a published ~1.5 MB grid of per-cell E/N shifts; the
|
|
32
|
-
* seven-parameter Helmert implemented here is OS's own documented approximation to it, which the
|
|
33
|
-
* guide rates at "up to 3.5 m (95%)".
|
|
34
|
-
*
|
|
35
|
-
* MEASURED against OS's official 40-point OSTN15/OSGM15 test set (`OSTN15_OSGM15_TestInput_*`, the
|
|
36
|
-
* developer-pack vectors, joining each point's published OSGB36 E/N to its published ETRS89 lat/lon):
|
|
37
|
-
*
|
|
38
|
-
* | p50 | p90 | p95 | max | mean |
|
|
39
|
-
* | ------ | ------ | ------ | ------ | ------ |
|
|
40
|
-
* | 1.74 m | 3.23 m | 4.18 m | 4.91 m | 1.94 m |
|
|
41
|
-
*
|
|
42
|
-
* All 40 land under 5 m. The worst are exactly where OS warns the datum thins out — TP31 St Kilda
|
|
43
|
-
* (4.91 m), TP01 Scilly (4.72 m), TP32 Outer Hebrides (4.18 m); the mainland points sit near 1–2 m.
|
|
44
|
-
* p95 runs a little above the guide's 3.5 m because we discard ellipsoidal height (see
|
|
45
|
-
* {@link osgb36AiryToWGS84}), and because two of the three worst points are offshore rocks where
|
|
46
|
-
* "OSGB36 does not exist" in OS's own words.
|
|
47
|
-
*
|
|
48
|
-
* We take that error deliberately, because of what the coordinates are FOR. A Code-Point Open
|
|
49
|
-
* centroid is the mean position of a postcode unit's delivery points snapped to the nearest real
|
|
50
|
-
* address — the unit itself spans tens to hundreds of metres, and the resolver uses the centroid to
|
|
51
|
-
* pick a locality and rank candidates within a few hundred metres. A 2 m datum error is one to two
|
|
52
|
-
* orders of magnitude below the quantity being represented. Nothing downstream reads a postcode
|
|
53
|
-
* centroid at metre precision.
|
|
54
|
-
*
|
|
55
|
-
* **Do not use this module for anything that does.** Surveying, cadastral work, or any consumer
|
|
56
|
-
* comparing our coordinates against another OSGB36-derived dataset at sub-10 m tolerance needs
|
|
57
|
-
* OSTN15, which means shipping the shift grid. If that day comes, the swap point is
|
|
58
|
-
* {@link osgb36AiryToWGS84} — swap the Helmert for a grid interpolation and the projection step
|
|
59
|
-
* above it is unchanged.
|
|
60
|
-
*
|
|
61
|
-
* @see https://www.ordnancesurvey.co.uk/documents/resources/guide-coordinate-systems-great-britain.pdf
|
|
62
|
-
*/
|
|
63
|
-
/**
|
|
64
|
-
* Semi-major axis of the Airy 1830 ellipsoid, in metres — the figure of the Earth OSGB36 is referenced to.
|
|
65
5
|
*/
|
|
66
6
|
const AIRY_1830_A = 6_377_563.396;
|
|
67
|
-
/**
|
|
68
|
-
* Semi-minor axis of the Airy 1830 ellipsoid, in metres.
|
|
69
|
-
*/
|
|
70
7
|
const AIRY_1830_B = 6_356_256.909;
|
|
71
|
-
/**
|
|
72
|
-
* Semi-major axis of the GRS80 ellipsoid, in metres. WGS84's own semi-major axis is identical; the two ellipsoids
|
|
73
|
-
* differ only in the flattening's last digits (~0.1 mm at the pole), far below this module's error budget.
|
|
74
|
-
*/
|
|
75
8
|
const GRS80_A = 6_378_137;
|
|
76
|
-
/**
|
|
77
|
-
* Semi-minor axis of the GRS80 ellipsoid, in metres.
|
|
78
|
-
*/
|
|
79
9
|
const GRS80_B = 6_356_752.3141;
|
|
80
|
-
/**
|
|
81
|
-
* Scale factor on the National Grid's central meridian.
|
|
82
|
-
*/
|
|
83
10
|
const NATIONAL_GRID_F0 = 0.9996012717;
|
|
84
|
-
/**
|
|
85
|
-
* Latitude of the National Grid's true origin, 49° N, in radians.
|
|
86
|
-
*/
|
|
87
11
|
const NATIONAL_GRID_LAT0 = (49 * Math.PI) / 180;
|
|
88
|
-
/**
|
|
89
|
-
* Longitude of the National Grid's true origin, 2° W, in radians.
|
|
90
|
-
*/
|
|
91
12
|
const NATIONAL_GRID_LON0 = (-2 * Math.PI) / 180;
|
|
92
|
-
/**
|
|
93
|
-
* Easting of the National Grid's true origin (the "false easting"), in metres.
|
|
94
|
-
*/
|
|
95
13
|
const NATIONAL_GRID_E0 = 400_000;
|
|
96
|
-
/**
|
|
97
|
-
* Northing of the National Grid's true origin (the "false northing"), in metres. Negative because the true origin sits
|
|
98
|
-
* south-west of the grid's own zero.
|
|
99
|
-
*/
|
|
100
14
|
const NATIONAL_GRID_N0 = -100_000;
|
|
101
|
-
/**
|
|
102
|
-
* Arc-seconds → radians. The Helmert rotations are published in arc-seconds.
|
|
103
|
-
*/
|
|
104
15
|
const ARCSEC_TO_RAD = Math.PI / (180 * 3600);
|
|
105
|
-
/**
|
|
106
|
-
* Parts-per-million → unitless scale. The Helmert scale factor is published in ppm.
|
|
107
|
-
*/
|
|
108
16
|
const PPM = 1e-6;
|
|
109
|
-
/**
|
|
110
|
-
* Convergence threshold for the meridional-arc iteration in {@link osgb36GridToAiryLatLon}, in METRES of northing. OS's
|
|
111
|
-
* guide specifies 0.01 mm; this is that figure. It bounds the northing residual, not the latitude, which is why it is
|
|
112
|
-
* expressed in metres and compared against `northing - N0 - M`.
|
|
113
|
-
*/
|
|
114
17
|
const MERIDIONAL_ARC_TOLERANCE_M = 1e-5;
|
|
115
|
-
/**
|
|
116
|
-
* Convergence threshold for the cartesian→geodetic latitude iteration in {@link osgb36AiryToWGS84}, in RADIANS. 1e-13
|
|
117
|
-
* rad is ~0.6 µm on the ground — far below anything this module claims, and reached in four or five passes at GB
|
|
118
|
-
* latitudes.
|
|
119
|
-
*/
|
|
120
18
|
const GEODETIC_LATITUDE_TOLERANCE_RAD = 1e-13;
|
|
121
|
-
/**
|
|
122
|
-
* The seven-parameter Helmert transformation taking OSGB36 (Airy 1830) geocentric cartesian coordinates to WGS84.
|
|
123
|
-
*
|
|
124
|
-
* OS publishes this transform in the ETRS89/WGS84 → OSGB36 direction (guide table 4), as `tx = -446.448, ty = +125.157,
|
|
125
|
-
* tz = -542.060, s = +20.4894 ppm, rx = -0.1502", ry = -0.2470", rz = -0.8421"`. We need the OTHER direction, so every
|
|
126
|
-
* parameter is negated — valid to well inside the transform's own metre-scale error because the rotations are
|
|
127
|
-
* microradian-scale and the second-order terms of a proper inversion are sub-millimetre.
|
|
128
|
-
*
|
|
129
|
-
* The rotation convention is **Position Vector** (EPSG method 1033), NOT Coordinate Frame Rotation (EPSG 1032). The two
|
|
130
|
-
* differ only in the sign of the three rotations, which is why citing the method code matters more than it looks: paste
|
|
131
|
-
* these numbers into a library expecting 1032 and every result moves by roughly 20 m with no error raised.
|
|
132
|
-
*
|
|
133
|
-
* Getting a sign wrong here does not produce a subtly worse answer; it produces a coordinate tens to hundreds of metres
|
|
134
|
-
* out, in a consistent direction — which reads as a plausible coordinate. That is what the Annexe D test is for.
|
|
135
|
-
*/
|
|
136
19
|
const OSGB36_TO_WGS84_HELMERT = {
|
|
137
|
-
/**
|
|
138
|
-
* X translation, metres.
|
|
139
|
-
*/
|
|
140
20
|
tx: 446.448,
|
|
141
|
-
/**
|
|
142
|
-
* Y translation, metres.
|
|
143
|
-
*/
|
|
144
21
|
ty: -125.157,
|
|
145
|
-
/**
|
|
146
|
-
* Z translation, metres.
|
|
147
|
-
*/
|
|
148
22
|
tz: 542.06,
|
|
149
|
-
/**
|
|
150
|
-
* Scale correction, parts per million.
|
|
151
|
-
*/
|
|
152
23
|
scalePPM: -20.4894,
|
|
153
|
-
/**
|
|
154
|
-
* Rotation about the X axis, arc-seconds.
|
|
155
|
-
*/
|
|
156
24
|
rx: 0.1502,
|
|
157
|
-
/**
|
|
158
|
-
* Rotation about the Y axis, arc-seconds.
|
|
159
|
-
*/
|
|
160
25
|
ry: 0.247,
|
|
161
|
-
/**
|
|
162
|
-
* Rotation about the Z axis, arc-seconds.
|
|
163
|
-
*/
|
|
164
26
|
rz: 0.8421,
|
|
165
27
|
};
|
|
166
28
|
/**
|
|
167
|
-
*
|
|
168
|
-
*
|
|
29
|
+
* Converts a National Grid easting and northing to OSGB36 latitude and longitude
|
|
30
|
+
* on the Airy 1830 ellipsoid, without a datum shift.
|
|
169
31
|
*
|
|
170
|
-
*
|
|
171
|
-
* so it is NOT a WGS84 coordinate and must not be handed to anything expecting one; feed it to
|
|
172
|
-
* {@link osgb36AiryToWGS84}. Exported separately so the projection can be tested against OS's worked example
|
|
173
|
-
* independently of the Helmert, which is the only way to tell a projection bug from a datum-shift bug.
|
|
32
|
+
* Pass the result to {@link osgb36AiryToWGS84} to get WGS84 coordinates.
|
|
174
33
|
*/
|
|
175
34
|
export function osgb36GridToAiryLatLon({ easting, northing }) {
|
|
176
35
|
const a = AIRY_1830_A;
|
|
@@ -180,13 +39,10 @@ export function osgb36GridToAiryLatLon({ easting, northing }) {
|
|
|
180
39
|
const lon0 = NATIONAL_GRID_LON0;
|
|
181
40
|
const e0 = NATIONAL_GRID_E0;
|
|
182
41
|
const n0 = NATIONAL_GRID_N0;
|
|
183
|
-
// Eccentricity squared of the Airy ellipsoid, and the `n` series parameter.
|
|
184
42
|
const e2 = (a * a - b * b) / (a * a);
|
|
185
43
|
const n = (a - b) / (a + b);
|
|
186
44
|
const n2 = n * n;
|
|
187
45
|
const n3 = n2 * n;
|
|
188
|
-
// Iterate latitude until the meridional arc `M` matches the northing. OS's guide specifies a 0.01 mm
|
|
189
|
-
// threshold; it converges in three or four passes anywhere in GB.
|
|
190
46
|
let lat = lat0;
|
|
191
47
|
let m = 0;
|
|
192
48
|
do {
|
|
@@ -207,7 +63,6 @@ export function osgb36GridToAiryLatLon({ easting, northing }) {
|
|
|
207
63
|
const tan2 = tanLat * tanLat;
|
|
208
64
|
const tan4 = tan2 * tan2;
|
|
209
65
|
const tan6 = tan4 * tan2;
|
|
210
|
-
// `nu` = transverse radius of curvature; `rho` = meridional radius; `eta2` = their ratio less one.
|
|
211
66
|
const nu = a * f0 * (1 - e2 * sinLat * sinLat) ** -0.5;
|
|
212
67
|
const rho = a * f0 * (1 - e2) * (1 - e2 * sinLat * sinLat) ** -1.5;
|
|
213
68
|
const eta2 = nu / rho - 1;
|
|
@@ -234,16 +89,13 @@ export function osgb36GridToAiryLatLon({ easting, northing }) {
|
|
|
234
89
|
};
|
|
235
90
|
}
|
|
236
91
|
/**
|
|
237
|
-
*
|
|
92
|
+
* Converts OSGB36 latitude and longitude on Airy 1830 to WGS84 with the seven-parameter
|
|
93
|
+
* Helmert transform, accurate to about 5 m.
|
|
238
94
|
*
|
|
239
|
-
*
|
|
240
|
-
* Heights are not modelled: the input is treated as sitting on the Airy ellipsoid and the output's ellipsoidal height
|
|
241
|
-
* is discarded. For a horizontal postcode centroid that costs well under a metre; for anything vertical it is wrong by
|
|
242
|
-
* the ~50 m geoid–ellipsoid separation over GB, so this function does not pretend to return a height.
|
|
95
|
+
* The transform ignores height, so use the result for horizontal positions only.
|
|
243
96
|
*/
|
|
244
97
|
export function osgb36AiryToWGS84({ latitude, longitude }) {
|
|
245
98
|
const { tx, ty, tz, scalePPM, rx, ry, rz } = OSGB36_TO_WGS84_HELMERT;
|
|
246
|
-
// Convert Airy 1830 geodetic coordinates to geocentric Cartesian coordinates.
|
|
247
99
|
const phi = (latitude * Math.PI) / 180;
|
|
248
100
|
const lambda = (longitude * Math.PI) / 180;
|
|
249
101
|
const sinPhi = Math.sin(phi);
|
|
@@ -253,7 +105,6 @@ export function osgb36AiryToWGS84({ latitude, longitude }) {
|
|
|
253
105
|
const x1 = nuAiry * cosPhi * Math.cos(lambda);
|
|
254
106
|
const y1 = nuAiry * cosPhi * Math.sin(lambda);
|
|
255
107
|
const z1 = (1 - e2Airy) * nuAiry * sinPhi;
|
|
256
|
-
// Apply Helmert rotation, scale, and translation.
|
|
257
108
|
const s = 1 + scalePPM * PPM;
|
|
258
109
|
const rxRad = rx * ARCSEC_TO_RAD;
|
|
259
110
|
const ryRad = ry * ARCSEC_TO_RAD;
|
|
@@ -261,12 +112,10 @@ export function osgb36AiryToWGS84({ latitude, longitude }) {
|
|
|
261
112
|
const x2 = tx + s * x1 - rzRad * y1 + ryRad * z1;
|
|
262
113
|
const y2 = ty + rzRad * x1 + s * y1 - rxRad * z1;
|
|
263
114
|
const z2 = tz - ryRad * x1 + rxRad * y1 + s * z1;
|
|
264
|
-
// Convert GRS80 geocentric Cartesian coordinates to geodetic coordinates by latitude iteration.
|
|
265
115
|
const e2GRS = (GRS80_A * GRS80_A - GRS80_B * GRS80_B) / (GRS80_A * GRS80_A);
|
|
266
116
|
const p = Math.sqrt(x2 * x2 + y2 * y2);
|
|
267
117
|
let phi2 = Math.atan2(z2, p * (1 - e2GRS));
|
|
268
118
|
let phiPrev = 2 * Math.PI;
|
|
269
|
-
// Converges in a handful of passes at GB latitudes; the guard bounds it regardless.
|
|
270
119
|
for (let i = 0; i < 100 && Math.abs(phi2 - phiPrev) > GEODETIC_LATITUDE_TOLERANCE_RAD; i++) {
|
|
271
120
|
phiPrev = phi2;
|
|
272
121
|
const nuGRS = GRS80_A / Math.sqrt(1 - e2GRS * Math.sin(phi2) * Math.sin(phi2));
|
|
@@ -279,20 +128,18 @@ export function osgb36AiryToWGS84({ latitude, longitude }) {
|
|
|
279
128
|
};
|
|
280
129
|
}
|
|
281
130
|
/**
|
|
282
|
-
*
|
|
283
|
-
*
|
|
131
|
+
* Converts a British National Grid (EPSG:27700) easting and northing to WGS84
|
|
132
|
+
* (EPSG:4326) latitude and longitude, accurate to about 5 m across GB.
|
|
284
133
|
*
|
|
285
|
-
*
|
|
286
|
-
*
|
|
287
|
-
* Open uses exactly that to mean "no coordinate available" (its 865 positional-quality-90 rows). Callers must filter
|
|
288
|
-
* those rows themselves — a zero here is a legitimate coordinate, so this module cannot tell the difference.
|
|
134
|
+
* It converts `{ easting: 0, northing: 0 }` like any other point, so callers must
|
|
135
|
+
* filter out Code-Point Open's zero placeholder rows.
|
|
289
136
|
*/
|
|
290
137
|
export function osgb36ToWGS84(point) {
|
|
291
138
|
return osgb36AiryToWGS84(osgb36GridToAiryLatLon(point));
|
|
292
139
|
}
|
|
293
140
|
/**
|
|
294
|
-
*
|
|
295
|
-
*
|
|
141
|
+
* Converts a National Grid point to WGS84 in GeoJSON `[longitude, latitude]` order,
|
|
142
|
+
* matching {@link Coordinates2D}.
|
|
296
143
|
*/
|
|
297
144
|
export function osgb36ToCoordinates2D(point) {
|
|
298
145
|
const { latitude, longitude } = osgb36ToWGS84(point);
|
package/out/osgb36.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"osgb36.js","sourceRoot":"","sources":["../lib/osgb36.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"osgb36.js","sourceRoot":"","sources":["../lib/osgb36.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,MAAM,WAAW,GAAG,aAAa,CAAA;AAEjC,MAAM,WAAW,GAAG,aAAa,CAAA;AAEjC,MAAM,OAAO,GAAG,SAAS,CAAA;AAEzB,MAAM,OAAO,GAAG,cAAc,CAAA;AAE9B,MAAM,gBAAgB,GAAG,YAAY,CAAA;AAErC,MAAM,kBAAkB,GAAG,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,GAAG,CAAA;AAE/C,MAAM,kBAAkB,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,GAAG,CAAA;AAE/C,MAAM,gBAAgB,GAAG,OAAO,CAAA;AAEhC,MAAM,gBAAgB,GAAG,CAAC,OAAO,CAAA;AAEjC,MAAM,aAAa,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC,GAAG,GAAG,IAAI,CAAC,CAAA;AAE5C,MAAM,GAAG,GAAG,IAAI,CAAA;AAEhB,MAAM,0BAA0B,GAAG,IAAI,CAAA;AAEvC,MAAM,+BAA+B,GAAG,KAAK,CAAA;AAE7C,MAAM,uBAAuB,GAAG;IAC/B,EAAE,EAAE,OAAO;IAEX,EAAE,EAAE,CAAC,OAAO;IAEZ,EAAE,EAAE,MAAM;IAEV,QAAQ,EAAE,CAAC,OAAO;IAElB,EAAE,EAAE,MAAM;IAEV,EAAE,EAAE,KAAK;IAET,EAAE,EAAE,MAAM;CACD,CAAA;AAmBV;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CAAC,EAAE,OAAO,EAA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;IAEpD,OAAO,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAA;AAC7B,CAAC"}
|
package/out/polyline.d.ts
CHANGED
|
@@ -14,14 +14,16 @@
|
|
|
14
14
|
/**
|
|
15
15
|
* Clamp a fraction into `[0, 1]`.
|
|
16
16
|
*
|
|
17
|
-
* NaN passes through
|
|
18
|
-
*
|
|
17
|
+
* NaN passes through deliberately.
|
|
18
|
+
* An interpolation whose inputs were not numbers should produce NaN coordinates a
|
|
19
|
+
* caller can detect rather than silently snap to a segment's start.
|
|
19
20
|
*/
|
|
20
21
|
export declare function clampFraction(t: number): number;
|
|
21
22
|
/**
|
|
22
23
|
* The point at fraction `t` of a polyline's total arc length (haversine), plus that total in km.
|
|
23
24
|
*
|
|
24
|
-
* `t` is assumed clamped to `[0, 1]`.
|
|
25
|
+
* `t` is assumed clamped to `[0, 1]`.
|
|
26
|
+
* A zero-length polyline yields its first vertex and a length of 0, so a degenerate
|
|
25
27
|
* segment still produces a usable coordinate rather than NaN.
|
|
26
28
|
*/
|
|
27
29
|
export declare function pointAlong(polyline: readonly [number, number][], t: number): [lon: number, lat: number, lengthKm: number];
|
package/out/polyline.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"polyline.d.ts","sourceRoot":"","sources":["../lib/polyline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH
|
|
1
|
+
{"version":3,"file":"polyline.d.ts","sourceRoot":"","sources":["../lib/polyline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAE/C;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CACzB,QAAQ,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,EACrC,CAAC,EAAE,MAAM,GACP,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,CAqC9C"}
|
package/out/polyline.js
CHANGED
|
@@ -15,8 +15,9 @@ import { haversineKm } from "#distance";
|
|
|
15
15
|
/**
|
|
16
16
|
* Clamp a fraction into `[0, 1]`.
|
|
17
17
|
*
|
|
18
|
-
* NaN passes through
|
|
19
|
-
*
|
|
18
|
+
* NaN passes through deliberately.
|
|
19
|
+
* An interpolation whose inputs were not numbers should produce NaN coordinates a
|
|
20
|
+
* caller can detect rather than silently snap to a segment's start.
|
|
20
21
|
*/
|
|
21
22
|
export function clampFraction(t) {
|
|
22
23
|
return t < 0 ? 0 : Math.min(1, t);
|
|
@@ -24,7 +25,8 @@ export function clampFraction(t) {
|
|
|
24
25
|
/**
|
|
25
26
|
* The point at fraction `t` of a polyline's total arc length (haversine), plus that total in km.
|
|
26
27
|
*
|
|
27
|
-
* `t` is assumed clamped to `[0, 1]`.
|
|
28
|
+
* `t` is assumed clamped to `[0, 1]`.
|
|
29
|
+
* A zero-length polyline yields its first vertex and a length of 0, so a degenerate
|
|
28
30
|
* segment still produces a usable coordinate rather than NaN.
|
|
29
31
|
*/
|
|
30
32
|
export function pointAlong(polyline, t) {
|