@mailwoman/spatial 8.6.0 → 9.0.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 +4 -0
- package/geometries/point.ts +37 -15
- package/geometries/polygon.ts +70 -2
- package/h3/cell.ts +78 -39
- package/h3/index.ts +1 -1
- package/index.ts +1 -1
- package/osgb36.ts +371 -0
- package/out/geometries/point.d.ts +26 -1
- package/out/geometries/point.d.ts.map +1 -1
- package/out/geometries/point.js +33 -16
- package/out/geometries/point.js.map +1 -1
- package/out/geometries/polygon.d.ts +34 -2
- package/out/geometries/polygon.d.ts.map +1 -1
- package/out/geometries/polygon.js +43 -0
- package/out/geometries/polygon.js.map +1 -1
- package/out/h3/cell.d.ts +43 -15
- package/out/h3/cell.d.ts.map +1 -1
- package/out/h3/cell.js +63 -34
- package/out/h3/cell.js.map +1 -1
- package/out/h3/index.d.ts +1 -1
- package/out/h3/index.js +1 -1
- package/out/index.d.ts +1 -1
- package/out/index.d.ts.map +1 -1
- package/out/index.js +1 -1
- package/out/index.js.map +1 -1
- package/out/osgb36.d.ts +125 -0
- package/out/osgb36.d.ts.map +1 -0
- package/out/osgb36.js +301 -0
- package/out/osgb36.js.map +1 -0
- package/out/position.d.ts +28 -1
- package/out/position.d.ts.map +1 -1
- package/out/position.js +40 -1
- package/out/position.js.map +1 -1
- package/out/tsconfig.test.tsbuildinfo +1 -1
- package/out/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/position.ts +44 -1
- package/countries/codes.ts +0 -534
- package/countries/index.ts +0 -8
- package/countries/names.ts +0 -274
- package/out/countries/codes.d.ts +0 -529
- package/out/countries/codes.d.ts.map +0 -1
- package/out/countries/codes.js +0 -519
- package/out/countries/codes.js.map +0 -1
- package/out/countries/index.d.ts +0 -8
- package/out/countries/index.d.ts.map +0 -1
- package/out/countries/index.js +0 -8
- package/out/countries/index.js.map +0 -1
- package/out/countries/names.d.ts +0 -23
- package/out/countries/names.d.ts.map +0 -1
- package/out/countries/names.js +0 -264
- package/out/countries/names.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"polygon.js","sourceRoot":"","sources":["../../geometries/polygon.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AAqGtD;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAsC,KAAc;IACnF,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,KAAK,CAAA;IAE7D,OAAO,MAAM,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,IAAI,aAAa,IAAI,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;AACjH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAqB;IACvD,OAAO,KAAK,CAAC,WAAW,CAAC,MAAM,KAAK,CAAC,CAAA;AACtC,CAAC;
|
|
1
|
+
{"version":3,"file":"polygon.js","sourceRoot":"","sources":["../../geometries/polygon.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AAqGtD;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAsC,KAAc;IACnF,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,KAAK,CAAA;IAE7D,OAAO,MAAM,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,IAAI,aAAa,IAAI,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;AACjH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAqB;IACvD,OAAO,KAAK,CAAC,WAAW,CAAC,MAAM,KAAK,CAAC,CAAA;AACtC,CAAC;AAYD;;;;;;GAMG;A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ANGED
|
@@ -9,44 +9,72 @@
|
|
|
9
9
|
* by `./index.ts`, so keeping them together closed an import cycle.
|
|
10
10
|
*/
|
|
11
11
|
import type { Tagged } from "type-fest";
|
|
12
|
+
/**
|
|
13
|
+
* The finest resolution H3 defines. Resolutions run `[0, H3_MAX_RESOLUTION]`.
|
|
14
|
+
*/
|
|
15
|
+
export declare const H3_MAX_RESOLUTION = 15;
|
|
12
16
|
/**
|
|
13
17
|
* A H3 cell index, full 64 bits.
|
|
14
18
|
*
|
|
19
|
+
* Written as 15 hex characters because the top nibble of a cell index is always zero: bit 63 is reserved, and the 4-bit
|
|
20
|
+
* mode field that follows is `1` for a cell, which lands entirely inside the second nibble. That is why every cell
|
|
21
|
+
* index printed here begins with `8`.
|
|
22
|
+
*
|
|
15
23
|
* @type {string}
|
|
16
24
|
* @title H3 Cell Index
|
|
17
25
|
* @pattern ^[0-9a-f]{15}$
|
|
18
26
|
*/
|
|
19
27
|
export type H3Cell = Tagged<string, "H3Cell">;
|
|
28
|
+
/**
|
|
29
|
+
* Is `value` a real H3 cell index?
|
|
30
|
+
*
|
|
31
|
+
* Delegates to h3-js rather than testing the surface shape. The shape is necessary but nowhere near sufficient —
|
|
32
|
+
* `000000000000000`, `fffffffffffffff` and `123456789abcdef` are all fifteen lowercase hex characters and none of them
|
|
33
|
+
* is a cell. A guard that returns `value is H3Cell` on those hands the caller a branded type it has not earned, and the
|
|
34
|
+
* error surfaces later inside h3-js with no reference to where the bad value entered.
|
|
35
|
+
*/
|
|
20
36
|
export declare function isH3Cell(value: string): value is H3Cell;
|
|
21
37
|
/**
|
|
22
|
-
* A H3 cell index
|
|
38
|
+
* A H3 cell index with its mode and resolution nibbles removed — the low 52 bits, fixed width.
|
|
23
39
|
*
|
|
24
40
|
* @type {string}
|
|
25
41
|
* @title H3 Cell Index (Short)
|
|
26
|
-
* @pattern ^[0-9a-f]{
|
|
42
|
+
* @pattern ^[0-9a-f]{13}$
|
|
27
43
|
*/
|
|
28
44
|
export type H3CellShort = Tagged<string, "H3CellShort">;
|
|
29
45
|
/**
|
|
30
|
-
*
|
|
46
|
+
* Strip the mode and resolution nibbles off a full H3 cell index, keeping the base cell and the whole digit path.
|
|
47
|
+
*
|
|
48
|
+
* The digits past the cell's own resolution are all `7` in a valid index, so nothing is discarded and nothing is
|
|
49
|
+
* inferred: the short form carries the cell losslessly for every resolution, and {@link expandH3Cell} reverses it
|
|
50
|
+
* exactly once you tell it which resolution the cell was captured at.
|
|
51
|
+
*
|
|
52
|
+
* Zero-padded to a fixed 13 characters, so the hex form orders and compares the same way the integer
|
|
53
|
+
* {@link shortCellToInt} packs does. Base cells 0-7 leave the leading nibble zero, and an unpadded string would both
|
|
54
|
+
* mis-sort and mis-expand.
|
|
31
55
|
*/
|
|
32
56
|
export declare function shortenH3Cell(cell: H3Cell): H3CellShort;
|
|
33
57
|
/**
|
|
34
|
-
*
|
|
58
|
+
* Rebuild a full H3 cell index from a short cell captured at `resolution`.
|
|
59
|
+
*
|
|
60
|
+
* The short form drops only the mode and resolution nibbles, so reconstruction is a straight concatenation: `"8"` (cell
|
|
61
|
+
* mode) + the resolution nibble + the 52 bits verbatim. The result is the identical index `latLngToCell` would have
|
|
62
|
+
* produced at that resolution.
|
|
63
|
+
*
|
|
64
|
+
* `resolution` is a required piece of external knowledge — a short cell does not name its own resolution, so the caller
|
|
65
|
+
* has to supply the one the cell was shortened at. Supplying the wrong one is caught rather than tolerated: a mismatch
|
|
66
|
+
* leaves digits past the stated resolution set to something other than `7`, which H3 rejects, and this throws instead
|
|
67
|
+
* of returning an index that downstream `cellToParent` calls would refuse with `Cell arguments had incompatible
|
|
68
|
+
* resolutions`.
|
|
35
69
|
*
|
|
36
|
-
* @
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* (`Cell arguments had incompatible resolutions`) rather than throwing here. A caller needing to reconstruct a full
|
|
40
|
-
* cell from a short cell captured at a KNOWN resolution R other than 15 must NOT pass `resolution: R` to this
|
|
41
|
-
* function — see `bdc/sdk/filing-landscape.ts`'s `res9ShortCellToRes6Parent` for the correct straight-concatenation
|
|
42
|
-
* formula (`"8" + R.toString(16) + shortHex.padStart(13, "0")`) and its docstring for the full explanation. Do not
|
|
43
|
-
* "fix" this function to take an arbitrary resolution without reading that docstring first — it's out of scope for
|
|
44
|
-
* casual changes.
|
|
70
|
+
* @throws {RangeError} If `resolution` is not an integer in `[0, 15]`, or `h3CellShort` is wider than 13 hex
|
|
71
|
+
* characters.
|
|
72
|
+
* @throws {Error} If the short cell and resolution do not together name a valid H3 cell.
|
|
45
73
|
*/
|
|
46
74
|
export declare function expandH3Cell(h3CellShort: H3CellShort, resolution?: number): H3Cell;
|
|
47
75
|
/**
|
|
48
|
-
* Pack an H3 cell into the
|
|
49
|
-
*
|
|
76
|
+
* Pack an H3 cell into the short-cell integer used as a clustered B-tree key across layer databases (poi.db, bdc.db,
|
|
77
|
+
* address-id). 52 bits, so it stays inside `Number.MAX_SAFE_INTEGER` and SQLite's signed 64-bit integer column alike.
|
|
50
78
|
*/
|
|
51
79
|
export declare function shortCellToInt(cell: H3Cell): number;
|
|
52
80
|
//# sourceMappingURL=cell.d.ts.map
|
package/out/h3/cell.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cell.d.ts","sourceRoot":"","sources":["../../h3/cell.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;
|
|
1
|
+
{"version":3,"file":"cell.d.ts","sourceRoot":"","sources":["../../h3/cell.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAEvC;;GAEG;AACH,eAAO,MAAM,iBAAiB,KAAK,CAAA;AAEnC;;;;;;;;;;GAUG;AACH,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;AAE7C;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,MAAM,CAEvD;AAED;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;AAYvD;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAKvD;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,YAAY,CAAC,WAAW,EAAE,WAAW,EAAE,UAAU,SAAoB,GAAG,MAAM,CAsB7F;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEnD"}
|
package/out/h3/cell.js
CHANGED
|
@@ -8,52 +8,81 @@
|
|
|
8
8
|
* point-valued helpers there do. `geometries/point.ts` needs the primitives and is itself imported
|
|
9
9
|
* by `./index.ts`, so keeping them together closed an import cycle.
|
|
10
10
|
*/
|
|
11
|
+
import { isValidCell } from "h3-js";
|
|
12
|
+
/**
|
|
13
|
+
* The finest resolution H3 defines. Resolutions run `[0, H3_MAX_RESOLUTION]`.
|
|
14
|
+
*/
|
|
15
|
+
export const H3_MAX_RESOLUTION = 15;
|
|
16
|
+
/**
|
|
17
|
+
* Is `value` a real H3 cell index?
|
|
18
|
+
*
|
|
19
|
+
* Delegates to h3-js rather than testing the surface shape. The shape is necessary but nowhere near sufficient —
|
|
20
|
+
* `000000000000000`, `fffffffffffffff` and `123456789abcdef` are all fifteen lowercase hex characters and none of them
|
|
21
|
+
* is a cell. A guard that returns `value is H3Cell` on those hands the caller a branded type it has not earned, and the
|
|
22
|
+
* error surfaces later inside h3-js with no reference to where the bad value entered.
|
|
23
|
+
*/
|
|
11
24
|
export function isH3Cell(value) {
|
|
12
|
-
return
|
|
25
|
+
return isValidCell(value);
|
|
13
26
|
}
|
|
14
27
|
/**
|
|
15
|
-
*
|
|
28
|
+
* Number of hex characters in the short form. 52 bits: a 7-bit base cell followed by fifteen 3-bit digits.
|
|
29
|
+
*/
|
|
30
|
+
const SHORT_CELL_HEX_LENGTH = 13;
|
|
31
|
+
/**
|
|
32
|
+
* Mask selecting the low 52 bits of a cell index — everything but the mode and resolution nibbles.
|
|
33
|
+
*/
|
|
34
|
+
const SHORT_CELL_MASK = 0xfffffffffffffn;
|
|
35
|
+
/**
|
|
36
|
+
* Strip the mode and resolution nibbles off a full H3 cell index, keeping the base cell and the whole digit path.
|
|
37
|
+
*
|
|
38
|
+
* The digits past the cell's own resolution are all `7` in a valid index, so nothing is discarded and nothing is
|
|
39
|
+
* inferred: the short form carries the cell losslessly for every resolution, and {@link expandH3Cell} reverses it
|
|
40
|
+
* exactly once you tell it which resolution the cell was captured at.
|
|
41
|
+
*
|
|
42
|
+
* Zero-padded to a fixed 13 characters, so the hex form orders and compares the same way the integer
|
|
43
|
+
* {@link shortCellToInt} packs does. Base cells 0-7 leave the leading nibble zero, and an unpadded string would both
|
|
44
|
+
* mis-sort and mis-expand.
|
|
16
45
|
*/
|
|
17
46
|
export function shortenH3Cell(cell) {
|
|
18
|
-
// ...and convert it to a 48-bit cell address.
|
|
19
47
|
const cellBigInt = BigInt(`0x${cell}`);
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
// Extract the cell address without the resolution
|
|
23
|
-
const h3CellShortBigInt = cellBigInt & 0xfffffffffffffn;
|
|
24
|
-
const h3CellShortHex = h3CellShortBigInt.toString(16);
|
|
25
|
-
return h3CellShortHex;
|
|
48
|
+
const h3CellShortBigInt = cellBigInt & SHORT_CELL_MASK;
|
|
49
|
+
return h3CellShortBigInt.toString(16).padStart(SHORT_CELL_HEX_LENGTH, "0");
|
|
26
50
|
}
|
|
27
|
-
//2 aa 84 5a 18 ac 6b
|
|
28
|
-
// 8 f2 aa 84 5a 18 ac 6b
|
|
29
51
|
/**
|
|
30
|
-
*
|
|
52
|
+
* Rebuild a full H3 cell index from a short cell captured at `resolution`.
|
|
31
53
|
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
54
|
+
* The short form drops only the mode and resolution nibbles, so reconstruction is a straight concatenation: `"8"` (cell
|
|
55
|
+
* mode) + the resolution nibble + the 52 bits verbatim. The result is the identical index `latLngToCell` would have
|
|
56
|
+
* produced at that resolution.
|
|
57
|
+
*
|
|
58
|
+
* `resolution` is a required piece of external knowledge — a short cell does not name its own resolution, so the caller
|
|
59
|
+
* has to supply the one the cell was shortened at. Supplying the wrong one is caught rather than tolerated: a mismatch
|
|
60
|
+
* leaves digits past the stated resolution set to something other than `7`, which H3 rejects, and this throws instead
|
|
61
|
+
* of returning an index that downstream `cellToParent` calls would refuse with `Cell arguments had incompatible
|
|
62
|
+
* resolutions`.
|
|
63
|
+
*
|
|
64
|
+
* @throws {RangeError} If `resolution` is not an integer in `[0, 15]`, or `h3CellShort` is wider than 13 hex
|
|
65
|
+
* characters.
|
|
66
|
+
* @throws {Error} If the short cell and resolution do not together name a valid H3 cell.
|
|
67
|
+
*/
|
|
68
|
+
export function expandH3Cell(h3CellShort, resolution = H3_MAX_RESOLUTION) {
|
|
69
|
+
if (!Number.isInteger(resolution) || resolution < 0 || resolution > H3_MAX_RESOLUTION) {
|
|
70
|
+
throw new RangeError(`H3 resolution must be an integer in [0, ${H3_MAX_RESOLUTION}], received ${resolution}.`);
|
|
71
|
+
}
|
|
72
|
+
if (h3CellShort.length > SHORT_CELL_HEX_LENGTH) {
|
|
73
|
+
throw new RangeError(`Short H3 cell "${h3CellShort}" is ${h3CellShort.length} hex characters, wider than the ${SHORT_CELL_HEX_LENGTH} a short cell holds.`);
|
|
74
|
+
}
|
|
75
|
+
// Accept an unpadded short cell too — an integer round-tripped through `toString(16)` loses its leading zeros.
|
|
76
|
+
const shortHex = h3CellShort.padStart(SHORT_CELL_HEX_LENGTH, "0");
|
|
77
|
+
const cell = `8${resolution.toString(16)}${shortHex}`;
|
|
78
|
+
if (!isValidCell(cell)) {
|
|
79
|
+
throw new Error(`Short H3 cell "${h3CellShort}" does not name a valid cell at resolution ${resolution} — it was captured at a different resolution.`);
|
|
80
|
+
}
|
|
52
81
|
return cell;
|
|
53
82
|
}
|
|
54
83
|
/**
|
|
55
|
-
* Pack an H3 cell into the
|
|
56
|
-
*
|
|
84
|
+
* Pack an H3 cell into the short-cell integer used as a clustered B-tree key across layer databases (poi.db, bdc.db,
|
|
85
|
+
* address-id). 52 bits, so it stays inside `Number.MAX_SAFE_INTEGER` and SQLite's signed 64-bit integer column alike.
|
|
57
86
|
*/
|
|
58
87
|
export function shortCellToInt(cell) {
|
|
59
88
|
return Number(BigInt(`0x${shortenH3Cell(cell)}`));
|
package/out/h3/cell.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cell.js","sourceRoot":"","sources":["../../h3/cell.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;
|
|
1
|
+
{"version":3,"file":"cell.js","sourceRoot":"","sources":["../../h3/cell.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAA;AAGnC;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,CAAA;AAenC;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAa;IACrC,OAAO,WAAW,CAAC,KAAK,CAAC,CAAA;AAC1B,CAAC;AAWD;;GAEG;AACH,MAAM,qBAAqB,GAAG,EAAE,CAAA;AAEhC;;GAEG;AACH,MAAM,eAAe,GAAG,gBAAsB,CAAA;AAE9C;;;;;;;;;;GAUG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY;IACzC,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC,C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ointLiteral } from "../geometries/point.ts";
|
|
|
7
7
|
import { type H3Cell, type H3CellShort } from "./cell.ts";
|
|
8
8
|
export * from "./cell.ts";
|
|
9
9
|
/**
|
|
10
|
-
* Given a
|
|
10
|
+
* Given a short cell address and the resolution it was captured at, return the centre of that cell.
|
|
11
11
|
*/
|
|
12
12
|
export declare function shortCellToPoint(shortCell: H3CellShort, resolution?: number): GeoPoint;
|
|
13
13
|
export declare function cellToPointLiteral(cell: H3Cell): PointLiteral;
|
package/out/h3/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import { GeoPoint } from "../geometries/point.js";
|
|
|
8
8
|
import { expandH3Cell } from "./cell.js";
|
|
9
9
|
export * from "./cell.js";
|
|
10
10
|
/**
|
|
11
|
-
* Given a
|
|
11
|
+
* Given a short cell address and the resolution it was captured at, return the centre of that cell.
|
|
12
12
|
*/
|
|
13
13
|
export function shortCellToPoint(shortCell, resolution = 15) {
|
|
14
14
|
const cell = expandH3Cell(shortCell, resolution);
|
package/out/index.d.ts
CHANGED
|
@@ -5,12 +5,12 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export * from "./bbox.ts";
|
|
7
7
|
export * from "./coordinate-formats.ts";
|
|
8
|
-
export * from "./countries/index.ts";
|
|
9
8
|
export * from "./feature.ts";
|
|
10
9
|
export * from "./geometries/index.ts";
|
|
11
10
|
export * from "./google/index.ts";
|
|
12
11
|
export * from "./h3/index.ts";
|
|
13
12
|
export * from "./objects.ts";
|
|
13
|
+
export * from "./osgb36.ts";
|
|
14
14
|
export * from "./polyline.ts";
|
|
15
15
|
export * from "./position.ts";
|
|
16
16
|
export * from "./projection.ts";
|
package/out/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,WAAW,CAAA;AACzB,cAAc,yBAAyB,CAAA;AACvC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,WAAW,CAAA;AACzB,cAAc,yBAAyB,CAAA;AACvC,cAAc,cAAc,CAAA;AAC5B,cAAc,uBAAuB,CAAA;AACrC,cAAc,mBAAmB,CAAA;AACjC,cAAc,eAAe,CAAA;AAC7B,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA;AAC7B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,oBAAoB,CAAA"}
|
package/out/index.js
CHANGED
|
@@ -5,12 +5,12 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export * from "./bbox.js";
|
|
7
7
|
export * from "./coordinate-formats.js";
|
|
8
|
-
export * from "./countries/index.js";
|
|
9
8
|
export * from "./feature.js";
|
|
10
9
|
export * from "./geometries/index.js";
|
|
11
10
|
export * from "./google/index.js";
|
|
12
11
|
export * from "./h3/index.js";
|
|
13
12
|
export * from "./objects.js";
|
|
13
|
+
export * from "./osgb36.js";
|
|
14
14
|
export * from "./polyline.js";
|
|
15
15
|
export * from "./position.js";
|
|
16
16
|
export * from "./projection.js";
|
package/out/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,WAAW,CAAA;AACzB,cAAc,yBAAyB,CAAA;AACvC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,WAAW,CAAA;AACzB,cAAc,yBAAyB,CAAA;AACvC,cAAc,cAAc,CAAA;AAC5B,cAAc,uBAAuB,CAAA;AACrC,cAAc,mBAAmB,CAAA;AACjC,cAAc,eAAe,CAAA;AAC7B,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA;AAC7B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,oBAAoB,CAAA"}
|
package/out/osgb36.d.ts
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software.
|
|
3
|
+
* @license AGPL-3.0
|
|
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 seam 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
|
+
import type { Coordinates2D } from "./position.ts";
|
|
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
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* A position on the British National Grid, in metres.
|
|
80
|
+
*/
|
|
81
|
+
export interface NationalGridPoint {
|
|
82
|
+
/**
|
|
83
|
+
* Easting in metres. Valid GB values run roughly 0…700,000.
|
|
84
|
+
*/
|
|
85
|
+
easting: number;
|
|
86
|
+
/**
|
|
87
|
+
* Northing in metres. Valid GB values run roughly 0…1,300,000.
|
|
88
|
+
*/
|
|
89
|
+
northing: number;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Convert National Grid eastings/northings to OSGB36 geodetic lat/lon on the Airy 1830 ellipsoid, by Redfearn's inverse
|
|
93
|
+
* transverse Mercator series.
|
|
94
|
+
*
|
|
95
|
+
* This is the EXACT half of the pipeline — pure projection algebra, no datum shift. The result is still on Airy 1830,
|
|
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.
|
|
99
|
+
*/
|
|
100
|
+
export declare function osgb36GridToAiryLatLon({ easting, northing }: NationalGridPoint): GeodeticLatLon;
|
|
101
|
+
/**
|
|
102
|
+
* Convert OSGB36 geodetic lat/lon (Airy 1830) to WGS84 lat/lon (GRS80) via the seven-parameter Helmert.
|
|
103
|
+
*
|
|
104
|
+
* This is the APPROXIMATE half — see the module docstring for the ±5 m budget and when it stops being acceptable.
|
|
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.
|
|
108
|
+
*/
|
|
109
|
+
export declare function osgb36AiryToWGS84({ latitude, longitude }: GeodeticLatLon): GeodeticLatLon;
|
|
110
|
+
/**
|
|
111
|
+
* Convert a British National Grid (EPSG:27700) easting/northing straight to WGS84 (EPSG:4326) lat/lon — the composition
|
|
112
|
+
* of {@link osgb36GridToAiryLatLon} and {@link osgb36AiryToWGS84}, and the function callers actually want.
|
|
113
|
+
*
|
|
114
|
+
* Accurate to about ±5 m across GB (see the module docstring). Does NOT validate that the input lies within the grid's
|
|
115
|
+
* GB extent: `{easting: 0, northing: 0}` is a real point in the Atlantic south-west of the Scillies, and Code-Point
|
|
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.
|
|
118
|
+
*/
|
|
119
|
+
export declare function osgb36ToWGS84(point: NationalGridPoint): GeodeticLatLon;
|
|
120
|
+
/**
|
|
121
|
+
* {@link osgb36ToWGS84} in GeoJSON axis order — `[longitude, latitude]`, matching {@link Coordinates2D} and every
|
|
122
|
+
* geometry helper in this package.
|
|
123
|
+
*/
|
|
124
|
+
export declare function osgb36ToCoordinates2D(point: NationalGridPoint): Coordinates2D;
|
|
125
|
+
//# sourceMappingURL=osgb36.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"osgb36.d.ts","sourceRoot":"","sources":["../osgb36.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAuHlD;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC9B;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAA;IAChB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAA;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IACjC;;OAEG;IACH,OAAO,EAAE,MAAM,CAAA;IACf;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAA;CAChB;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,iBAAiB,GAAG,cAAc,CAuE/F;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,cAAc,GAAG,cAAc,CA8CzF;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,iBAAiB,GAAG,cAAc,CAEtE;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,iBAAiB,GAAG,aAAa,CAI7E"}
|