@mailwoman/spatial 10.0.0 → 10.2.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.
Files changed (148) hide show
  1. package/README.md +2 -2
  2. package/lib/bbox.ts +41 -34
  3. package/lib/coordinate/bounds.ts +2 -2
  4. package/lib/coordinate/formats.ts +21 -33
  5. package/lib/distance.ts +56 -28
  6. package/lib/feature.ts +2 -2
  7. package/lib/geometries/point.ts +42 -35
  8. package/lib/geometries/polygon.ts +27 -135
  9. package/lib/geometries/ring-blob.ts +35 -132
  10. package/lib/google/place-id.ts +4 -2
  11. package/lib/h3/cell.ts +23 -78
  12. package/lib/h3/coverage.ts +13 -9
  13. package/lib/h3/interior-cells.ts +13 -34
  14. package/lib/h3/polygon-cells.ts +61 -167
  15. package/lib/{h3/index.ts → h3.ts} +1 -1
  16. package/lib/index.ts +6 -5
  17. package/lib/objects.ts +6 -6
  18. package/lib/open-location-code.ts +11 -42
  19. package/lib/osgb36.ts +28 -187
  20. package/lib/polyline.ts +5 -3
  21. package/lib/position.ts +39 -20
  22. package/lib/projection/transform.ts +43 -44
  23. package/lib/{projection/index.ts → projection.ts} +1 -1
  24. package/lib/well-known-text.ts +9 -9
  25. package/out/bbox.d.ts +17 -14
  26. package/out/bbox.d.ts.map +1 -1
  27. package/out/bbox.js +32 -23
  28. package/out/bbox.js.map +1 -1
  29. package/out/coordinate/bounds.d.ts +2 -2
  30. package/out/coordinate/bounds.js +2 -2
  31. package/out/coordinate/formats.d.ts +17 -16
  32. package/out/coordinate/formats.d.ts.map +1 -1
  33. package/out/coordinate/formats.js +20 -32
  34. package/out/coordinate/formats.js.map +1 -1
  35. package/out/distance.d.ts +51 -26
  36. package/out/distance.d.ts.map +1 -1
  37. package/out/distance.js +53 -27
  38. package/out/distance.js.map +1 -1
  39. package/out/feature.d.ts +2 -2
  40. package/out/feature.d.ts.map +1 -1
  41. package/out/geometries/point.d.ts +30 -22
  42. package/out/geometries/point.d.ts.map +1 -1
  43. package/out/geometries/point.js +37 -30
  44. package/out/geometries/point.js.map +1 -1
  45. package/out/geometries/polygon.d.ts +27 -126
  46. package/out/geometries/polygon.d.ts.map +1 -1
  47. package/out/geometries/polygon.js +14 -42
  48. package/out/geometries/polygon.js.map +1 -1
  49. package/out/geometries/ring-blob.d.ts +24 -110
  50. package/out/geometries/ring-blob.d.ts.map +1 -1
  51. package/out/geometries/ring-blob.js +30 -116
  52. package/out/geometries/ring-blob.js.map +1 -1
  53. package/out/{geometries/index.js → geometries.d.ts} +1 -1
  54. package/out/geometries.d.ts.map +1 -0
  55. package/out/{geometries/index.d.ts → geometries.js} +1 -1
  56. package/out/geometries.js.map +1 -0
  57. package/out/google/place-id.d.ts +4 -2
  58. package/out/google/place-id.d.ts.map +1 -1
  59. package/out/google/place-id.js.map +1 -1
  60. package/out/{google/index.d.ts → google.d.ts} +1 -1
  61. package/out/google.d.ts.map +1 -0
  62. package/out/{google/index.js → google.js} +1 -1
  63. package/out/google.js.map +1 -0
  64. package/out/h3/cell.d.ts +19 -73
  65. package/out/h3/cell.d.ts.map +1 -1
  66. package/out/h3/cell.js +22 -65
  67. package/out/h3/cell.js.map +1 -1
  68. package/out/h3/coverage.d.ts +12 -8
  69. package/out/h3/coverage.d.ts.map +1 -1
  70. package/out/h3/coverage.js +12 -8
  71. package/out/h3/coverage.js.map +1 -1
  72. package/out/h3/interior-cells.d.ts +9 -28
  73. package/out/h3/interior-cells.d.ts.map +1 -1
  74. package/out/h3/interior-cells.js +13 -32
  75. package/out/h3/interior-cells.js.map +1 -1
  76. package/out/h3/polygon-cells.d.ts +28 -120
  77. package/out/h3/polygon-cells.d.ts.map +1 -1
  78. package/out/h3/polygon-cells.js +50 -148
  79. package/out/h3/polygon-cells.js.map +1 -1
  80. package/out/{h3/index.d.ts → h3.d.ts} +2 -2
  81. package/out/h3.d.ts.map +1 -0
  82. package/out/{h3/index.js → h3.js} +2 -2
  83. package/out/h3.js.map +1 -0
  84. package/out/index.d.ts +6 -5
  85. package/out/index.d.ts.map +1 -1
  86. package/out/index.js +6 -5
  87. package/out/index.js.map +1 -1
  88. package/out/objects.d.ts +6 -6
  89. package/out/open-location-code.d.ts +11 -22
  90. package/out/open-location-code.d.ts.map +1 -1
  91. package/out/open-location-code.js +9 -40
  92. package/out/open-location-code.js.map +1 -1
  93. package/out/osgb36.d.ts +21 -97
  94. package/out/osgb36.d.ts.map +1 -1
  95. package/out/osgb36.js +12 -165
  96. package/out/osgb36.js.map +1 -1
  97. package/out/polyline.d.ts +5 -3
  98. package/out/polyline.d.ts.map +1 -1
  99. package/out/polyline.js +5 -3
  100. package/out/polyline.js.map +1 -1
  101. package/out/position.d.ts +36 -20
  102. package/out/position.d.ts.map +1 -1
  103. package/out/position.js +0 -1
  104. package/out/position.js.map +1 -1
  105. package/out/projection/transform.d.ts +33 -30
  106. package/out/projection/transform.d.ts.map +1 -1
  107. package/out/projection/transform.js +15 -17
  108. package/out/projection/transform.js.map +1 -1
  109. package/out/{projection/index.d.ts → projection.d.ts} +2 -2
  110. package/out/projection.d.ts.map +1 -0
  111. package/out/{projection/index.js → projection.js} +2 -2
  112. package/out/projection.js.map +1 -0
  113. package/out/{regions/index.js → regions.d.ts} +1 -1
  114. package/out/regions.d.ts.map +1 -0
  115. package/out/{regions/index.d.ts → regions.js} +1 -1
  116. package/out/regions.js.map +1 -0
  117. package/out/tools/ogr/stream.d.ts +21 -11
  118. package/out/tools/ogr/stream.d.ts.map +1 -1
  119. package/out/tools/ogr/stream.js +17 -10
  120. package/out/tools/ogr/stream.js.map +1 -1
  121. package/out/tools/{ogr/index.d.ts → ogr.d.ts} +25 -15
  122. package/out/tools/ogr.d.ts.map +1 -0
  123. package/out/tools/{ogr/index.js → ogr.js} +25 -21
  124. package/out/tools/ogr.js.map +1 -0
  125. package/out/tools/tsconfig.tsbuildinfo +1 -0
  126. package/out/tsconfig.test.tsbuildinfo +1 -1
  127. package/out/well-known-text.d.ts +9 -9
  128. package/out/well-known-text.d.ts.map +1 -1
  129. package/out/well-known-text.js +7 -7
  130. package/out/well-known-text.js.map +1 -1
  131. package/package.json +37 -129
  132. package/{lib/tools → tools}/ogr/stream.ts +26 -15
  133. package/{lib/tools/ogr/index.ts → tools/ogr.ts} +44 -30
  134. package/out/geometries/index.d.ts.map +0 -1
  135. package/out/geometries/index.js.map +0 -1
  136. package/out/google/index.d.ts.map +0 -1
  137. package/out/google/index.js.map +0 -1
  138. package/out/h3/index.d.ts.map +0 -1
  139. package/out/h3/index.js.map +0 -1
  140. package/out/projection/index.d.ts.map +0 -1
  141. package/out/projection/index.js.map +0 -1
  142. package/out/regions/index.d.ts.map +0 -1
  143. package/out/regions/index.js.map +0 -1
  144. package/out/tools/ogr/index.d.ts.map +0 -1
  145. package/out/tools/ogr/index.js.map +0 -1
  146. /package/lib/{geometries/index.ts → geometries.ts} +0 -0
  147. /package/lib/{google/index.ts → google.ts} +0 -0
  148. /package/lib/{regions/index.ts → regions.ts} +0 -0
package/out/h3.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"h3.js","sourceRoot":"","sources":["../lib/h3.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AAEpC,OAAO,EAAE,QAAQ,EAAqB,MAAM,mBAAmB,CAAA;AAC/D,OAAO,EAAiC,YAAY,EAAE,MAAM,UAAU,CAAA;AAEtE,cAAc,UAAU,CAAA;AACxB,cAAc,oBAAoB,CAAA;AAClC,cAAc,mBAAmB,CAAA;AAEjC;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,SAAsB,EAAE,UAAU,GAAG,EAAE;IACvE,MAAM,IAAI,GAAG,YAAY,CAAC,SAAS,EAAE,UAAU,CAAC,CAAA;IAEhD,2DAA2D;IAC3D,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,GAAG,YAAY,CAAC,IAAI,CAAC,CAAA;IAEhD,OAAO,IAAI,QAAQ,CAAC,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAA;AAC3C,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,IAAY;IAC9C,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,GAAG,YAAY,CAAC,IAAI,CAAC,CAAA;IAEhD,OAAO;QACN,IAAI,EAAE,OAAO;QACb,WAAW,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC;KAClC,CAAA;AACF,CAAC"}
package/out/index.d.ts CHANGED
@@ -9,13 +9,14 @@ export * from "#coordinate/bounds";
9
9
  export * from "#distance";
10
10
  export * from "#feature";
11
11
  export * from "#open-location-code";
12
- export * from "#geometries/index";
13
- export * from "#google/index";
14
- export * from "#h3/index";
12
+ export * from "#geometries";
13
+ export * from "#google";
14
+ export * from "#h3";
15
15
  export * from "#objects";
16
16
  export * from "#osgb36";
17
17
  export * from "#polyline";
18
18
  export * from "#position";
19
- export * from "#projection/index";
20
- export * from "#regions/index";
19
+ export { isValidLatitude, isValidLongitude } from "#coordinate/bounds";
20
+ export * from "#projection";
21
+ export * from "#regions";
21
22
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,OAAO,CAAA;AACrB,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA;AAClC,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,cAAc,qBAAqB,CAAA;AACnC,cAAc,mBAAmB,CAAA;AACjC,cAAc,eAAe,CAAA;AAC7B,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,mBAAmB,CAAA;AACjC,cAAc,gBAAgB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,OAAO,CAAA;AACrB,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA;AAClC,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,cAAc,qBAAqB,CAAA;AACnC,cAAc,aAAa,CAAA;AAC3B,cAAc,SAAS,CAAA;AACvB,cAAc,KAAK,CAAA;AACnB,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACtE,cAAc,aAAa,CAAA;AAC3B,cAAc,UAAU,CAAA"}
package/out/index.js CHANGED
@@ -9,13 +9,14 @@ export * from "#coordinate/bounds";
9
9
  export * from "#distance";
10
10
  export * from "#feature";
11
11
  export * from "#open-location-code";
12
- export * from "#geometries/index";
13
- export * from "#google/index";
14
- export * from "#h3/index";
12
+ export * from "#geometries";
13
+ export * from "#google";
14
+ export * from "#h3";
15
15
  export * from "#objects";
16
16
  export * from "#osgb36";
17
17
  export * from "#polyline";
18
18
  export * from "#position";
19
- export * from "#projection/index";
20
- export * from "#regions/index";
19
+ export { isValidLatitude, isValidLongitude } from "#coordinate/bounds";
20
+ export * from "#projection";
21
+ export * from "#regions";
21
22
  //# sourceMappingURL=index.js.map
package/out/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,OAAO,CAAA;AACrB,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA;AAClC,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,cAAc,qBAAqB,CAAA;AACnC,cAAc,mBAAmB,CAAA;AACjC,cAAc,eAAe,CAAA;AAC7B,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,mBAAmB,CAAA;AACjC,cAAc,gBAAgB,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,OAAO,CAAA;AACrB,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA;AAClC,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,cAAc,qBAAqB,CAAA;AACnC,cAAc,aAAa,CAAA;AAC3B,cAAc,SAAS,CAAA;AACvB,cAAc,KAAK,CAAA;AACnB,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACtE,cAAc,aAAa,CAAA;AAC3B,cAAc,UAAU,CAAA"}
package/out/objects.d.ts CHANGED
@@ -24,8 +24,8 @@ export declare const GeometryType: {
24
24
  /**
25
25
  * The base GeoJSON object.
26
26
  *
27
- * The GeoJSON specification also allows foreign members (https://tools.ietf.org/html/rfc7946#section-6.1) to be
28
- * included in the object.
27
+ * The GeoJSON specification also allows foreign members
28
+ * (https://tools.ietf.org/html/rfc7946#section-6.1) to be included in the object.
29
29
  *
30
30
  * @title Geo Object
31
31
  * @public
@@ -37,14 +37,14 @@ export interface GeoObjectLiteral {
37
37
  */
38
38
  type: GeometryType;
39
39
  /**
40
- * A unique identifier for the feature, such as a UUID, a serial number, or a name.
40
+ * A unique identifier for the feature, such as a uuid, a serial number, or a name.
41
41
  */
42
42
  id?: string | number | undefined | null;
43
43
  /**
44
44
  * A bounding box of the coordinate range of the object's Geometries, Features, or Feature Collections.
45
45
  *
46
- * This is useful when defining the extent of a GeoJSON object, i.e. the minimum and maximum coordinates of the
47
- * object's Geometries, Features, or Feature Collections.
46
+ * This is useful when defining the extent of a GeoJSON object, i.e. the minimum
47
+ * and maximum coordinates of the object's Geometries, Features, or Feature Collections.
48
48
  *
49
49
  * @see {@link https://tools.ietf.org/html/rfc7946#section-5 GeoJSON Bounding Boxes}
50
50
  */
@@ -61,7 +61,7 @@ export interface GeoObjectLiteral {
61
61
  /**
62
62
  * The name of the coordinate reference system.
63
63
  *
64
- * @default "EPSG:4326"
64
+ * @defaultValue `"epsg:4326"`
65
65
  */
66
66
  name: string;
67
67
  };
@@ -2,22 +2,10 @@
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
5
  */
18
6
  /**
19
- * A decoded plus-code cell: the center (the coordinate consumers want) plus the cell's span, from which callers price
20
- * the claim (`uncertaintyM` ≈ the half-diagonal).
7
+ * Describes a decoded plus-code cell by its center and its span in degrees, from
8
+ * which callers derive an uncertainty radius.
21
9
  */
22
10
  export interface DecodedPlusCode {
23
11
  lat: number;
@@ -26,23 +14,24 @@ export interface DecodedPlusCode {
26
14
  lonSpanDeg: number;
27
15
  }
28
16
  /**
29
- * A syntactically-valid FULL plus code: exactly 8 digits, `+`, then 2 or 3 digits. (The spec allows padded and longer
30
- * forms; addresses carry the 10–11 digit register, which is all this reader accepts.)
17
+ * Returns true for a full plus code of exactly 8 digits, `+`, and 2 or 3 digits.
18
+ *
19
+ * It rejects the padded and longer forms the spec allows, since addresses use only the 10–11 digit form.
31
20
  */
32
21
  export declare function isFullPlusCode(token: string): boolean;
33
22
  /**
34
- * A syntactically-valid SHORT plus code: 2, 4, or 6 leading digits removed — so 6, 4, or 2 digits before the `+`. The
35
- * 4-before-`+` form (`VFQ6+92P`) is the one Google prints on place cards.
23
+ * Returns true for a short plus code with 2, 4 or 6 digits before the `+`,
24
+ * such as the `VFQ6+92P` form Google prints on place cards.
36
25
  */
37
26
  export declare function isShortPlusCode(token: string): boolean;
38
27
  /**
39
- * Decode a FULL plus code to its cell. Returns null on anything `isFullPlusCode` rejects.
28
+ * Decodes a full plus code to its cell, returning null for anything {@link isFullPlusCode} rejects.
40
29
  */
41
30
  export declare function decodePlusCode(code: string): DecodedPlusCode | null;
42
31
  /**
43
- * Recover a SHORT plus code against a reference coordinate, per the spec's `recoverNearest`: prepend the reference's
44
- * prefix at the missing precision, then shift the candidate cell by whole prefix-resolutions when a neighboring cell
45
- * center sits closer to the reference. Returns the decoded nearest cell, or null for an invalid short code.
32
+ * Recovers a short plus code to the matching cell nearest a reference coordinate,
33
+ * following the spec's `recoverNearest`.
34
+ * It returns null for an invalid short code.
46
35
  */
47
36
  export declare function recoverNearestPlusCode(shortCode: string, refLat: number, refLon: number): DecodedPlusCode | null;
48
37
  //# sourceMappingURL=open-location-code.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"open-location-code.d.ts","sourceRoot":"","sources":["../lib/open-location-code.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAsBH;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC/B,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;IACX,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,MAAM,CAAA;CAClB;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAErD;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEtD;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI,CAqCnE;AA2BD;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI,CA8BhH"}
1
+ {"version":3,"file":"open-location-code.d.ts","sourceRoot":"","sources":["../lib/open-location-code.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAWH;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC/B,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;IACX,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,MAAM,CAAA;CAClB;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAErD;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEtD;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI,CAmCnE;AAuBD;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI,CA2BhH"}
@@ -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
- * A syntactically-valid FULL plus code: exactly 8 digits, `+`, then 2 or 3 digits. (The spec allows padded and longer
36
- * forms; addresses carry the 10–11 digit register, which is all this reader accepts.)
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
- * A syntactically-valid SHORT plus code: 2, 4, or 6 leading digits removed — so 6, 4, or 2 digits before the `+`. The
43
- * 4-before-`+` form (`VFQ6+92P`) is the one Google prints on place cards.
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
- * Decode a FULL plus code to its cell. Returns null on anything `isFullPlusCode` rejects.
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
- * Recover a SHORT plus code against a reference coordinate, per the spec's `recoverNearest`: prepend the reference's
104
- * prefix at the missing precision, then shift the candidate cell by whole prefix-resolutions when a neighboring cell
105
- * center sits closer to the reference. Returns the decoded nearest cell, or null for an invalid short code.
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;;;;;;;;;;;;;;;;GAgBG;AAEH;;;GAGG;AACH,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;;;GAGG;AACH,MAAM,gBAAgB,GAAG,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,IAAI,CAAU,CAAA;AAEpE;;GAEG;AACH,MAAM,YAAY,GAAG,CAAC,CAAA;AACtB,MAAM,SAAS,GAAG,CAAC,CAAA;AAanB;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,KAAa;IAC3C,OAAO,2DAA2D,CA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AAI,gBAAgB,CAAA;IAC/B,CAAC;SAAM,IAAI,MAAM,GAAG,gBAAgB,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,EAAE,CAAC;QACvD,MAAM,CAAC,GAAG,IAAI,gBAAgB,CAAA;IAC/B,CAAC;IAED,OAAO,MAAM,CAAA;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 metres.
8
+ * A position on the British National Grid, in meters.
80
9
  */
81
10
  export interface NationalGridPoint {
82
11
  /**
83
- * Easting in metres. Valid GB values run roughly 0…700,000.
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
- * Northing in metres. Valid GB values run roughly 0…1,300,000.
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
- * Convert National Grid eastings/northings to OSGB36 geodetic lat/lon on the Airy 1830 ellipsoid, by Redfearn's inverse
93
- * transverse Mercator series.
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
- * 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.
26
+ * Pass the result to {@link osgb36AiryToWGS84} to get WGS84 coordinates.
99
27
  */
100
- export declare function osgb36GridToAiryLatLon({ easting, northing }: NationalGridPoint): GeodeticLatLon;
28
+ export declare function osgb36GridToAiryLatLon({ easting, northing }: NationalGridPoint): GeoCoordinate;
101
29
  /**
102
- * Convert OSGB36 geodetic lat/lon (Airy 1830) to WGS84 lat/lon (GRS80) via the seven-parameter Helmert.
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
- * 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.
33
+ * The transform ignores height, so use the result for horizontal positions only.
108
34
  */
109
- export declare function osgb36AiryToWGS84({ latitude, longitude }: GeodeticLatLon): GeodeticLatLon;
35
+ export declare function osgb36AiryToWGS84({ latitude, longitude }: GeoCoordinate): GeoCoordinate;
110
36
  /**
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.
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
- * 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.
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): GeodeticLatLon;
43
+ export declare function osgb36ToWGS84(point: NationalGridPoint): GeoCoordinate;
120
44
  /**
121
- * {@link osgb36ToWGS84} in GeoJSON axis order — `[longitude, latitude]`, matching {@link Coordinates2D} and every
122
- * geometry helper in this package.
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
@@ -1 +1 @@
1
- {"version":3,"file":"osgb36.d.ts","sourceRoot":"","sources":["../lib/osgb36.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAuH9C;;;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"}
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,CAA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