@mailwoman/spatial 9.1.0 → 9.3.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 (161) hide show
  1. package/{bbox.ts → lib/bbox.ts} +54 -3
  2. package/lib/coordinate-bounds.ts +52 -0
  3. package/{coordinate-formats.ts → lib/coordinate-formats.ts} +16 -3
  4. package/lib/distance.ts +165 -0
  5. package/{feature.ts → lib/feature.ts} +1 -1
  6. package/{geometries → lib/geometries}/collection.ts +4 -4
  7. package/lib/geometries/index.ts +13 -0
  8. package/{geometries → lib/geometries}/line-string.ts +2 -2
  9. package/{geometries → lib/geometries}/point.ts +9 -9
  10. package/{geometries → lib/geometries}/polygon.ts +93 -89
  11. package/lib/geometries/ring-blob.ts +521 -0
  12. package/{google → lib/google}/index.ts +1 -1
  13. package/{h3 → lib/h3}/cell.ts +83 -1
  14. package/lib/h3/coverage.ts +45 -0
  15. package/{h3 → lib/h3}/index.ts +5 -3
  16. package/lib/h3/interior-cells.ts +138 -0
  17. package/lib/h3/polygon-cells.ts +462 -0
  18. package/lib/index.ts +21 -0
  19. package/{objects.ts → lib/objects.ts} +1 -1
  20. package/lib/open-location-code.ts +168 -0
  21. package/{osgb36.ts → lib/osgb36.ts} +2 -2
  22. package/{polyline.ts → lib/polyline.ts} +1 -1
  23. package/lib/position.ts +216 -0
  24. package/lib/projection-transform.ts +115 -0
  25. package/{regions → lib/regions}/codes.ts +1 -1
  26. package/{regions → lib/regions}/index.ts +2 -2
  27. package/lib/tools/ogr-stream.ts +99 -0
  28. package/lib/tools/ogr.ts +201 -0
  29. package/{sdk → lib}/well-known-text.ts +2 -1
  30. package/out/bbox.d.ts +23 -2
  31. package/out/bbox.d.ts.map +1 -1
  32. package/out/bbox.js +33 -2
  33. package/out/bbox.js.map +1 -1
  34. package/out/coordinate-bounds.d.ts +41 -0
  35. package/out/coordinate-bounds.d.ts.map +1 -0
  36. package/out/coordinate-bounds.js +45 -0
  37. package/out/coordinate-bounds.js.map +1 -0
  38. package/out/coordinate-formats.d.ts +8 -0
  39. package/out/coordinate-formats.d.ts.map +1 -1
  40. package/out/coordinate-formats.js +14 -3
  41. package/out/coordinate-formats.js.map +1 -1
  42. package/out/distance.d.ts +84 -0
  43. package/out/distance.d.ts.map +1 -0
  44. package/out/distance.js +132 -0
  45. package/out/distance.js.map +1 -0
  46. package/out/feature.d.ts +1 -1
  47. package/out/feature.d.ts.map +1 -1
  48. package/out/feature.js.map +1 -1
  49. package/out/geometries/collection.d.ts +4 -4
  50. package/out/geometries/collection.d.ts.map +1 -1
  51. package/out/geometries/collection.js.map +1 -1
  52. package/out/geometries/index.d.ts +5 -4
  53. package/out/geometries/index.d.ts.map +1 -1
  54. package/out/geometries/index.js +5 -4
  55. package/out/geometries/index.js.map +1 -1
  56. package/out/geometries/line-string.d.ts +2 -2
  57. package/out/geometries/line-string.d.ts.map +1 -1
  58. package/out/geometries/line-string.js.map +1 -1
  59. package/out/geometries/point.d.ts +9 -9
  60. package/out/geometries/point.d.ts.map +1 -1
  61. package/out/geometries/point.js +9 -9
  62. package/out/geometries/point.js.map +1 -1
  63. package/out/geometries/polygon.d.ts +60 -56
  64. package/out/geometries/polygon.d.ts.map +1 -1
  65. package/out/geometries/polygon.js +66 -63
  66. package/out/geometries/polygon.js.map +1 -1
  67. package/out/geometries/ring-blob.d.ts +183 -0
  68. package/out/geometries/ring-blob.d.ts.map +1 -0
  69. package/out/geometries/ring-blob.js +376 -0
  70. package/out/geometries/ring-blob.js.map +1 -0
  71. package/out/google/index.d.ts +1 -1
  72. package/out/google/index.d.ts.map +1 -1
  73. package/out/google/index.js +1 -1
  74. package/out/google/index.js.map +1 -1
  75. package/out/google/place-id.d.ts.map +1 -1
  76. package/out/google/place-id.js.map +1 -1
  77. package/out/h3/cell.d.ts +32 -0
  78. package/out/h3/cell.d.ts.map +1 -1
  79. package/out/h3/cell.js +68 -1
  80. package/out/h3/cell.js.map +1 -1
  81. package/out/h3/coverage.d.ts +32 -0
  82. package/out/h3/coverage.d.ts.map +1 -0
  83. package/out/h3/coverage.js +27 -0
  84. package/out/h3/coverage.js.map +1 -0
  85. package/out/h3/index.d.ts +5 -3
  86. package/out/h3/index.d.ts.map +1 -1
  87. package/out/h3/index.js +5 -3
  88. package/out/h3/index.js.map +1 -1
  89. package/out/h3/interior-cells.d.ts +54 -0
  90. package/out/h3/interior-cells.d.ts.map +1 -0
  91. package/out/h3/interior-cells.js +111 -0
  92. package/out/h3/interior-cells.js.map +1 -0
  93. package/out/h3/polygon-cells.d.ts +182 -0
  94. package/out/h3/polygon-cells.d.ts.map +1 -0
  95. package/out/h3/polygon-cells.js +339 -0
  96. package/out/h3/polygon-cells.js.map +1 -0
  97. package/out/index.d.ts +15 -12
  98. package/out/index.d.ts.map +1 -1
  99. package/out/index.js +15 -12
  100. package/out/index.js.map +1 -1
  101. package/out/objects.d.ts +1 -1
  102. package/out/objects.d.ts.map +1 -1
  103. package/out/objects.js +1 -1
  104. package/out/objects.js.map +1 -1
  105. package/out/open-location-code.d.ts +48 -0
  106. package/out/open-location-code.d.ts.map +1 -0
  107. package/out/open-location-code.js +137 -0
  108. package/out/open-location-code.js.map +1 -0
  109. package/out/osgb36.d.ts +2 -2
  110. package/out/osgb36.d.ts.map +1 -1
  111. package/out/osgb36.js +1 -1
  112. package/out/osgb36.js.map +1 -1
  113. package/out/polyline.d.ts.map +1 -1
  114. package/out/polyline.js +1 -1
  115. package/out/polyline.js.map +1 -1
  116. package/out/position.d.ts +4 -61
  117. package/out/position.d.ts.map +1 -1
  118. package/out/position.js +14 -126
  119. package/out/position.js.map +1 -1
  120. package/out/projection-transform.d.ts +67 -0
  121. package/out/projection-transform.d.ts.map +1 -0
  122. package/out/projection-transform.js +48 -0
  123. package/out/projection-transform.js.map +1 -0
  124. package/out/projection.d.ts.map +1 -1
  125. package/out/projection.js.map +1 -1
  126. package/out/regions/codes.d.ts.map +1 -1
  127. package/out/regions/codes.js.map +1 -1
  128. package/out/regions/index.d.ts +2 -2
  129. package/out/regions/index.d.ts.map +1 -1
  130. package/out/regions/index.js +2 -2
  131. package/out/regions/index.js.map +1 -1
  132. package/out/regions/names.d.ts.map +1 -1
  133. package/out/regions/names.js.map +1 -1
  134. package/out/tools/ogr-stream.d.ts +34 -0
  135. package/out/tools/ogr-stream.d.ts.map +1 -0
  136. package/out/tools/ogr-stream.js +74 -0
  137. package/out/tools/ogr-stream.js.map +1 -0
  138. package/out/tools/ogr.d.ts +87 -0
  139. package/out/tools/ogr.d.ts.map +1 -0
  140. package/out/tools/ogr.js +84 -0
  141. package/out/tools/ogr.js.map +1 -0
  142. package/out/tsconfig.test.tsbuildinfo +1 -1
  143. package/out/{sdk/well-known-text.d.ts → well-known-text.d.ts} +1 -1
  144. package/out/well-known-text.d.ts.map +1 -0
  145. package/out/well-known-text.js.map +1 -0
  146. package/package.json +143 -14
  147. package/geometries/index.ts +0 -12
  148. package/index.ts +0 -18
  149. package/out/sdk/index.d.ts +0 -7
  150. package/out/sdk/index.d.ts.map +0 -1
  151. package/out/sdk/index.js +0 -7
  152. package/out/sdk/index.js.map +0 -1
  153. package/out/sdk/well-known-text.d.ts.map +0 -1
  154. package/out/sdk/well-known-text.js.map +0 -1
  155. package/out/tsconfig.tsbuildinfo +0 -1
  156. package/position.ts +0 -345
  157. package/sdk/index.ts +0 -7
  158. /package/{google → lib/google}/place-id.ts +0 -0
  159. /package/{projection.ts → lib/projection.ts} +0 -0
  160. /package/{regions → lib/regions}/names.ts +0 -0
  161. /package/out/{sdk/well-known-text.js → well-known-text.js} +0 -0
@@ -0,0 +1,339 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * Turn one authority polygon into the H3 cells that summarize it — the conversion SCOPE invariant 6 asks
7
+ * for, done once at build time so the runtime probes structure instead of geometry.
8
+ *
9
+ * SHARED BY EVERY POLYGON LAYER RATHER THAN COPIED INTO EACH, because the traps below are properties of
10
+ * the TOOL rather than of any one product. `packages/flood` measured them; `packages/soil` inherits them
11
+ * unchanged; the layer contract's polygon-builder section states them as requirements. A second copy of
12
+ * an allocator guard is a second place for it to stop guarding.
13
+ *
14
+ * THE INDEX IS CELL-TOUCHES-POLYGON, NOT CENTRE-IN-POLYGON, AND A ZERO-CELL FEATURE FAILS THE BUILD.
15
+ * A polyfill keyed on cell centres drops every polygon smaller than a cell, and each dropped feature
16
+ * reads downstream as an absence. Measured: on Ireland's zoning layer `polygonToCells` returns zero cells
17
+ * for 86.8% of polygons at resolution 9, and the EA flood product's first row is a 128 m² square that
18
+ * `polygonToCells` misses at resolutions 7 through 10 while `containmentOverlapping` returns one cell for
19
+ * it. So the index takes overlapping containment, and {@link classifyFeatureCells} throws on a feature
20
+ * that reaches no cell rather than skipping it.
21
+ *
22
+ * THE `[lat, lng]` TRAP IS AVOIDED BY NOT ENTERING IT. h3-js reads a vertex as `[lat, lng]` in its
23
+ * default mode; every call here passes `isGeoJSON = true` and hands it GeoJSON-order `[lon, lat]` rings,
24
+ * which is the order an ingest already produces. Converting instead would put a transposition between the
25
+ * geometry and the index that nothing downstream could see.
26
+ *
27
+ * WHOLE AND PARTIAL ARE TWO POLYFILLS OF THE SAME RING, NOT A TEST WE INVENT. `containmentFull` is the
28
+ * cell set entirely inside the polygon; `containmentOverlapping` is the set that touches it at all. The
29
+ * difference is exactly the boundary fringe, which is where the geometry tier has to be consulted.
30
+ *
31
+ * MOST PARTS NEVER REACH h3 AT ALL, AND THAT IS THE POINT. The WASM heap is exhausted by CALL VOLUME, not
32
+ * by any one polygon: h3-js frees every buffer it allocates, so what accumulates over millions of
33
+ * interleaved tiny and large allocations is fragmentation. Three runs over the EA product died on the
34
+ * same feature after roughly 510,000 others — a 164 m² feature of 23 parts and 130 vertices that
35
+ * classifies in 35 ms at every resolution 9 through 4 in a fresh process. So the calls are removed rather
36
+ * than shrunk, in the two places where the answer is a fact about geometry: {@link enclosingCell} (a part
37
+ * whose bounding-box corners all fall in one cell lies inside it, because a cell is convex) and
38
+ * {@link canContainCell} (a part narrower than `edge × √3` cannot enclose a hexagon, so its
39
+ * `containmentFull` set is empty). Both were checked against the unconditional polyfill over 60,000 real
40
+ * features at resolution 9 with zero disagreements, and `packages/flood/test/unit/cells.test.ts` pins the
41
+ * comparison.
42
+ *
43
+ * A BIG POLYGON IS ALSO INDEXED COARSER, BECAUSE h3's ALLOCATOR IS SIZED FROM THE BOUNDING BOX.
44
+ * `polygonToCells` reserves room for the whole bounding box before it walks anything, so a long thin river
45
+ * polygon reserves the rectangle the river's meanders span rather than the river. Each feature is
46
+ * therefore indexed at the finest resolution whose bounding-box estimate fits {@link CELL_ESTIMATE_BUDGET},
47
+ * and the resolution it got is returned on the result. That is not a compromise bolted on: a coarse cell
48
+ * wholly inside a large polygon is exactly what `compactCells` would have produced anyway, so the whole
49
+ * tier is unchanged in meaning and only the fringe is coarser.
50
+ *
51
+ * AND THE ESTIMATE IS A PREDICTION, SO AN ALLOCATION FAILURE IS RECOVERED RATHER THAN FATAL.
52
+ * {@linkcode classifyFeatureCells} steps the resolution down and retries; only a feature that fails at
53
+ * {@linkcode MIN_INDEX_RESOLUTION} is refused. Nothing is ever skipped, because a skipped feature is an
54
+ * invented absence.
55
+ *
56
+ * BOUNDING THE CALL VOLUME IS THE CALLER'S JOB AND IT IS NOT OPTIONAL. The shortcuts here make a build
57
+ * faster; they are not what makes it reproducible. A builder runs the classification in child processes
58
+ * over ranges of the source's own stable ids, so each gets a heap that starts empty — see
59
+ * `packages/flood/lib/sdk/ingest-chunk.ts` and `packages/soil/lib/sdk/ingest-chunk.ts`.
60
+ */
61
+ import { cellToChildren, cellToParent, compactCells, getHexagonAreaAvg, getHexagonEdgeLengthAvg, getResolution, latLngToCell, polygonToCellsExperimental, POLYGON_TO_CELLS_FLAGS, } from "h3-js";
62
+ import { METRES_PER_DEGREE } from "#distance";
63
+ import { ringsBoundingBox } from "#geometries/ring-blob";
64
+ import { shortCellToInt } from "#h3/cell";
65
+ /**
66
+ * The largest bounding-box cell estimate a single polyfill may reserve.
67
+ *
68
+ * H3-js allocates its output buffer from the polygon's bounding box before walking, so this is a memory ceiling rather
69
+ * than a limit on real output: two million cells is sixteen megabytes of `uint64`, comfortably inside the WASM heap,
70
+ * and the largest EA flood features exceed it by orders of magnitude at resolution 9 (the run that established this
71
+ * failed with `Memory allocation failed (code: 13)`).
72
+ */
73
+ export const CELL_ESTIMATE_BUDGET = 2_000_000;
74
+ /**
75
+ * The coarsest resolution a feature may be pushed down to. Below this a "cell" is tens of thousands of square
76
+ * kilometres and the index stops summarizing anything.
77
+ */
78
+ export const MIN_INDEX_RESOLUTION = 4;
79
+ /**
80
+ * A degree box's height and width in metres, longitude scaled at the box's mid-latitude so the two are comparable.
81
+ */
82
+ function boxExtentMetres(box) {
83
+ const midLat = ((box.minLat + box.maxLat) / 2) * (Math.PI / 180);
84
+ return {
85
+ heightM: (box.maxLat - box.minLat) * METRES_PER_DEGREE,
86
+ widthM: (box.maxLon - box.minLon) * METRES_PER_DEGREE * Math.cos(midLat),
87
+ };
88
+ }
89
+ /**
90
+ * The single cell containing this whole bounding box, or `undefined` when it spans more than one.
91
+ *
92
+ * An H3 cell is convex, so a rectangle whose four corners all fall in the same cell lies entirely inside it. That makes
93
+ * this an exact answer rather than an approximation, and it takes the WASM polyfill off the majority of a small-polygon
94
+ * product's parts: 38.8% of the EA flood features are under 11 m across, and most parts of the multi-part ones are
95
+ * smaller still.
96
+ */
97
+ function enclosingCell(box, resolution) {
98
+ if (!Number.isFinite(box.minLat))
99
+ return undefined;
100
+ const first = latLngToCell(box.minLat, box.minLon, resolution);
101
+ for (const [lat, lon] of [
102
+ [box.minLat, box.maxLon],
103
+ [box.maxLat, box.minLon],
104
+ [box.maxLat, box.maxLon],
105
+ ]) {
106
+ if (latLngToCell(lat, lon, resolution) !== first)
107
+ return undefined;
108
+ }
109
+ return first;
110
+ }
111
+ /**
112
+ * Could a shape this size contain a whole cell?
113
+ *
114
+ * A hexagon's minimum width is twice its inradius, and its inradius is `edge × √3/2` — so a bounding box narrower than
115
+ * `edge × √3` in either direction cannot enclose one, and the `containmentFull` polyfill is guaranteed to return
116
+ * nothing. The comparison is deliberately permissive: a wrong `true` costs one polyfill call, while a wrong `false`
117
+ * would demote a whole cell to a partial one, which the ray cast still answers correctly but more slowly.
118
+ */
119
+ function canContainCell(box, resolution) {
120
+ if (!Number.isFinite(box.minLat))
121
+ return false;
122
+ const minimumWidthM = getHexagonEdgeLengthAvg(resolution, "m") * Math.sqrt(3);
123
+ const { heightM, widthM } = boxExtentMetres(box);
124
+ return heightM >= minimumWidthM && widthM >= minimumWidthM;
125
+ }
126
+ /**
127
+ * How many cells at `resolution` the feature's bounding box spans.
128
+ *
129
+ * The same quantity h3 reserves its buffer from, computed here so an oversized polyfill is never issued. Approximate on
130
+ * purpose: it decides which resolution to ask for, not what the answer is.
131
+ */
132
+ export function estimateCellCount(polygons, resolution) {
133
+ const box = ringsBoundingBox(polygons);
134
+ if (!Number.isFinite(box.minLat))
135
+ return 0;
136
+ const { heightM, widthM } = boxExtentMetres(box);
137
+ const heightKM = heightM / 1000;
138
+ const widthKM = widthM / 1000;
139
+ return (Math.max(widthKM, 0.001) * Math.max(heightKM, 0.001)) / getHexagonAreaAvg(resolution, "km2");
140
+ }
141
+ /**
142
+ * The finest resolution at or below `target` whose estimate fits the budget.
143
+ */
144
+ export function resolutionForFeature(polygons, target) {
145
+ for (let resolution = target; resolution > MIN_INDEX_RESOLUTION; resolution--) {
146
+ if (estimateCellCount(polygons, resolution) <= CELL_ESTIMATE_BUDGET)
147
+ return resolution;
148
+ }
149
+ return MIN_INDEX_RESOLUTION;
150
+ }
151
+ /**
152
+ * Classify one feature's cells, at `targetResolution` or the coarsest resolution its bounding box allows.
153
+ *
154
+ * @param layerLabel Names the layer in every message, so a build log says which artifact refused rather than only which
155
+ * feature.
156
+ * @throws {Error} When the feature reaches no cell at all. That cannot happen with overlapping containment on a valid
157
+ * ring, so it means the geometry is degenerate — and a silently skipped feature is an invented absence.
158
+ */
159
+ export function classifyFeatureCells(polygons, targetResolution, featureID, layerLabel = "polygon index") {
160
+ let resolution = resolutionForFeature(polygons, targetResolution);
161
+ let touched = new Set();
162
+ let full = new Set();
163
+ // THE BUDGET IS A PREDICTION AND THE RETRY IS WHAT MAKES IT NON-FATAL. `estimateCellCount` is a bounding-box
164
+ // approximation of what h3 will reserve, and h3's own reservation depends on the polygon's shape and on what the WASM
165
+ // heap already holds — measured over the EA product, a run that had classified 350,000 features threw `Memory
166
+ // allocation failed (code: 13)` on a feature that classified cleanly on its own. So an allocation failure steps the
167
+ // resolution down and tries again rather than ending the build, and only a feature that fails at
168
+ // {@link MIN_INDEX_RESOLUTION} is refused: a coarser cell is a real answer, and a skipped feature is an invented
169
+ // absence.
170
+ for (;;) {
171
+ try {
172
+ touched = new Set();
173
+ full = new Set();
174
+ for (const rings of polygons) {
175
+ // `isGeoJSON = true`: the rings are already `[lon, lat]`, which is the order an ingest emits. Converting
176
+ // instead would put a transposition between the geometry and the index that nothing downstream could see.
177
+ const geoJSONRings = rings;
178
+ const box = ringsBoundingBox([rings]);
179
+ const enclosing = enclosingCell(box, resolution);
180
+ // A PART THAT FITS INSIDE ONE CELL IS ANSWERED WITHOUT THE ALLOCATOR, and that is a fact rather than an
181
+ // approximation: an H3 cell is convex, so a rectangle whose four corners all fall in one cell lies entirely
182
+ // within it. Such a part touches exactly that cell and fills none of it.
183
+ if (enclosing) {
184
+ touched.add(enclosing);
185
+ continue;
186
+ }
187
+ const overlapping = polygonToCellsExperimental(geoJSONRings, resolution, POLYGON_TO_CELLS_FLAGS.containmentOverlapping, true);
188
+ // AN EMPTY ANSWER FOR A REAL PART IS AN ALLOCATOR FAILURE WEARING A RESULT'S CLOTHES, and it has to be caught
189
+ // HERE rather than after the whole feature. h3-js sizes its output buffer with `_calloc`, and a `_calloc`
190
+ // that fails returns the null pointer — which in WASM is ordinary writable memory, so the call reports
191
+ // success and the reader hands back an array of zeros, i.e. nothing. Every part with a non-degenerate
192
+ // bounding box touches at least one cell, so zero is impossible as an answer. Checking per FEATURE instead
193
+ // would pass any multi-part feature whose other parts happened to answer, and silently index it short.
194
+ if (!overlapping.length) {
195
+ throw new Error(`${layerLabel}: part of feature ${featureID} spanning ${box.minLat},${box.minLon} to ${box.maxLat},${box.maxLon} returned no cell at resolution ${resolution} — a part always touches at least one, so this is an allocator failure reported as an answer`);
196
+ }
197
+ for (const cell of overlapping) {
198
+ touched.add(cell);
199
+ }
200
+ // A part narrower than a cell's minimum width cannot contain one, so its `full` set is empty and asking for it
201
+ // is pure cost. Erring towards asking is safe — a missed whole cell becomes a partial one and the ray cast
202
+ // still answers correctly — so the comparison is the permissive one.
203
+ if (!canContainCell(box, resolution))
204
+ continue;
205
+ for (const cell of polygonToCellsExperimental(geoJSONRings, resolution, POLYGON_TO_CELLS_FLAGS.containmentFull, true)) {
206
+ full.add(cell);
207
+ }
208
+ }
209
+ break;
210
+ }
211
+ catch (error) {
212
+ if (resolution <= MIN_INDEX_RESOLUTION) {
213
+ throw new Error(`${layerLabel}: feature ${featureID} could not be indexed at any resolution down to ${MIN_INDEX_RESOLUTION} — ${String(error.message)}`);
214
+ }
215
+ resolution--;
216
+ }
217
+ }
218
+ if (!touched.size) {
219
+ throw new Error(`${layerLabel}: feature ${featureID} reaches no cell at resolution ${resolution} — a feature indexed to nothing reads downstream as an absence, which is the one answer a layer must never invent`);
220
+ }
221
+ // A cell can be full for one polygon of a MultiPolygon and merely touched by another; full wins, because the point
222
+ // is inside either way.
223
+ const partial = [];
224
+ for (const cell of touched) {
225
+ if (!full.has(cell)) {
226
+ partial.push(cell);
227
+ }
228
+ }
229
+ return { resolution, whole: [...full], partial };
230
+ }
231
+ /**
232
+ * Split a cell set into same-resolution groups — what `compactCells` requires, and what an adaptively-indexed layer
233
+ * cannot assume it already has.
234
+ *
235
+ * Pooling mixed resolutions throws inside h3; compacting only the target-resolution group would silently drop every
236
+ * coarsened feature's interior, which is the shape of failure that still produces an artifact.
237
+ */
238
+ export function groupCellsByResolution(cells) {
239
+ const groups = new Map();
240
+ for (const cell of cells) {
241
+ const resolution = getResolution(cell);
242
+ const group = groups.get(resolution);
243
+ if (group) {
244
+ group.push(cell);
245
+ }
246
+ else {
247
+ groups.set(resolution, [cell]);
248
+ }
249
+ }
250
+ return [...groups.values()];
251
+ }
252
+ /**
253
+ * Compact a cell set that may span several resolutions.
254
+ *
255
+ * `compactCells` takes one resolution at a time, and an adaptively-indexed layer's coarsened features sit at another —
256
+ * so the set is grouped before compaction rather than pooled. Pooling would throw; compacting only the
257
+ * target-resolution group would silently drop every coarsened feature's interior, which is the shape of failure that
258
+ * still produces an artifact.
259
+ */
260
+ export function compactAcrossResolutions(cells) {
261
+ const compacted = [];
262
+ for (const group of groupCellsByResolution(cells)) {
263
+ compacted.push(...compactCells(group));
264
+ }
265
+ return compacted;
266
+ }
267
+ /**
268
+ * The cells a probe walks for one index cell: the cell itself at the index resolution, and its parent at every other
269
+ * resolution the layer stores.
270
+ *
271
+ * The stored rows sit at SEVERAL resolutions — each feature's whole tier is compacted parent-ward, and a polygon too
272
+ * large for h3's allocator at the index resolution was indexed coarser — so a point is answered by walking its own
273
+ * ancestor chain over every resolution the layer stores.
274
+ */
275
+ export function ancestorChainCells(indexCell, indexResolution, resolutions) {
276
+ return resolutions.map((resolution) => resolution === indexResolution ? indexCell : cellToParent(indexCell, resolution));
277
+ }
278
+ /**
279
+ * One classified feature's cell rows, ready for insertion — the whole set compacted, the partial set left at its own
280
+ * resolution.
281
+ *
282
+ * SHARED BY EVERY POLYGON LAYER WHOSE CELL ROW NAMES A POLYGON rather than a class accumulated across features. There
283
+ * is no product knowledge in it: compaction, the short-cell encoding and the belt-and-braces subtraction below are h3
284
+ * and blob arithmetic, and a second copy is a second place for the subtraction to stop happening.
285
+ *
286
+ * COMPACTION IS PER FEATURE, which is what keeps a build's memory flat in row count with no temporary table: a row that
287
+ * names one polygon is final the moment that polygon is classified. Only the WHOLE set is compacted — compacting the
288
+ * fringe would claim it covers ground it does not.
289
+ */
290
+ export function featureCellRows(cells) {
291
+ const rows = [];
292
+ const wholeShort = new Set();
293
+ for (const cell of compactAcrossResolutions(cells.whole)) {
294
+ const resolution = getResolution(cell);
295
+ const short = shortCellToInt(cell);
296
+ wholeShort.add(short);
297
+ rows.push({ h3Cell: short, resolution, containment: "whole" });
298
+ }
299
+ for (const cell of cells.partial) {
300
+ const short = shortCellToInt(cell);
301
+ // A cell cannot be both for one polygon; the classifier already subtracts the whole set, and this is belt and braces
302
+ // against a compaction that produced a parent the partial set also names.
303
+ if (wholeShort.has(short))
304
+ continue;
305
+ rows.push({ h3Cell: short, resolution: cells.resolution, containment: "partial" });
306
+ }
307
+ return rows;
308
+ }
309
+ /**
310
+ * The coverage cell a row at `cell` belongs to.
311
+ *
312
+ * `cellToParent` of the finer cell, never a fresh `latLngToCell` at the coarse resolution: every existing reader in
313
+ * this repo derives a coverage cell that way, and the two agree for a point but not for a cell — a re-derivation from a
314
+ * representative point would put a fringe row in a neighbouring coverage cell.
315
+ */
316
+ export function coverageCellFor(cell, coverageResolution) {
317
+ return cellToParent(cell, coverageResolution);
318
+ }
319
+ /**
320
+ * Record the coverage cells one index cell falls in.
321
+ *
322
+ * An adaptively-coarsened cell can be COARSER than the coverage resolution, in which case it spans several coverage
323
+ * cells and every one of them is recorded: a coarse cell counted against one arbitrary child would leave the others
324
+ * reading as empty.
325
+ */
326
+ export function addCoverageCells(into, cell, cellResolution, coverageResolution) {
327
+ if (cellResolution === coverageResolution) {
328
+ into.add(shortCellToInt(cell));
329
+ return;
330
+ }
331
+ if (cellResolution > coverageResolution) {
332
+ into.add(shortCellToInt(coverageCellFor(cell, coverageResolution)));
333
+ return;
334
+ }
335
+ for (const child of cellToChildren(cell, coverageResolution)) {
336
+ into.add(shortCellToInt(child));
337
+ }
338
+ }
339
+ //# sourceMappingURL=polygon-cells.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"polygon-cells.js","sourceRoot":"","sources":["../../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M,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,CAAC,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,CAAC,CAAA;IACnF,CAAC;IAED,OAAO,IAAI,CAAA;AACZ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY,EAAE,kBAA0B;IACvE,OAAO,YAAY,CAAC,IAAI,EAAE,kBAAkB,CAAW,CAAA;AACxD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAC/B,IAAiB,EACjB,IAAY,EACZ,cAAsB,EACtB,kBAA0B;IAE1B,IAAI,cAAc,KAAK,kBAAkB,EAAE,CAAC;QAC3C,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAA;QAE9B,OAAM;IACP,CAAC;IAED,IAAI,cAAc,GAAG,kBAAkB,EAAE,CAAC;QACzC,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC,eAAe,CAAC,IAAI,EAAE,kBAAkB,CAAC,CAAC,CAAC,CAAA;QAEnE,OAAM;IACP,CAAC;IAED,KAAK,MAAM,KAAK,IAAI,cAAc,CAAC,IAAI,EAAE,kBAAkB,CAAC,EAAE,CAAC;QAC9D,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC,KAAe,CAAC,CAAC,CAAA;IAC1C,CAAC;AACF,CAAC"}
package/out/index.d.ts CHANGED
@@ -3,16 +3,19 @@
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
5
  */
6
- export * from "./bbox.ts";
7
- export * from "./coordinate-formats.ts";
8
- export * from "./feature.ts";
9
- export * from "./geometries/index.ts";
10
- export * from "./google/index.ts";
11
- export * from "./h3/index.ts";
12
- export * from "./objects.ts";
13
- export * from "./osgb36.ts";
14
- export * from "./polyline.ts";
15
- export * from "./position.ts";
16
- export * from "./projection.ts";
17
- export * from "./regions/index.ts";
6
+ export * from "#bbox";
7
+ export * from "#coordinate-formats";
8
+ export * from "#coordinate-bounds";
9
+ export * from "#distance";
10
+ export * from "#feature";
11
+ export * from "#open-location-code";
12
+ export * from "#geometries/index";
13
+ export * from "#google/index";
14
+ export * from "#h3/index";
15
+ export * from "#objects";
16
+ export * from "#osgb36";
17
+ export * from "#polyline";
18
+ export * from "#position";
19
+ export * from "#projection";
20
+ export * from "#regions/index";
18
21
  //# sourceMappingURL=index.d.ts.map
@@ -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,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"}
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,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA"}
package/out/index.js CHANGED
@@ -3,16 +3,19 @@
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
5
  */
6
- export * from "./bbox.js";
7
- export * from "./coordinate-formats.js";
8
- export * from "./feature.js";
9
- export * from "./geometries/index.js";
10
- export * from "./google/index.js";
11
- export * from "./h3/index.js";
12
- export * from "./objects.js";
13
- export * from "./osgb36.js";
14
- export * from "./polyline.js";
15
- export * from "./position.js";
16
- export * from "./projection.js";
17
- export * from "./regions/index.js";
6
+ export * from "#bbox";
7
+ export * from "#coordinate-formats";
8
+ export * from "#coordinate-bounds";
9
+ export * from "#distance";
10
+ export * from "#feature";
11
+ export * from "#open-location-code";
12
+ export * from "#geometries/index";
13
+ export * from "#google/index";
14
+ export * from "#h3/index";
15
+ export * from "#objects";
16
+ export * from "#osgb36";
17
+ export * from "#polyline";
18
+ export * from "#position";
19
+ export * from "#projection";
20
+ export * from "#regions/index";
18
21
  //# sourceMappingURL=index.js.map
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,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"}
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,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA"}
package/out/objects.d.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
5
  */
6
- import { type BBox2DLiteral, type BBox3DLiteral } from "./bbox.ts";
6
+ import { type BBox2DLiteral, type BBox3DLiteral } from "#bbox";
7
7
  /**
8
8
  * GeoJSON object types.
9
9
  */
@@ -1 +1 @@
1
- {"version":3,"file":"objects.d.ts","sourceRoot":"","sources":["../objects.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,aAAa,EAAY,MAAM,WAAW,CAAA;AAE5E;;GAEG;AACH,MAAM,MAAM,YAAY,GACrB,OAAO,GACP,YAAY,GACZ,YAAY,GACZ,iBAAiB,GACjB,SAAS,GACT,cAAc,GACd,oBAAoB,GACpB,mBAAmB,CAAA;AAEtB;;GAEG;AACH,eAAO,MAAM,YAAY;;;;;;;;;CASsB,CAAA;AAE/C;;;;;;;;;GASG;AACH,MAAM,WAAW,gBAAgB;IAChC;;OAEG;IACH,IAAI,EAAE,YAAY,CAAA;IAElB;;OAEG;IACH,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,CAAA;IAEvC;;;;;;;OAOG;IACH,IAAI,CAAC,EAAE,aAAa,GAAG,aAAa,CAAA;IAEpC;;;;;OAKG;IACH,GAAG,CAAC,EAAE;QACL,IAAI,EAAE,MAAM,CAAA;QAEZ,UAAU,EAAE;YACX;;;;eAIG;YACH,IAAI,EAAE,MAAM,CAAA;SACZ,CAAA;KACD,CAAA;CACD;AAED;;GAEG;AACH,8BAAsB,SAAU,YAAW,gBAAgB;IAC1D;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAA;IAE3B;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,aAAa,GAAG,aAAa,CAAA;IAEpC,SAAS,aAAa,IAAI,CAAC,EAAE,aAAa,GAAG,aAAa;IAI1D;;OAEG;IACI,IAAI;CAGX"}
1
+ {"version":3,"file":"objects.d.ts","sourceRoot":"","sources":["../lib/objects.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,aAAa,EAAY,MAAM,OAAO,CAAA;AAExE;;GAEG;AACH,MAAM,MAAM,YAAY,GACrB,OAAO,GACP,YAAY,GACZ,YAAY,GACZ,iBAAiB,GACjB,SAAS,GACT,cAAc,GACd,oBAAoB,GACpB,mBAAmB,CAAA;AAEtB;;GAEG;AACH,eAAO,MAAM,YAAY;;;;;;;;;CASsB,CAAA;AAE/C;;;;;;;;;GASG;AACH,MAAM,WAAW,gBAAgB;IAChC;;OAEG;IACH,IAAI,EAAE,YAAY,CAAA;IAElB;;OAEG;IACH,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,CAAA;IAEvC;;;;;;;OAOG;IACH,IAAI,CAAC,EAAE,aAAa,GAAG,aAAa,CAAA;IAEpC;;;;;OAKG;IACH,GAAG,CAAC,EAAE;QACL,IAAI,EAAE,MAAM,CAAA;QAEZ,UAAU,EAAE;YACX;;;;eAIG;YACH,IAAI,EAAE,MAAM,CAAA;SACZ,CAAA;KACD,CAAA;CACD;AAED;;GAEG;AACH,8BAAsB,SAAU,YAAW,gBAAgB;IAC1D;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAA;IAE3B;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,aAAa,GAAG,aAAa,CAAA;IAEpC,SAAS,aAAa,IAAI,CAAC,EAAE,aAAa,GAAG,aAAa;IAI1D;;OAEG;IACI,IAAI;CAGX"}
package/out/objects.js CHANGED
@@ -3,7 +3,7 @@
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
5
  */
6
- import { is2DBBox } from "./bbox.js";
6
+ import { is2DBBox } from "#bbox";
7
7
  /**
8
8
  * Shadow enum-like record of valid GeoJSON object types.
9
9
  */
@@ -1 +1 @@
1
- {"version":3,"file":"objects.js","sourceRoot":"","sources":["../objects.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAA0C,QAAQ,EAAE,MAAM,WAAW,CAAA;AAe5E;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IAC3B,KAAK,EAAE,OAAO;IACd,UAAU,EAAE,YAAY;IACxB,UAAU,EAAE,YAAY;IACxB,eAAe,EAAE,iBAAiB;IAClC,OAAO,EAAE,SAAS;IAClB,YAAY,EAAE,cAAc;IAC5B,kBAAkB,EAAE,oBAAoB;IACxC,iBAAiB,EAAE,mBAAmB;CACQ,CAAA;AAqD/C;;GAEG;AACH,MAAM,OAAgB,SAAS;IAM9B;;;;;;OAMG;IACH,IAAI,CAAgC;IAEpC,YAAsB,IAAoC;QACzD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IACjB,CAAC;IAED;;OAEG;IACI,IAAI;QACV,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC3B,CAAC;CACD"}
1
+ {"version":3,"file":"objects.js","sourceRoot":"","sources":["../lib/objects.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAA0C,QAAQ,EAAE,MAAM,OAAO,CAAA;AAexE;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IAC3B,KAAK,EAAE,OAAO;IACd,UAAU,EAAE,YAAY;IACxB,UAAU,EAAE,YAAY;IACxB,eAAe,EAAE,iBAAiB;IAClC,OAAO,EAAE,SAAS;IAClB,YAAY,EAAE,cAAc;IAC5B,kBAAkB,EAAE,oBAAoB;IACxC,iBAAiB,EAAE,mBAAmB;CACQ,CAAA;AAqD/C;;GAEG;AACH,MAAM,OAAgB,SAAS;IAM9B;;;;;;OAMG;IACH,IAAI,CAAgC;IAEpC,YAAsB,IAAoC;QACzD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IACjB,CAAC;IAED;;OAEG;IACI,IAAI;QACV,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC3B,CAAC;CACD"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
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
+ * 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).
21
+ */
22
+ export interface DecodedPlusCode {
23
+ lat: number;
24
+ lon: number;
25
+ latSpanDeg: number;
26
+ lonSpanDeg: number;
27
+ }
28
+ /**
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.)
31
+ */
32
+ export declare function isFullPlusCode(token: string): boolean;
33
+ /**
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.
36
+ */
37
+ export declare function isShortPlusCode(token: string): boolean;
38
+ /**
39
+ * Decode a FULL plus code to its cell. Returns null on anything `isFullPlusCode` rejects.
40
+ */
41
+ export declare function decodePlusCode(code: string): DecodedPlusCode | null;
42
+ /**
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.
46
+ */
47
+ export declare function recoverNearestPlusCode(shortCode: string, refLat: number, refLon: number): DecodedPlusCode | null;
48
+ //# sourceMappingURL=open-location-code.d.ts.map
@@ -0,0 +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"}