@mailwoman/spatial 8.5.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.
Files changed (52) hide show
  1. package/README.md +4 -0
  2. package/geometries/point.ts +37 -15
  3. package/geometries/polygon.ts +70 -2
  4. package/h3/cell.ts +78 -39
  5. package/h3/index.ts +1 -1
  6. package/index.ts +1 -1
  7. package/osgb36.ts +371 -0
  8. package/out/geometries/point.d.ts +26 -1
  9. package/out/geometries/point.d.ts.map +1 -1
  10. package/out/geometries/point.js +33 -16
  11. package/out/geometries/point.js.map +1 -1
  12. package/out/geometries/polygon.d.ts +34 -2
  13. package/out/geometries/polygon.d.ts.map +1 -1
  14. package/out/geometries/polygon.js +43 -0
  15. package/out/geometries/polygon.js.map +1 -1
  16. package/out/h3/cell.d.ts +43 -15
  17. package/out/h3/cell.d.ts.map +1 -1
  18. package/out/h3/cell.js +63 -34
  19. package/out/h3/cell.js.map +1 -1
  20. package/out/h3/index.d.ts +1 -1
  21. package/out/h3/index.js +1 -1
  22. package/out/index.d.ts +1 -1
  23. package/out/index.d.ts.map +1 -1
  24. package/out/index.js +1 -1
  25. package/out/index.js.map +1 -1
  26. package/out/osgb36.d.ts +125 -0
  27. package/out/osgb36.d.ts.map +1 -0
  28. package/out/osgb36.js +301 -0
  29. package/out/osgb36.js.map +1 -0
  30. package/out/position.d.ts +28 -1
  31. package/out/position.d.ts.map +1 -1
  32. package/out/position.js +40 -1
  33. package/out/position.js.map +1 -1
  34. package/out/tsconfig.test.tsbuildinfo +1 -1
  35. package/out/tsconfig.tsbuildinfo +1 -1
  36. package/package.json +3 -3
  37. package/position.ts +44 -1
  38. package/countries/codes.ts +0 -534
  39. package/countries/index.ts +0 -8
  40. package/countries/names.ts +0 -274
  41. package/out/countries/codes.d.ts +0 -529
  42. package/out/countries/codes.d.ts.map +0 -1
  43. package/out/countries/codes.js +0 -519
  44. package/out/countries/codes.js.map +0 -1
  45. package/out/countries/index.d.ts +0 -8
  46. package/out/countries/index.d.ts.map +0 -1
  47. package/out/countries/index.js +0 -8
  48. package/out/countries/index.js.map +0 -1
  49. package/out/countries/names.d.ts +0 -23
  50. package/out/countries/names.d.ts.map +0 -1
  51. package/out/countries/names.js +0 -264
  52. package/out/countries/names.js.map +0 -1
package/osgb36.ts ADDED
@@ -0,0 +1,371 @@
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
+
64
+ import type { Coordinates2D } from "./position.ts"
65
+
66
+ /**
67
+ * Semi-major axis of the Airy 1830 ellipsoid, in metres — the figure of the Earth OSGB36 is referenced to.
68
+ */
69
+ const AIRY_1830_A = 6_377_563.396
70
+
71
+ /**
72
+ * Semi-minor axis of the Airy 1830 ellipsoid, in metres.
73
+ */
74
+ const AIRY_1830_B = 6_356_256.909
75
+
76
+ /**
77
+ * Semi-major axis of the GRS80 ellipsoid, in metres. WGS84's own semi-major axis is identical; the two ellipsoids
78
+ * differ only in the flattening's last digits (~0.1 mm at the pole), far below this module's error budget.
79
+ */
80
+ const GRS80_A = 6_378_137
81
+
82
+ /**
83
+ * Semi-minor axis of the GRS80 ellipsoid, in metres.
84
+ */
85
+ const GRS80_B = 6_356_752.3141
86
+
87
+ /**
88
+ * Scale factor on the National Grid's central meridian.
89
+ */
90
+ const NATIONAL_GRID_F0 = 0.9996012717
91
+
92
+ /**
93
+ * Latitude of the National Grid's true origin, 49° N, in radians.
94
+ */
95
+ const NATIONAL_GRID_LAT0 = (49 * Math.PI) / 180
96
+
97
+ /**
98
+ * Longitude of the National Grid's true origin, 2° W, in radians.
99
+ */
100
+ const NATIONAL_GRID_LON0 = (-2 * Math.PI) / 180
101
+
102
+ /**
103
+ * Easting of the National Grid's true origin (the "false easting"), in metres.
104
+ */
105
+ const NATIONAL_GRID_E0 = 400_000
106
+
107
+ /**
108
+ * Northing of the National Grid's true origin (the "false northing"), in metres. Negative because the true origin sits
109
+ * south-west of the grid's own zero.
110
+ */
111
+ const NATIONAL_GRID_N0 = -100_000
112
+
113
+ /**
114
+ * Arc-seconds → radians. The Helmert rotations are published in arc-seconds.
115
+ */
116
+ const ARCSEC_TO_RAD = Math.PI / (180 * 3600)
117
+
118
+ /**
119
+ * Parts-per-million → unitless scale. The Helmert scale factor is published in ppm.
120
+ */
121
+ const PPM = 1e-6
122
+
123
+ /**
124
+ * Convergence threshold for the meridional-arc iteration in {@link osgb36GridToAiryLatLon}, in METRES of northing. OS's
125
+ * guide specifies 0.01 mm; this is that figure. It bounds the northing residual, not the latitude, which is why it is
126
+ * expressed in metres and compared against `northing - N0 - M`.
127
+ */
128
+ const MERIDIONAL_ARC_TOLERANCE_M = 1e-5
129
+
130
+ /**
131
+ * Convergence threshold for the cartesian→geodetic latitude iteration in {@link osgb36AiryToWGS84}, in RADIANS. 1e-13
132
+ * rad is ~0.6 µm on the ground — far below anything this module claims, and reached in four or five passes at GB
133
+ * latitudes.
134
+ */
135
+ const GEODETIC_LATITUDE_TOLERANCE_RAD = 1e-13
136
+
137
+ /**
138
+ * The seven-parameter Helmert transformation taking OSGB36 (Airy 1830) geocentric cartesian coordinates to WGS84.
139
+ *
140
+ * OS publishes this transform in the ETRS89/WGS84 → OSGB36 direction (guide table 4), as `tx = -446.448, ty = +125.157,
141
+ * tz = -542.060, s = +20.4894 ppm, rx = -0.1502", ry = -0.2470", rz = -0.8421"`. We need the OTHER direction, so every
142
+ * parameter is negated — valid to well inside the transform's own metre-scale error because the rotations are
143
+ * microradian-scale and the second-order terms of a proper inversion are sub-millimetre.
144
+ *
145
+ * The rotation convention is **Position Vector** (EPSG method 1033), NOT Coordinate Frame Rotation (EPSG 1032). The two
146
+ * differ only in the sign of the three rotations, which is why citing the method code matters more than it looks: paste
147
+ * these numbers into a library expecting 1032 and every result moves by roughly 20 m with no error raised.
148
+ *
149
+ * Getting a sign wrong here does not produce a subtly worse answer; it produces a coordinate tens to hundreds of metres
150
+ * out, in a consistent direction — which reads as a plausible coordinate. That is what the Annexe D test is for.
151
+ */
152
+ const OSGB36_TO_WGS84_HELMERT = {
153
+ /**
154
+ * X translation, metres.
155
+ */
156
+ tx: 446.448,
157
+ /**
158
+ * Y translation, metres.
159
+ */
160
+ ty: -125.157,
161
+ /**
162
+ * Z translation, metres.
163
+ */
164
+ tz: 542.06,
165
+ /**
166
+ * Scale correction, parts per million.
167
+ */
168
+ scalePPM: -20.4894,
169
+ /**
170
+ * Rotation about the X axis, arc-seconds.
171
+ */
172
+ rx: 0.1502,
173
+ /**
174
+ * Rotation about the Y axis, arc-seconds.
175
+ */
176
+ ry: 0.247,
177
+ /**
178
+ * Rotation about the Z axis, arc-seconds.
179
+ */
180
+ rz: 0.8421,
181
+ } as const
182
+
183
+ /**
184
+ * A geodetic position on an unspecified ellipsoid, in degrees. Which ellipsoid is the caller's business — the whole
185
+ * point of this module is that the same numbers mean different places on Airy 1830 and on GRS80.
186
+ */
187
+ export interface GeodeticLatLon {
188
+ /**
189
+ * Latitude in decimal degrees, positive north.
190
+ */
191
+ latitude: number
192
+ /**
193
+ * Longitude in decimal degrees, positive east.
194
+ */
195
+ longitude: number
196
+ }
197
+
198
+ /**
199
+ * A position on the British National Grid, in metres.
200
+ */
201
+ export interface NationalGridPoint {
202
+ /**
203
+ * Easting in metres. Valid GB values run roughly 0…700,000.
204
+ */
205
+ easting: number
206
+ /**
207
+ * Northing in metres. Valid GB values run roughly 0…1,300,000.
208
+ */
209
+ northing: number
210
+ }
211
+
212
+ /**
213
+ * Convert National Grid eastings/northings to OSGB36 geodetic lat/lon on the Airy 1830 ellipsoid, by Redfearn's inverse
214
+ * transverse Mercator series.
215
+ *
216
+ * This is the EXACT half of the pipeline — pure projection algebra, no datum shift. The result is still on Airy 1830,
217
+ * so it is NOT a WGS84 coordinate and must not be handed to anything expecting one; feed it to
218
+ * {@link osgb36AiryToWGS84}. Exported separately so the projection can be tested against OS's worked example
219
+ * independently of the Helmert, which is the only way to tell a projection bug from a datum-shift bug.
220
+ */
221
+ export function osgb36GridToAiryLatLon({ easting, northing }: NationalGridPoint): GeodeticLatLon {
222
+ const a = AIRY_1830_A
223
+ const b = AIRY_1830_B
224
+ const f0 = NATIONAL_GRID_F0
225
+ const lat0 = NATIONAL_GRID_LAT0
226
+ const lon0 = NATIONAL_GRID_LON0
227
+ const e0 = NATIONAL_GRID_E0
228
+ const n0 = NATIONAL_GRID_N0
229
+
230
+ // Eccentricity squared of the Airy ellipsoid, and the `n` series parameter.
231
+ const e2 = (a * a - b * b) / (a * a)
232
+ const n = (a - b) / (a + b)
233
+ const n2 = n * n
234
+ const n3 = n2 * n
235
+
236
+ // Iterate latitude until the meridional arc `M` matches the northing. OS's guide specifies a 0.01 mm
237
+ // threshold; it converges in three or four passes anywhere in GB.
238
+ let lat = lat0
239
+ let m = 0
240
+
241
+ do {
242
+ lat = (northing - n0 - m) / (a * f0) + lat
243
+
244
+ const dLat = lat - lat0
245
+ const sLat = lat + lat0
246
+
247
+ m =
248
+ b *
249
+ f0 *
250
+ ((1 + n + (5 / 4) * n2 + (5 / 4) * n3) * dLat -
251
+ (3 * n + 3 * n2 + (21 / 8) * n3) * Math.sin(dLat) * Math.cos(sLat) +
252
+ ((15 / 8) * n2 + (15 / 8) * n3) * Math.sin(2 * dLat) * Math.cos(2 * sLat) -
253
+ (35 / 24) * n3 * Math.sin(3 * dLat) * Math.cos(3 * sLat))
254
+ } while (Math.abs(northing - n0 - m) >= MERIDIONAL_ARC_TOLERANCE_M)
255
+
256
+ const sinLat = Math.sin(lat)
257
+ const cosLat = Math.cos(lat)
258
+ const tanLat = Math.tan(lat)
259
+ const tan2 = tanLat * tanLat
260
+ const tan4 = tan2 * tan2
261
+ const tan6 = tan4 * tan2
262
+
263
+ // `nu` = transverse radius of curvature; `rho` = meridional radius; `eta2` = their ratio less one.
264
+ const nu = a * f0 * (1 - e2 * sinLat * sinLat) ** -0.5
265
+ const rho = a * f0 * (1 - e2) * (1 - e2 * sinLat * sinLat) ** -1.5
266
+ const eta2 = nu / rho - 1
267
+
268
+ const secLat = 1 / cosLat
269
+ const vii = tanLat / (2 * rho * nu)
270
+ const viii = (tanLat / (24 * rho * nu ** 3)) * (5 + 3 * tan2 + eta2 - 9 * tan2 * eta2)
271
+ const ix = (tanLat / (720 * rho * nu ** 5)) * (61 + 90 * tan2 + 45 * tan4)
272
+ const x = secLat / nu
273
+ const xi = (secLat / (6 * nu ** 3)) * (nu / rho + 2 * tan2)
274
+ const xii = (secLat / (120 * nu ** 5)) * (5 + 28 * tan2 + 24 * tan4)
275
+ const xiia = (secLat / (5040 * nu ** 7)) * (61 + 662 * tan2 + 1320 * tan4 + 720 * tan6)
276
+
277
+ const dE = easting - e0
278
+ const dE2 = dE * dE
279
+ const dE3 = dE2 * dE
280
+ const dE4 = dE2 * dE2
281
+ const dE5 = dE4 * dE
282
+ const dE6 = dE4 * dE2
283
+ const dE7 = dE6 * dE
284
+
285
+ const latitude = lat - vii * dE2 + viii * dE4 - ix * dE6
286
+ const longitude = lon0 + x * dE - xi * dE3 + xii * dE5 - xiia * dE7
287
+
288
+ return {
289
+ latitude: (latitude * 180) / Math.PI,
290
+ longitude: (longitude * 180) / Math.PI,
291
+ }
292
+ }
293
+
294
+ /**
295
+ * Convert OSGB36 geodetic lat/lon (Airy 1830) to WGS84 lat/lon (GRS80) via the seven-parameter Helmert.
296
+ *
297
+ * This is the APPROXIMATE half — see the module docstring for the ±5 m budget and when it stops being acceptable.
298
+ * Heights are not modelled: the input is treated as sitting on the Airy ellipsoid and the output's ellipsoidal height
299
+ * is discarded. For a horizontal postcode centroid that costs well under a metre; for anything vertical it is wrong by
300
+ * the ~50 m geoid–ellipsoid separation over GB, so this function does not pretend to return a height.
301
+ */
302
+ export function osgb36AiryToWGS84({ latitude, longitude }: GeodeticLatLon): GeodeticLatLon {
303
+ const { tx, ty, tz, scalePPM, rx, ry, rz } = OSGB36_TO_WGS84_HELMERT
304
+
305
+ // --- Airy 1830 geodetic → geocentric cartesian.
306
+ const phi = (latitude * Math.PI) / 180
307
+ const lambda = (longitude * Math.PI) / 180
308
+ const sinPhi = Math.sin(phi)
309
+ const cosPhi = Math.cos(phi)
310
+ const e2Airy = (AIRY_1830_A * AIRY_1830_A - AIRY_1830_B * AIRY_1830_B) / (AIRY_1830_A * AIRY_1830_A)
311
+ const nuAiry = AIRY_1830_A / Math.sqrt(1 - e2Airy * sinPhi * sinPhi)
312
+
313
+ const x1 = nuAiry * cosPhi * Math.cos(lambda)
314
+ const y1 = nuAiry * cosPhi * Math.sin(lambda)
315
+ const z1 = (1 - e2Airy) * nuAiry * sinPhi
316
+
317
+ // --- Helmert: rotate, scale, translate.
318
+ const s = 1 + scalePPM * PPM
319
+ const rxRad = rx * ARCSEC_TO_RAD
320
+ const ryRad = ry * ARCSEC_TO_RAD
321
+ const rzRad = rz * ARCSEC_TO_RAD
322
+
323
+ const x2 = tx + s * x1 - rzRad * y1 + ryRad * z1
324
+ const y2 = ty + rzRad * x1 + s * y1 - rxRad * z1
325
+ const z2 = tz - ryRad * x1 + rxRad * y1 + s * z1
326
+
327
+ // --- GRS80 geocentric cartesian → geodetic, by the standard iteration on latitude.
328
+ const e2GRS = (GRS80_A * GRS80_A - GRS80_B * GRS80_B) / (GRS80_A * GRS80_A)
329
+ const p = Math.sqrt(x2 * x2 + y2 * y2)
330
+
331
+ let phi2 = Math.atan2(z2, p * (1 - e2GRS))
332
+ let phiPrev = 2 * Math.PI
333
+
334
+ // Converges in a handful of passes at GB latitudes; the guard bounds it regardless.
335
+ for (let i = 0; i < 100 && Math.abs(phi2 - phiPrev) > GEODETIC_LATITUDE_TOLERANCE_RAD; i++) {
336
+ phiPrev = phi2
337
+
338
+ const nuGRS = GRS80_A / Math.sqrt(1 - e2GRS * Math.sin(phi2) * Math.sin(phi2))
339
+ const height = p / Math.cos(phi2) - nuGRS
340
+
341
+ phi2 = Math.atan2(z2, p * (1 - (e2GRS * nuGRS) / (nuGRS + height)))
342
+ }
343
+
344
+ return {
345
+ latitude: (phi2 * 180) / Math.PI,
346
+ longitude: (Math.atan2(y2, x2) * 180) / Math.PI,
347
+ }
348
+ }
349
+
350
+ /**
351
+ * Convert a British National Grid (EPSG:27700) easting/northing straight to WGS84 (EPSG:4326) lat/lon — the composition
352
+ * of {@link osgb36GridToAiryLatLon} and {@link osgb36AiryToWGS84}, and the function callers actually want.
353
+ *
354
+ * Accurate to about ±5 m across GB (see the module docstring). Does NOT validate that the input lies within the grid's
355
+ * GB extent: `{easting: 0, northing: 0}` is a real point in the Atlantic south-west of the Scillies, and Code-Point
356
+ * Open uses exactly that to mean "no coordinate available" (its 865 positional-quality-90 rows). Callers must filter
357
+ * those rows themselves — a zero here is a legitimate coordinate, so this module cannot tell the difference.
358
+ */
359
+ export function osgb36ToWGS84(point: NationalGridPoint): GeodeticLatLon {
360
+ return osgb36AiryToWGS84(osgb36GridToAiryLatLon(point))
361
+ }
362
+
363
+ /**
364
+ * {@link osgb36ToWGS84} in GeoJSON axis order — `[longitude, latitude]`, matching {@link Coordinates2D} and every
365
+ * geometry helper in this package.
366
+ */
367
+ export function osgb36ToCoordinates2D(point: NationalGridPoint): Coordinates2D {
368
+ const { latitude, longitude } = osgb36ToWGS84(point)
369
+
370
+ return [longitude, latitude]
371
+ }
@@ -79,6 +79,13 @@ export declare class GeoPoint implements PointLiteral {
79
79
  get bbox(): BBox2DLiteral | BBox3DLiteral | undefined;
80
80
  set bbox(bbox: BBox2DLiteral | BBox3DLiteral | undefined);
81
81
  get coordinates(): Point2DCoordinates | Point3DCoordinates;
82
+ /**
83
+ * Assigns the pair as GeoJSON [longitude, latitude(, altitude)] — the axis order is the contract, never inferred from
84
+ * the magnitudes — and REJECTS a coordinate that is not on the globe. See {@link GeoPoint.from} for why both halves of
85
+ * that sentence are load-bearing.
86
+ *
87
+ * @throws {RangeError} When longitude is outside [-180, 180] or latitude is outside [-90, 90].
88
+ */
82
89
  set coordinates(coords: Point2DCoordinates | Point3DCoordinates);
83
90
  /**
84
91
  * The longitude of the point in degrees, i.e. the x-coordinate.
@@ -142,7 +149,25 @@ export declare class GeoPoint implements PointLiteral {
142
149
  */
143
150
  constructor(input: GeoPointInput, bbox?: BBox2DLiteral | BBox3DLiteral | GeoBoundingBox);
144
151
  /**
145
- * Attempts to create a new GeoPoint instance from the given input.
152
+ * Attempts to create a new GeoPoint instance from the given input, returning `null` rather than throwing when the
153
+ * input is not a coordinate this class will stand behind.
154
+ *
155
+ * Two rules, both of which this constructor got wrong until 2026-08-05 (the defect was recorded in `e9bfd139` and
156
+ * routed around rather than fixed):
157
+ *
158
+ * 1. **A 2-tuple is GeoJSON [longitude, latitude]. The axis order is never inferred.** The old path ran the pair through
159
+ * `inferGeoJSONCoordOrder`, whose only signal is the [-90, 90] latitude range, so it transposed a pair exactly
160
+ * when |the second magnitude| > 90. A caller handing it `[latitude, longitude]` therefore got the pair repaired in
161
+ * Dallas and left corrupted in Berlin — behaviour selected by the data, from one code path. This change is a no-op
162
+ * for every WELL-FORMED input: a valid `[longitude, latitude]` pair can never have an out-of-range second element,
163
+ * so the heuristic never fired on one.
164
+ * 2. **An out-of-range magnitude is rejected, not repaired.** `[999, 999]` used to produce a GeoPoint reporting latitude
165
+ * 999. It now returns `null` here and throws a `RangeError` from the constructor. Note the deliberate asymmetry
166
+ * with the scalar `longitude` / `latitude` setters, which still wrap and clamp: mutating a point is a pan gesture,
167
+ * where 190° meaning -170° is right; PARSING one is a claim about the world, where an impossible magnitude means
168
+ * the input was malformed and any repair invents a location.
169
+ *
170
+ * A 0/0 result is treated as the "missing coordinate" sentinel (Null Island) and also returns `null`.
146
171
  */
147
172
  static from(input: unknown): GeoPoint | null;
148
173
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"point.d.ts","sourceRoot":"","sources":["../../geometries/point.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,MAAM,MAAM,qCAAqC,CAAA;AAC7D,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAA;AAKhF,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,aAAa,EAAE,cAAc,EAAU,MAAM,YAAY,CAAA;AAC3F,OAAO,EAAE,KAAK,MAAM,EAAiB,MAAM,eAAe,CAAA;AAC1D,OAAO,EAAE,KAAK,gBAAgB,EAAgB,MAAM,eAAe,CAAA;AACnE,OAAO,EACN,KAAK,wBAAwB,EAC7B,KAAK,aAAa,IAAI,kBAAkB,EACxC,KAAK,aAAa,IAAI,kBAAkB,EAOxC,MAAM,gBAAgB,CAAA;AAEvB;;;;;;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AC,CAAA;AAExF;;GAEG;AACH,MAAM,WAAW,iBAAkB,SAAQ,gBAAgB;IAC1D;;OAEG;IACH,IAAI,EAAE,YAAY,CAAA;IAClB;;;;OAIG;IACH,WAAW,EAAE,cAAc,CAAA;CAC3B"}
@@ -9,7 +9,7 @@ import { latLngToCell } from "h3-js";
9
9
  import { GeoBoundingBox, isBBox } from "../bbox.js";
10
10
  import { shortenH3Cell } from "../h3/cell.js";
11
11
  import { GeometryType } from "../objects.js";
12
- import { clampLatitude, inferGeoJSONCoordOrder, isCoordPairLiteral, isGoogleMapsLatLngLiteral, isInterpolatedCoordinates, wrapLongitude, } from "../position.js";
12
+ import { clampLatitude, isCoordPairLiteral, isGoogleMapsLatLngLiteral, isInterpolatedCoordinates, isValidLatitude, isValidLongitude, wrapLongitude, } from "../position.js";
13
13
  /**
14
14
  * Type-predicate to determine if the given input is a GeoJSON Point geometry.
15
15
  */
@@ -74,8 +74,18 @@ export class GeoPoint {
74
74
  }
75
75
  return [this.#longitude, this.#latitude];
76
76
  }
77
+ /**
78
+ * Assigns the pair as GeoJSON [longitude, latitude(, altitude)] — the axis order is the contract, never inferred from
79
+ * the magnitudes — and REJECTS a coordinate that is not on the globe. See {@link GeoPoint.from} for why both halves of
80
+ * that sentence are load-bearing.
81
+ *
82
+ * @throws {RangeError} When longitude is outside [-180, 180] or latitude is outside [-90, 90].
83
+ */
77
84
  set coordinates(coords) {
78
85
  const [longitude, latitude, altitude] = coords;
86
+ if (!isValidLongitude(longitude) || !isValidLatitude(latitude)) {
87
+ throw new RangeError(`GeoPoint expects GeoJSON [longitude, latitude] with longitude in [-180, 180] and latitude in [-90, 90]; got [${longitude}, ${latitude}]`);
88
+ }
79
89
  this.#longitude = longitude;
80
90
  this.#latitude = latitude;
81
91
  this.#altitude = typeof altitude === "number" ? altitude : 0;
@@ -124,14 +134,7 @@ export class GeoPoint {
124
134
  }
125
135
  constructor(input, bbox) {
126
136
  if (isCoordPairLiteral(input)) {
127
- // A ternary does not carry the narrowing through, and inferGeoJSONCoordOrder needs the 2-tuple.
128
- // oxlint-disable-next-line unicorn/prefer-ternary -- the if/else is what narrows `input`
129
- if (input.length === 2) {
130
- this.coordinates = inferGeoJSONCoordOrder(input);
131
- }
132
- else {
133
- this.coordinates = input;
134
- }
137
+ this.coordinates = input;
135
138
  }
136
139
  else if (isPointLiteral(input)) {
137
140
  this.coordinates = [...input.coordinates];
@@ -143,14 +146,10 @@ export class GeoPoint {
143
146
  this.coordinates = [input.lng, input.lat];
144
147
  }
145
148
  else if (isGeolocationCoordinatesLike(input)) {
146
- this.#longitude = input.longitude;
147
- this.#latitude = input.latitude;
148
- this.#altitude = input.altitude || 0;
149
+ this.coordinates = [input.longitude, input.latitude, input.altitude || 0];
149
150
  }
150
151
  else if (isInterpolatedCoordinates(input)) {
151
- this.#longitude = input.x;
152
- this.#latitude = input.y;
153
- this.#altitude = 0;
152
+ this.coordinates = [input.x, input.y];
154
153
  }
155
154
  else {
156
155
  this.coordinates = [0, 0];
@@ -160,7 +159,25 @@ export class GeoPoint {
160
159
  }
161
160
  }
162
161
  /**
163
- * Attempts to create a new GeoPoint instance from the given input.
162
+ * Attempts to create a new GeoPoint instance from the given input, returning `null` rather than throwing when the
163
+ * input is not a coordinate this class will stand behind.
164
+ *
165
+ * Two rules, both of which this constructor got wrong until 2026-08-05 (the defect was recorded in `e9bfd139` and
166
+ * routed around rather than fixed):
167
+ *
168
+ * 1. **A 2-tuple is GeoJSON [longitude, latitude]. The axis order is never inferred.** The old path ran the pair through
169
+ * `inferGeoJSONCoordOrder`, whose only signal is the [-90, 90] latitude range, so it transposed a pair exactly
170
+ * when |the second magnitude| > 90. A caller handing it `[latitude, longitude]` therefore got the pair repaired in
171
+ * Dallas and left corrupted in Berlin — behaviour selected by the data, from one code path. This change is a no-op
172
+ * for every WELL-FORMED input: a valid `[longitude, latitude]` pair can never have an out-of-range second element,
173
+ * so the heuristic never fired on one.
174
+ * 2. **An out-of-range magnitude is rejected, not repaired.** `[999, 999]` used to produce a GeoPoint reporting latitude
175
+ * 999. It now returns `null` here and throws a `RangeError` from the constructor. Note the deliberate asymmetry
176
+ * with the scalar `longitude` / `latitude` setters, which still wrap and clamp: mutating a point is a pan gesture,
177
+ * where 190° meaning -170° is right; PARSING one is a claim about the world, where an impossible magnitude means
178
+ * the input was malformed and any repair invents a location.
179
+ *
180
+ * A 0/0 result is treated as the "missing coordinate" sentinel (Null Island) and also returns `null`.
164
181
  */
165
182
  static from(input) {
166
183
  if (!input)
@@ -1 +1 @@
1
- {"version":3,"file":"point.js","sourceRoot":"","sources":["../../geometries/point.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,wBAAwB,CAAA;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AAEpC,OAAO,EAA0C,cAAc,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAC3F,OAAO,EAAe,aAAa,EAAE,MAAM,eAAe,CAAA;AAC1D,OAAO,EAAyB,YAAY,EAAE,MAAM,eAAe,CAAA;AACnE,OAAO,EAIN,aAAa,EACb,sBAAsB,EACtB,kBAAkB,EAClB,yBAAyB,EACzB,yBAAyB,EACzB,aAAa,GACb,MAAM,gBAAgB,CAAA;AA4BvB;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,KAAgD;IAC9E,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAA;IAErD,IAAI,CAAC,CAAC,MAAM,IAAI,KAAK,CAAC;QAAE,OAAO,KAAK,CAAA;IAEpC,IAAI,CAAC,CAAC,aAAa,IAAI,KAAK,CAAC;QAAE,OAAO,KAAK,CAAA;IAE3C,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,CAAC,KAAK;QAAE,OAAO,KAAK,CAAA;IAEnD,OAAO,kBAAkB,CAAC,K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;IAEM,eAAe;QACrB,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,CAAA;IACzC,CAAC;IAEM,eAAe;QACrB,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,CAAA;IACzD,CAAC;IAED;;OAEG;IACI,qBAAqB;QAC3B,OAAO;YACN,GAAG,EAAE,IAAI,CAAC,SAAS;YACnB,GAAG,EAAE,IAAI,CAAC,UAAU;SACpB,CAAA;IACF,CAAC;IAED;;OAEG;IACI,KAAK;QACX,MAAM,SAAS,GAAG,aAAa,CAAC,GAAG,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC,CAAA;QAEvE,OAAO,SAAS,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAA;IAC3C,CAAC;IAED;;OAEG;IACI,QAAQ,CAAC,UAAU,GAAG,EAAE;QAC9B,MAAM,IAAI,GAAG,YAAY,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,UAAU,EAAE,UAAU,CAAW,CAAA;QAEhF,OAAO,IAAI,CAAA;IACZ,CAAC;IAED;;OAEG;IACI,aAAa,CAAC,UAAU,GAAG,EAAE;QACnC,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAA;QAEtC,OAAO,aAAa,CAAC,IAAI,CAAC,CAAA;IAC3B,CAAC;IAEM,QAAQ;QACd,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAA;IACrC,CAAC;IACD,YAAY;IAEL,CAAC,MAAM,CAAC,QAAQ,CAAC;QACvB,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAA;IAC3C,CAAC;CACD"}
@@ -105,15 +105,47 @@ export declare function isPolygonLiteral<P extends PolygonPath = PolygonPath>(in
105
105
  * Predicate for checking if a polygon geometry is a solid, i.e. it has no holes.
106
106
  */
107
107
  export declare function isSolidPolygonPath(input: PolygonLiteral): boolean;
108
+ /**
109
+ * A linear ring as the containment predicates read it: positions of `[lon, lat, …]`.
110
+ *
111
+ * Deliberately looser than {@link LineStringPath} — the ray cast only ever indexes `[0]` and `[1]`, and the callers
112
+ * arrive with different position types (`[number, number, ...number[]]` from the resolver's GeoJSON reader, plain
113
+ * `number[][]` from a `JSON.parse` of a stored geometry column). A tight tuple type here would force a cast at every
114
+ * call site and buy nothing the predicate uses.
115
+ */
116
+ export type ContainmentRing = readonly (readonly number[])[];
117
+ /**
118
+ * Ray-cast a point against ONE linear ring — the even-odd crossing count. Shoot a ray along +lon and toggle on every
119
+ * edge crossing.
120
+ *
121
+ * Points exactly on an edge are implementation-defined; either side is acceptable for geocoding, where admin boundaries
122
+ * are Douglas-Peucker–simplified before they ever reach us.
123
+ */
124
+ export declare function pointInRing(lon: number, lat: number, ring: ContainmentRing): boolean;
125
+ /**
126
+ * Even-odd containment over a polygon's ring list (`[outer, hole₁, …]`).
127
+ *
128
+ * Being inside an odd number of rings means inside the polygon, which handles holes — and islands inside holes —
129
+ * without depending on ring winding order. GeoJSON nominally specifies orientation, but the gazetteer sources do not
130
+ * reliably honour it, so the orientation-free rule is the one that survives real data.
131
+ */
132
+ export declare function pointInPolygon(lon: number, lat: number, rings: readonly ContainmentRing[]): boolean;
133
+ /**
134
+ * Inside ANY polygon of a multi-polygon.
135
+ */
136
+ export declare function pointInMultiPolygon(lon: number, lat: number, polygons: readonly (readonly ContainmentRing[])[]): boolean;
108
137
  /**
109
138
  * A collection of polygons, such as a country with islands or a lake with islands.
110
139
  */
111
140
  export interface MultiPolygonLiteral<P extends PolygonPath = SolidPolygonPath> extends GeoObjectLiteral {
112
141
  type: "MultiPolygon";
113
142
  /**
114
- * An array of polygons.
143
+ * One ring array per polygon — `coordinates[polygon][ring][position]`, matching a `Polygon`'s `coordinates` lifted by
144
+ * exactly one level.
145
+ *
146
+ * @see {@link https://datatracker.ietf.org/doc/html/rfc7946#section-3.1.7 | RFC 7946 Section 3.1.7}
115
147
  */
116
- coordinates: P[][];
148
+ coordinates: P[];
117
149
  }
118
150
  /**
119
151
  * Predicate for checking if a GeoJSON object is a `MultiPolygon` geometry.
@@ -1 +1 @@
1
- {"version":3,"file":"polygon.d.ts","sourceRoot":"","sources":["../../geometries/polygon.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAEtD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC9B;;;OAGG;IACH,YAAY,EAAE,cAAc;CAC5B,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC/B;;;OAGG;IACH,YAAY,EAAE,cAAc;IAC5B;;OAEG;IACH,GAAG,aAAa,EAAE,cAAc,EAAE;CAClC,CAAA;AAED;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,GAAG,gBAAgB,GAAG,iBAAiB,CAAA;AAE9D;;GAEG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC,SAAS,WAAW,GAAG,gBAAgB,CAAE,SAAQ,gBAAgB;IACjG;;OAEG;IACH,IAAI,EAAE,SAAS,CAAA;IACf;;;;;;OAMG;IACH,WAAW,EAAE,CAAC,CAAA;CACd;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,cAAc,CAAC,CAAC,CAAC,CAIhH;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAEjE;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB,CAAC,CAAC,SAAS,WAAW,GAAG,gBAAgB,CA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AAED,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAiBlG"}
@@ -18,6 +18,49 @@ export function isPolygonLiteral(input) {
18
18
  export function isSolidPolygonPath(input) {
19
19
  return input.coordinates.length === 1;
20
20
  }
21
+ /**
22
+ * Ray-cast a point against ONE linear ring — the even-odd crossing count. Shoot a ray along +lon and toggle on every
23
+ * edge crossing.
24
+ *
25
+ * Points exactly on an edge are implementation-defined; either side is acceptable for geocoding, where admin boundaries
26
+ * are Douglas-Peucker–simplified before they ever reach us.
27
+ */
28
+ export function pointInRing(lon, lat, ring) {
29
+ let inside = false;
30
+ const n = ring.length;
31
+ for (let i = 0, j = n - 1; i < n; j = i++) {
32
+ const xi = ring[i][0];
33
+ const yi = ring[i][1];
34
+ const xj = ring[j][0];
35
+ const yj = ring[j][1];
36
+ if (yi > lat !== yj > lat && lon < ((xj - xi) * (lat - yi)) / (yj - yi) + xi) {
37
+ inside = !inside;
38
+ }
39
+ }
40
+ return inside;
41
+ }
42
+ /**
43
+ * Even-odd containment over a polygon's ring list (`[outer, hole₁, …]`).
44
+ *
45
+ * Being inside an odd number of rings means inside the polygon, which handles holes — and islands inside holes —
46
+ * without depending on ring winding order. GeoJSON nominally specifies orientation, but the gazetteer sources do not
47
+ * reliably honour it, so the orientation-free rule is the one that survives real data.
48
+ */
49
+ export function pointInPolygon(lon, lat, rings) {
50
+ let inside = false;
51
+ for (const ring of rings) {
52
+ if (pointInRing(lon, lat, ring)) {
53
+ inside = !inside;
54
+ }
55
+ }
56
+ return inside;
57
+ }
58
+ /**
59
+ * Inside ANY polygon of a multi-polygon.
60
+ */
61
+ export function pointInMultiPolygon(lon, lat, polygons) {
62
+ return polygons.some((rings) => pointInPolygon(lon, lat, rings));
63
+ }
21
64
  /**
22
65
  * Predicate for checking if a GeoJSON object is a `MultiPolygon` geometry.
23
66
  */