@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.
- package/{bbox.ts → lib/bbox.ts} +54 -3
- package/lib/coordinate-bounds.ts +52 -0
- package/{coordinate-formats.ts → lib/coordinate-formats.ts} +16 -3
- package/lib/distance.ts +165 -0
- package/{feature.ts → lib/feature.ts} +1 -1
- package/{geometries → lib/geometries}/collection.ts +4 -4
- package/lib/geometries/index.ts +13 -0
- package/{geometries → lib/geometries}/line-string.ts +2 -2
- package/{geometries → lib/geometries}/point.ts +9 -9
- package/{geometries → lib/geometries}/polygon.ts +93 -89
- package/lib/geometries/ring-blob.ts +521 -0
- package/{google → lib/google}/index.ts +1 -1
- package/{h3 → lib/h3}/cell.ts +83 -1
- package/lib/h3/coverage.ts +45 -0
- package/{h3 → lib/h3}/index.ts +5 -3
- package/lib/h3/interior-cells.ts +138 -0
- package/lib/h3/polygon-cells.ts +462 -0
- package/lib/index.ts +21 -0
- package/{objects.ts → lib/objects.ts} +1 -1
- package/lib/open-location-code.ts +168 -0
- package/{osgb36.ts → lib/osgb36.ts} +2 -2
- package/{polyline.ts → lib/polyline.ts} +1 -1
- package/lib/position.ts +216 -0
- package/lib/projection-transform.ts +115 -0
- package/{regions → lib/regions}/codes.ts +1 -1
- package/{regions → lib/regions}/index.ts +2 -2
- package/lib/tools/ogr-stream.ts +99 -0
- package/lib/tools/ogr.ts +201 -0
- package/{sdk → lib}/well-known-text.ts +2 -1
- package/out/bbox.d.ts +23 -2
- package/out/bbox.d.ts.map +1 -1
- package/out/bbox.js +33 -2
- package/out/bbox.js.map +1 -1
- package/out/coordinate-bounds.d.ts +41 -0
- package/out/coordinate-bounds.d.ts.map +1 -0
- package/out/coordinate-bounds.js +45 -0
- package/out/coordinate-bounds.js.map +1 -0
- package/out/coordinate-formats.d.ts +8 -0
- package/out/coordinate-formats.d.ts.map +1 -1
- package/out/coordinate-formats.js +14 -3
- package/out/coordinate-formats.js.map +1 -1
- package/out/distance.d.ts +84 -0
- package/out/distance.d.ts.map +1 -0
- package/out/distance.js +132 -0
- package/out/distance.js.map +1 -0
- package/out/feature.d.ts +1 -1
- package/out/feature.d.ts.map +1 -1
- package/out/feature.js.map +1 -1
- package/out/geometries/collection.d.ts +4 -4
- package/out/geometries/collection.d.ts.map +1 -1
- package/out/geometries/collection.js.map +1 -1
- package/out/geometries/index.d.ts +5 -4
- package/out/geometries/index.d.ts.map +1 -1
- package/out/geometries/index.js +5 -4
- package/out/geometries/index.js.map +1 -1
- package/out/geometries/line-string.d.ts +2 -2
- package/out/geometries/line-string.d.ts.map +1 -1
- package/out/geometries/line-string.js.map +1 -1
- package/out/geometries/point.d.ts +9 -9
- package/out/geometries/point.d.ts.map +1 -1
- package/out/geometries/point.js +9 -9
- package/out/geometries/point.js.map +1 -1
- package/out/geometries/polygon.d.ts +60 -56
- package/out/geometries/polygon.d.ts.map +1 -1
- package/out/geometries/polygon.js +66 -63
- package/out/geometries/polygon.js.map +1 -1
- package/out/geometries/ring-blob.d.ts +183 -0
- package/out/geometries/ring-blob.d.ts.map +1 -0
- package/out/geometries/ring-blob.js +376 -0
- package/out/geometries/ring-blob.js.map +1 -0
- package/out/google/index.d.ts +1 -1
- package/out/google/index.d.ts.map +1 -1
- package/out/google/index.js +1 -1
- package/out/google/index.js.map +1 -1
- package/out/google/place-id.d.ts.map +1 -1
- package/out/google/place-id.js.map +1 -1
- package/out/h3/cell.d.ts +32 -0
- package/out/h3/cell.d.ts.map +1 -1
- package/out/h3/cell.js +68 -1
- package/out/h3/cell.js.map +1 -1
- package/out/h3/coverage.d.ts +32 -0
- package/out/h3/coverage.d.ts.map +1 -0
- package/out/h3/coverage.js +27 -0
- package/out/h3/coverage.js.map +1 -0
- package/out/h3/index.d.ts +5 -3
- package/out/h3/index.d.ts.map +1 -1
- package/out/h3/index.js +5 -3
- package/out/h3/index.js.map +1 -1
- package/out/h3/interior-cells.d.ts +54 -0
- package/out/h3/interior-cells.d.ts.map +1 -0
- package/out/h3/interior-cells.js +111 -0
- package/out/h3/interior-cells.js.map +1 -0
- package/out/h3/polygon-cells.d.ts +182 -0
- package/out/h3/polygon-cells.d.ts.map +1 -0
- package/out/h3/polygon-cells.js +339 -0
- package/out/h3/polygon-cells.js.map +1 -0
- package/out/index.d.ts +15 -12
- package/out/index.d.ts.map +1 -1
- package/out/index.js +15 -12
- package/out/index.js.map +1 -1
- package/out/objects.d.ts +1 -1
- package/out/objects.d.ts.map +1 -1
- package/out/objects.js +1 -1
- package/out/objects.js.map +1 -1
- package/out/open-location-code.d.ts +48 -0
- package/out/open-location-code.d.ts.map +1 -0
- package/out/open-location-code.js +137 -0
- package/out/open-location-code.js.map +1 -0
- package/out/osgb36.d.ts +2 -2
- package/out/osgb36.d.ts.map +1 -1
- package/out/osgb36.js +1 -1
- package/out/osgb36.js.map +1 -1
- package/out/polyline.d.ts.map +1 -1
- package/out/polyline.js +1 -1
- package/out/polyline.js.map +1 -1
- package/out/position.d.ts +4 -61
- package/out/position.d.ts.map +1 -1
- package/out/position.js +14 -126
- package/out/position.js.map +1 -1
- package/out/projection-transform.d.ts +67 -0
- package/out/projection-transform.d.ts.map +1 -0
- package/out/projection-transform.js +48 -0
- package/out/projection-transform.js.map +1 -0
- package/out/projection.d.ts.map +1 -1
- package/out/projection.js.map +1 -1
- package/out/regions/codes.d.ts.map +1 -1
- package/out/regions/codes.js.map +1 -1
- package/out/regions/index.d.ts +2 -2
- package/out/regions/index.d.ts.map +1 -1
- package/out/regions/index.js +2 -2
- package/out/regions/index.js.map +1 -1
- package/out/regions/names.d.ts.map +1 -1
- package/out/regions/names.js.map +1 -1
- package/out/tools/ogr-stream.d.ts +34 -0
- package/out/tools/ogr-stream.d.ts.map +1 -0
- package/out/tools/ogr-stream.js +74 -0
- package/out/tools/ogr-stream.js.map +1 -0
- package/out/tools/ogr.d.ts +87 -0
- package/out/tools/ogr.d.ts.map +1 -0
- package/out/tools/ogr.js +84 -0
- package/out/tools/ogr.js.map +1 -0
- package/out/tsconfig.test.tsbuildinfo +1 -1
- package/out/{sdk/well-known-text.d.ts → well-known-text.d.ts} +1 -1
- package/out/well-known-text.d.ts.map +1 -0
- package/out/well-known-text.js.map +1 -0
- package/package.json +143 -14
- package/geometries/index.ts +0 -12
- package/index.ts +0 -18
- package/out/sdk/index.d.ts +0 -7
- package/out/sdk/index.d.ts.map +0 -1
- package/out/sdk/index.js +0 -7
- package/out/sdk/index.js.map +0 -1
- package/out/sdk/well-known-text.d.ts.map +0 -1
- package/out/sdk/well-known-text.js.map +0 -1
- package/out/tsconfig.tsbuildinfo +0 -1
- package/position.ts +0 -345
- package/sdk/index.ts +0 -7
- /package/{google → lib/google}/place-id.ts +0 -0
- /package/{projection.ts → lib/projection.ts} +0 -0
- /package/{regions → lib/regions}/names.ts +0 -0
- /package/out/{sdk/well-known-text.js → well-known-text.js} +0 -0
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* The ring blob — how a polygon layer stores one authority feature's UNSIMPLIFIED coordinates, and the
|
|
7
|
+
* point test that reads it without materializing them.
|
|
8
|
+
*
|
|
9
|
+
* THE GEOMETRY IS THE TRUTH TABLE. An H3 index above it answers a cell that lies wholly inside one
|
|
10
|
+
* feature; a cell a boundary crosses falls through to a ray cast against the few features the index
|
|
11
|
+
* already named. A rooftop answer at a boundary — which is where the answer usually matters most — has
|
|
12
|
+
* no other source, so the rings are stored at the resolution the authority published them and never
|
|
13
|
+
* simplified.
|
|
14
|
+
*
|
|
15
|
+
* THE LAYOUT PUTS THE COORDINATES ON AN 8-BYTE BOUNDARY, so the reader takes a `Float64Array` view over
|
|
16
|
+
* them instead of a `DataView.getFloat64` per ordinate. Header is `u32 version`, `u32 ringCount`, then
|
|
17
|
+
* one `(u32 pointCount, u32 polygonIndex)` pair per ring — `8 + 8 × ringCount` bytes, a multiple of
|
|
18
|
+
* eight by construction. Coordinates follow as `[lon, lat]` pairs, ring by ring.
|
|
19
|
+
*
|
|
20
|
+
* `polygonIndex` IS required AND CANNOT BE INFERRED. A source feature is a MultiPolygon, so its
|
|
21
|
+
* rings belong to several polygons and "the first ring is the exterior" is true only per polygon. The
|
|
22
|
+
* point test is orientation-free and nesting-free (even-odd across a polygon's own rings, the rule
|
|
23
|
+
* {@link pointInPolygon} uses), but it still has to know which rings share a polygon: an island sitting
|
|
24
|
+
* inside another polygon's hole is inside the layer and would cancel to "outside" if every ring were
|
|
25
|
+
* pooled into one list.
|
|
26
|
+
*
|
|
27
|
+
* SHARED BY EVERY POLYGON LAYER RATHER THAN COPIED INTO EACH. `@mailwoman/flood` and `@mailwoman/soil`
|
|
28
|
+
* both store an authority's rings this way, and a second copy of the alignment arithmetic or of the
|
|
29
|
+
* signed-area reading would be a second thing to get right — both failure modes are silent, since a
|
|
30
|
+
* mis-read blob answers a containment question wrongly and a hole-blind area reading answers "inside"
|
|
31
|
+
* for every point in a hole.
|
|
32
|
+
*/
|
|
33
|
+
/**
|
|
34
|
+
* Format version stamped into every blob. A reader that meets a different number throws rather than reinterpreting
|
|
35
|
+
* bytes it does not know the shape of.
|
|
36
|
+
*/
|
|
37
|
+
export const RING_BLOB_VERSION = 1;
|
|
38
|
+
/**
|
|
39
|
+
* Bytes of fixed header before the per-ring table.
|
|
40
|
+
*/
|
|
41
|
+
const HEADER_BYTES = 8;
|
|
42
|
+
/**
|
|
43
|
+
* Bytes per ring-table entry: `u32 pointCount`, `u32 polygonIndex`.
|
|
44
|
+
*/
|
|
45
|
+
const RING_ENTRY_BYTES = 8;
|
|
46
|
+
/**
|
|
47
|
+
* Positions a linear ring needs to bound an area: three distinct vertices plus the repeat that closes it (RFC 7946
|
|
48
|
+
* §3.1.6). Fewer is a degenerate ring, and encoding one would store a polygon no point can be inside.
|
|
49
|
+
*/
|
|
50
|
+
const MINIMUM_RING_POSITIONS = 4;
|
|
51
|
+
/**
|
|
52
|
+
* Pack a GeoJSON `MultiPolygon`/`Polygon` coordinate tree into the stored blob.
|
|
53
|
+
*
|
|
54
|
+
* @throws {RangeError} When the geometry carries no ring, or a ring carries fewer than four positions (a linear ring is
|
|
55
|
+
* closed, so three is the minimum distinct-vertex count plus the repeat).
|
|
56
|
+
*/
|
|
57
|
+
export function encodeRings(polygons) {
|
|
58
|
+
const entries = [];
|
|
59
|
+
let totalPoints = 0;
|
|
60
|
+
for (const [polygonIndex, rings] of polygons.entries()) {
|
|
61
|
+
for (const ring of rings) {
|
|
62
|
+
if (ring.length < MINIMUM_RING_POSITIONS) {
|
|
63
|
+
throw new RangeError(`ring blob: a linear ring needs at least ${MINIMUM_RING_POSITIONS} positions, got ${ring.length}`);
|
|
64
|
+
}
|
|
65
|
+
entries.push({ pointCount: ring.length, polygonIndex });
|
|
66
|
+
totalPoints += ring.length;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (!entries.length) {
|
|
70
|
+
throw new RangeError("ring blob: geometry carries no ring");
|
|
71
|
+
}
|
|
72
|
+
const headerBytes = HEADER_BYTES + RING_ENTRY_BYTES * entries.length;
|
|
73
|
+
const buffer = new ArrayBuffer(headerBytes + totalPoints * 2 * Float64Array.BYTES_PER_ELEMENT);
|
|
74
|
+
const view = new DataView(buffer);
|
|
75
|
+
view.setUint32(0, RING_BLOB_VERSION, true);
|
|
76
|
+
view.setUint32(4, entries.length, true);
|
|
77
|
+
for (const [index, entry] of entries.entries()) {
|
|
78
|
+
view.setUint32(HEADER_BYTES + index * RING_ENTRY_BYTES, entry.pointCount, true);
|
|
79
|
+
view.setUint32(HEADER_BYTES + index * RING_ENTRY_BYTES + 4, entry.polygonIndex, true);
|
|
80
|
+
}
|
|
81
|
+
const coordinates = new Float64Array(buffer, headerBytes, totalPoints * 2);
|
|
82
|
+
let cursor = 0;
|
|
83
|
+
for (const rings of polygons) {
|
|
84
|
+
for (const ring of rings) {
|
|
85
|
+
for (const position of ring) {
|
|
86
|
+
coordinates[cursor++] = position[0];
|
|
87
|
+
coordinates[cursor++] = position[1];
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return new Uint8Array(buffer);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* The ring table plus a `Float64Array` over the coordinates — what both the point test and the decoder walk.
|
|
95
|
+
*
|
|
96
|
+
* @throws {Error} When the blob's version is not {@linkcode RING_BLOB_VERSION}, or its declared ring table does not
|
|
97
|
+
* account for the bytes present. A blob that is silently mis-read answers a containment question wrongly, and a wrong
|
|
98
|
+
* containment answer is indistinguishable from a real one.
|
|
99
|
+
*/
|
|
100
|
+
function openRings(blob) {
|
|
101
|
+
// `blob.byteOffset` is not always zero: node:sqlite hands back a view into a shared buffer.
|
|
102
|
+
const view = new DataView(blob.buffer, blob.byteOffset, blob.byteLength);
|
|
103
|
+
const version = view.getUint32(0, true);
|
|
104
|
+
if (version !== RING_BLOB_VERSION) {
|
|
105
|
+
throw new Error(`ring blob: blob version ${version}, expected ${RING_BLOB_VERSION}`);
|
|
106
|
+
}
|
|
107
|
+
const ringCount = view.getUint32(4, true);
|
|
108
|
+
const headerBytes = HEADER_BYTES + RING_ENTRY_BYTES * ringCount;
|
|
109
|
+
const pointCounts = new Uint32Array(ringCount);
|
|
110
|
+
const polygonIndices = new Uint32Array(ringCount);
|
|
111
|
+
let totalPoints = 0;
|
|
112
|
+
for (let index = 0; index < ringCount; index++) {
|
|
113
|
+
const pointCount = view.getUint32(HEADER_BYTES + index * RING_ENTRY_BYTES, true);
|
|
114
|
+
pointCounts[index] = pointCount;
|
|
115
|
+
polygonIndices[index] = view.getUint32(HEADER_BYTES + index * RING_ENTRY_BYTES + 4, true);
|
|
116
|
+
totalPoints += pointCount;
|
|
117
|
+
}
|
|
118
|
+
const expected = headerBytes + totalPoints * 2 * Float64Array.BYTES_PER_ELEMENT;
|
|
119
|
+
if (expected !== blob.byteLength) {
|
|
120
|
+
throw new Error(`ring blob: blob declares ${expected} bytes of geometry, holds ${blob.byteLength}`);
|
|
121
|
+
}
|
|
122
|
+
// The header is a multiple of eight by construction, so the coordinate run is 8-byte aligned and this view is legal
|
|
123
|
+
// on a shared buffer whose own offset is aligned. A misaligned source buffer is copied rather than rejected.
|
|
124
|
+
const absoluteOffset = blob.byteOffset + headerBytes;
|
|
125
|
+
const coordinates = absoluteOffset % Float64Array.BYTES_PER_ELEMENT === 0
|
|
126
|
+
? new Float64Array(blob.buffer, absoluteOffset, totalPoints * 2)
|
|
127
|
+
: new Float64Array(blob.slice(headerBytes).buffer, 0, totalPoints * 2);
|
|
128
|
+
return { ringCount, pointCounts, polygonIndices, coordinates };
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Is the point inside the stored geometry?
|
|
132
|
+
*
|
|
133
|
+
* Even-odd within each polygon's own ring list, inside-any-polygon across them — the orientation-free rule
|
|
134
|
+
* {@linkcode pointInPolygon} states, applied without allocating the ring arrays. Reading a hole as an exterior ring is
|
|
135
|
+
* what this rule survives: a point inside a hole crosses two rings and comes out even, whichever way either ring
|
|
136
|
+
* winds.
|
|
137
|
+
*/
|
|
138
|
+
export function pointInEncodedRings(blob, lon, lat) {
|
|
139
|
+
const { ringCount, pointCounts, polygonIndices, coordinates } = openRings(blob);
|
|
140
|
+
if (!ringCount)
|
|
141
|
+
return false;
|
|
142
|
+
let cursor = 0;
|
|
143
|
+
let polygon = polygonIndices[0];
|
|
144
|
+
let inside = false;
|
|
145
|
+
for (let index = 0; index < ringCount; index++) {
|
|
146
|
+
const pointCount = pointCounts[index];
|
|
147
|
+
if (polygonIndices[index] !== polygon) {
|
|
148
|
+
if (inside)
|
|
149
|
+
return true;
|
|
150
|
+
polygon = polygonIndices[index];
|
|
151
|
+
inside = false;
|
|
152
|
+
}
|
|
153
|
+
if (crossesOdd(coordinates, cursor, pointCount, lon, lat)) {
|
|
154
|
+
inside = !inside;
|
|
155
|
+
}
|
|
156
|
+
cursor += pointCount * 2;
|
|
157
|
+
}
|
|
158
|
+
return inside;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* The even-odd crossing count over one ring held in a flat coordinate run. Mirrors {@linkcode pointInRing} exactly —
|
|
162
|
+
* same predicate, same tie behavior — so a decoded ring and an encoded one never disagree.
|
|
163
|
+
*/
|
|
164
|
+
function crossesOdd(coordinates, offset, pointCount, lon, lat) {
|
|
165
|
+
let inside = false;
|
|
166
|
+
for (let i = 0, j = pointCount - 1; i < pointCount; j = i++) {
|
|
167
|
+
const xi = coordinates[offset + i * 2];
|
|
168
|
+
const yi = coordinates[offset + i * 2 + 1];
|
|
169
|
+
const xj = coordinates[offset + j * 2];
|
|
170
|
+
const yj = coordinates[offset + j * 2 + 1];
|
|
171
|
+
if (yi > lat !== yj > lat && lon < ((xj - xi) * (lat - yi)) / (yj - yi) + xi) {
|
|
172
|
+
inside = !inside;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return inside;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Unpack the blob back into per-polygon flat coordinate runs — for tests, for a debug render, and for the round-trip
|
|
179
|
+
* check a build's fixtures assert.
|
|
180
|
+
*/
|
|
181
|
+
export function decodeRings(blob) {
|
|
182
|
+
const { ringCount, pointCounts, polygonIndices, coordinates } = openRings(blob);
|
|
183
|
+
const polygons = [];
|
|
184
|
+
let cursor = 0;
|
|
185
|
+
for (let index = 0; index < ringCount; index++) {
|
|
186
|
+
const pointCount = pointCounts[index];
|
|
187
|
+
const polygonIndex = polygonIndices[index];
|
|
188
|
+
polygons[polygonIndex] ??= [];
|
|
189
|
+
polygons[polygonIndex].push([...coordinates.subarray(cursor, cursor + pointCount * 2)]);
|
|
190
|
+
cursor += pointCount * 2;
|
|
191
|
+
}
|
|
192
|
+
return { polygons };
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Mean Earth radius in metres — the sphere the ring areas below are measured on.
|
|
196
|
+
*/
|
|
197
|
+
const EARTH_RADIUS_M = 6_371_008.8;
|
|
198
|
+
/**
|
|
199
|
+
* Signed spherical area of one linear ring, in square metres. **CLOCKWISE is positive**, counter-clockwise negative.
|
|
200
|
+
*
|
|
201
|
+
* The sign is the whole point: an orientation-respecting sum over a polygon's rings subtracts its holes, while a sum of
|
|
202
|
+
* absolute values adds them. Comparing the two against the source's own area figure is what tells a builder whether it
|
|
203
|
+
* has read the holes at all — the failure mode is silent, because a hole read as an exterior ring produces a perfectly
|
|
204
|
+
* well-formed polygon that simply covers more ground than the authority mapped.
|
|
205
|
+
*
|
|
206
|
+
* WHICH WINDING IS POSITIVE IS A CONTRACT, NOT A DETAIL, because a builder whose source encodes hole roles by
|
|
207
|
+
* ORIENTATION reads roles off this sign. It is the opposite of the standard planar shoelace: this sum runs `(lonᵢ −
|
|
208
|
+
* lonⱼ)` against the shoelace's `(xⱼ − xᵢ)`, so a ring `@mailwoman/spatial`'s own {@link rectangleRing} builds
|
|
209
|
+
* counter-clockwise answers NEGATIVE here. `@mailwoman/zoning` is the caller that depends on it, and
|
|
210
|
+
* `packages/zoning/test/unit/ring-roles.test.ts` pins the sign directly.
|
|
211
|
+
*/
|
|
212
|
+
export function ringSignedAreaM2(ring) {
|
|
213
|
+
let total = 0;
|
|
214
|
+
for (let i = 0, j = ring.length - 1; i < ring.length; j = i++) {
|
|
215
|
+
const [lonI, latI] = ring[i];
|
|
216
|
+
const [lonJ, latJ] = ring[j];
|
|
217
|
+
total +=
|
|
218
|
+
(((lonI - lonJ) * Math.PI) / 180) * (2 + Math.sin((latJ * Math.PI) / 180) + Math.sin((latI * Math.PI) / 180));
|
|
219
|
+
}
|
|
220
|
+
return (total * EARTH_RADIUS_M * EARTH_RADIUS_M) / 2;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Both readings of one feature's area, in square metres: `nested` respects ring orientation (holes subtract) and
|
|
224
|
+
* `allExterior` does not (holes add).
|
|
225
|
+
*
|
|
226
|
+
* A source whose holes are correctly nested makes `nested` match the authority's own figure and `allExterior` exceed
|
|
227
|
+
* it. The gap between them is the area a hole-blind reader would answer "inside" for.
|
|
228
|
+
*/
|
|
229
|
+
export function ringAreaReadings(polygons) {
|
|
230
|
+
let nested = 0;
|
|
231
|
+
let allExterior = 0;
|
|
232
|
+
for (const rings of polygons) {
|
|
233
|
+
// Per POLYGON, not pooled: two disjoint polygons of one feature can wind opposite ways without either being a
|
|
234
|
+
// hole, and a pooled sum would silently cancel them against each other.
|
|
235
|
+
let signedTotal = 0;
|
|
236
|
+
for (const ring of rings) {
|
|
237
|
+
const signed = ringSignedAreaM2(ring);
|
|
238
|
+
signedTotal += signed;
|
|
239
|
+
allExterior += Math.abs(signed);
|
|
240
|
+
}
|
|
241
|
+
nested += Math.abs(signedTotal);
|
|
242
|
+
}
|
|
243
|
+
return { nested, allExterior };
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Refuse a feature whose reprojected vertices fall outside the publisher's own declared extent.
|
|
247
|
+
*
|
|
248
|
+
* THE CHECK A PROJECTION CHECK CANNOT MAKE. A swapped coordinate order survives an authority-code comparison — both
|
|
249
|
+
* axes are still numbers in a plausible range — and a source read in its own metres as if they were degrees produces
|
|
250
|
+
* perfectly well-formed coordinates in the wrong ocean. Both show up here on the first feature, before a whole layer is
|
|
251
|
+
* written to the wrong side of the planet.
|
|
252
|
+
*
|
|
253
|
+
* SHARED BY EVERY POLYGON INGEST, because it is rectangle arithmetic over the ring types and knows nothing about any
|
|
254
|
+
* product. `marginDegrees` is the caller's, because a declared extent is itself a rounded published value and how
|
|
255
|
+
* tightly a source hugs its own is a fact about that source.
|
|
256
|
+
*
|
|
257
|
+
* @param context Names the calling ingest in the refusal, so a build log says which layer stopped.
|
|
258
|
+
* @throws {RangeError} On the first vertex outside the extent.
|
|
259
|
+
*/
|
|
260
|
+
export function assertRingsInsideExtent(polygons, label, extent, marginDegrees, context = "polygon ingest") {
|
|
261
|
+
for (const rings of polygons) {
|
|
262
|
+
for (const ring of rings) {
|
|
263
|
+
for (const position of ring) {
|
|
264
|
+
const lon = position[0];
|
|
265
|
+
const lat = position[1];
|
|
266
|
+
if (lon < extent.minLon - marginDegrees ||
|
|
267
|
+
lon > extent.maxLon + marginDegrees ||
|
|
268
|
+
lat < extent.minLat - marginDegrees ||
|
|
269
|
+
lat > extent.maxLat + marginDegrees) {
|
|
270
|
+
throw new RangeError(`${context}: ${label} has a vertex at ${lon}, ${lat}, outside the declared extent ` +
|
|
271
|
+
`[${extent.minLon}, ${extent.minLat}, ${extent.maxLon}, ${extent.maxLat}] — the reprojection or the coordinate order is wrong`);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* A point INSIDE one stored polygon, for a verification sampler.
|
|
279
|
+
*
|
|
280
|
+
* The bounding-box centre is tried first; where it is not inside — a crescent, a band hugging a river, a polygon with a
|
|
281
|
+
* hole through its middle — a small deterministic grid over the box is scanned. A polygon no grid point lands inside is
|
|
282
|
+
* refused (`undefined`) rather than approximated, because a sample point that is not actually inside the polygon turns
|
|
283
|
+
* an agreement check into a check on the sampler.
|
|
284
|
+
*
|
|
285
|
+
* SHARED BY EVERY POLYGON LAYER'S VERIFY, because it is bounding-box arithmetic over the ring blob and knows nothing
|
|
286
|
+
* about any product. `gridSteps` is the one thing that differs between them: a layer whose polygons are narrow strips
|
|
287
|
+
* needs a finer grid than one whose polygons are compact, and the value is part of a layer's sampling receipt — two
|
|
288
|
+
* runs of the same layer must draw the same points, so it is a caller's choice rather than a shared default nobody
|
|
289
|
+
* owns.
|
|
290
|
+
*
|
|
291
|
+
* @param gridSteps Grid divisions per axis. Only `steps − 1` interior lines are tested, so 7 gives a 6 × 6 grid.
|
|
292
|
+
*/
|
|
293
|
+
export function interiorPointOfEncodedRings(area, gridSteps = 7) {
|
|
294
|
+
const centreLat = (area.min_lat + area.max_lat) / 2;
|
|
295
|
+
const centreLon = (area.min_lon + area.max_lon) / 2;
|
|
296
|
+
if (pointInEncodedRings(area.rings, centreLon, centreLat)) {
|
|
297
|
+
return { latitude: centreLat, longitude: centreLon };
|
|
298
|
+
}
|
|
299
|
+
for (let row = 1; row < gridSteps; row++) {
|
|
300
|
+
for (let column = 1; column < gridSteps; column++) {
|
|
301
|
+
const latitude = area.min_lat + ((area.max_lat - area.min_lat) * row) / gridSteps;
|
|
302
|
+
const longitude = area.min_lon + ((area.max_lon - area.min_lon) * column) / gridSteps;
|
|
303
|
+
if (pointInEncodedRings(area.rings, longitude, latitude))
|
|
304
|
+
return { latitude, longitude };
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
return undefined;
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Whether a stored polygon's precomputed bounding box contains the point — the ray cast's prefilter, so the blob is
|
|
311
|
+
* only pulled off disk for a polygon that could contain the point.
|
|
312
|
+
*/
|
|
313
|
+
export function bboxContains(bounds, longitude, latitude) {
|
|
314
|
+
return (longitude >= bounds.min_lon &&
|
|
315
|
+
longitude <= bounds.max_lon &&
|
|
316
|
+
latitude >= bounds.min_lat &&
|
|
317
|
+
latitude <= bounds.max_lat);
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* A reproducible sample of interior points drawn by a deterministic STRIDE over a key list — the shape every polygon
|
|
321
|
+
* layer's verification sampler shares.
|
|
322
|
+
*
|
|
323
|
+
* The keys are chosen before any geometry is read: selecting them alone is an index-only walk over the primary key, and
|
|
324
|
+
* the rows they name are then fetched by key. The draw is deterministic rather than random, so a re-run compares the
|
|
325
|
+
* same points and a disagreement can be looked at rather than re-rolled.
|
|
326
|
+
*
|
|
327
|
+
* @param options.gridSteps The interior-point search depth, per {@link interiorPointOfEncodedRings} — part of a layer's
|
|
328
|
+
* sampling receipt, so it is a caller's choice rather than a shared default nobody owns.
|
|
329
|
+
*/
|
|
330
|
+
export function strideSampleInteriorPoints(keys, count, options) {
|
|
331
|
+
const points = [];
|
|
332
|
+
if (!keys.length)
|
|
333
|
+
return points;
|
|
334
|
+
const stride = Math.max(1, Math.floor(keys.length / Math.max(1, count)));
|
|
335
|
+
for (let index = 0; index < keys.length && points.length < count; index += stride) {
|
|
336
|
+
const area = options.fetch(keys[index]);
|
|
337
|
+
if (!area)
|
|
338
|
+
continue;
|
|
339
|
+
const interior = interiorPointOfEncodedRings(area, options.gridSteps);
|
|
340
|
+
if (!interior)
|
|
341
|
+
continue;
|
|
342
|
+
points.push(options.toPoint(area, interior));
|
|
343
|
+
}
|
|
344
|
+
return points;
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* The bounding rectangle of one feature's rings, in degrees — a ray cast's prefilter, precomputed.
|
|
348
|
+
*/
|
|
349
|
+
export function ringsBoundingBox(polygons) {
|
|
350
|
+
let minLat = Infinity;
|
|
351
|
+
let minLon = Infinity;
|
|
352
|
+
let maxLat = -Infinity;
|
|
353
|
+
let maxLon = -Infinity;
|
|
354
|
+
for (const rings of polygons) {
|
|
355
|
+
for (const ring of rings) {
|
|
356
|
+
for (const position of ring) {
|
|
357
|
+
const lon = position[0];
|
|
358
|
+
const lat = position[1];
|
|
359
|
+
if (lon < minLon) {
|
|
360
|
+
minLon = lon;
|
|
361
|
+
}
|
|
362
|
+
if (lon > maxLon) {
|
|
363
|
+
maxLon = lon;
|
|
364
|
+
}
|
|
365
|
+
if (lat < minLat) {
|
|
366
|
+
minLat = lat;
|
|
367
|
+
}
|
|
368
|
+
if (lat > maxLat) {
|
|
369
|
+
maxLat = lat;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
return { minLat, minLon, maxLat, maxLon };
|
|
375
|
+
}
|
|
376
|
+
//# sourceMappingURL=ring-blob.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ring-blob.js","sourceRoot":"","sources":["../../lib/geometries/ring-blob.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;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cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/google/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,kBAAkB,CAAA"}
|
package/out/google/index.js
CHANGED
package/out/google/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../google/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/google/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,kBAAkB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"place-id.d.ts","sourceRoot":"","sources":["../../google/place-id.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAEvC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;AAE3D;;GAEG;AACH,eAAO,MAAM,uBAAuB,QAAqB,CAAA;AAEzD;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,aAAa,CAErE"}
|
|
1
|
+
{"version":3,"file":"place-id.d.ts","sourceRoot":"","sources":["../../lib/google/place-id.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAEvC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;AAE3D;;GAEG;AACH,eAAO,MAAM,uBAAuB,QAAqB,CAAA;AAEzD;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,aAAa,CAErE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"place-id.js","sourceRoot":"","sources":["../../google/place-id.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAuBH;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,kBAAkB,CAAA;AAEzD;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAC,KAAa;IAC5C,OAAO,uBAAuB,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAA;AACtD,CAAC"}
|
|
1
|
+
{"version":3,"file":"place-id.js","sourceRoot":"","sources":["../../lib/google/place-id.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAuBH;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,kBAAkB,CAAA;AAEzD;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAC,KAAa;IAC5C,OAAO,uBAAuB,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAA;AACtD,CAAC"}
|
package/out/h3/cell.d.ts
CHANGED
|
@@ -72,9 +72,41 @@ export declare function shortenH3Cell(cell: H3Cell): H3CellShort;
|
|
|
72
72
|
* @throws {Error} If the short cell and resolution do not together name a valid H3 cell.
|
|
73
73
|
*/
|
|
74
74
|
export declare function expandH3Cell(h3CellShort: H3CellShort, resolution?: number): H3Cell;
|
|
75
|
+
/**
|
|
76
|
+
* The full H3 index for a short cell held as an integer, stored at `resolution`.
|
|
77
|
+
*
|
|
78
|
+
* Through {@link expandH3Cell} rather than a string concatenation, because it VALIDATES: a short cell that does not name
|
|
79
|
+
* a valid cell at the stated resolution throws here instead of reaching `compactCells` as a plausible-looking index.
|
|
80
|
+
*/
|
|
81
|
+
export declare function expandShortCellInt(shortCell: number, resolution: number): H3Cell;
|
|
75
82
|
/**
|
|
76
83
|
* Pack an H3 cell into the short-cell integer used as a clustered B-tree key across layer databases (poi.db, bdc.db,
|
|
77
84
|
* address-id). 52 bits, so it stays inside `Number.MAX_SAFE_INTEGER` and SQLite's signed 64-bit integer column alike.
|
|
78
85
|
*/
|
|
79
86
|
export declare function shortCellToInt(cell: H3Cell): number;
|
|
87
|
+
/**
|
|
88
|
+
* The one resolution a set of stored short cells was captured at.
|
|
89
|
+
*
|
|
90
|
+
* A short cell drops the resolution nibble, so a table of them does not say what resolution it is keyed at — and every
|
|
91
|
+
* `layer_coverage` reader needs that number to derive a probe's coverage cell. It is recoverable because
|
|
92
|
+
* {@link expandH3Cell} validates: a short cell expands to a valid index at EXACTLY ONE resolution, so trying all
|
|
93
|
+
* sixteen and keeping the one that survives is an exact answer rather than an inference.
|
|
94
|
+
*
|
|
95
|
+
* SHARED RATHER THAN COPIED, because both failure modes it names are silent in a second copy. A table that mixes
|
|
96
|
+
* resolutions read at one of them reports every cell at the other as unsurveyed, and an empty table read as "resolution
|
|
97
|
+
* 0" puts every probe in the same cell. `packages/mailwoman/lib/observations/absence-route.ts` re-exports this under
|
|
98
|
+
* its own name; `@mailwoman/coastal` calls it directly.
|
|
99
|
+
*
|
|
100
|
+
* @param context Names the caller in both messages, so a failure says which reader refused.
|
|
101
|
+
* @throws {Error} When `cells` is empty, when a value is not a short cell, or when the set mixes resolutions.
|
|
102
|
+
*/
|
|
103
|
+
export declare function recoverShortCellResolution(cells: readonly number[], context?: string): number;
|
|
104
|
+
/**
|
|
105
|
+
* Reconstruct a short-cell int's ancestor at a coarser resolution WITHOUT going through a centroid.
|
|
106
|
+
*
|
|
107
|
+
* The centroid is the wrong input: re-deriving a parent from a stored cell's center can land in a different parent than
|
|
108
|
+
* the original cell belonged to (measured at ~6% of CONUS blocks between res 9 and res 6), so a coverage read and the
|
|
109
|
+
* build that wrote it disagree on a fraction of cells. Reconstructing from the stored cell itself is exact.
|
|
110
|
+
*/
|
|
111
|
+
export declare function shortCellToParentInt(shortCell: number, from: number, to: number): number;
|
|
80
112
|
//# sourceMappingURL=cell.d.ts.map
|
package/out/h3/cell.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cell.d.ts","sourceRoot":"","sources":["../../h3/cell.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAEvC;;GAEG;AACH,eAAO,MAAM,iBAAiB,KAAK,CAAA;AAEnC;;;;;;;;;;GAUG;AACH,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;AAE7C;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,MAAM,CAEvD;AAED;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;AAYvD;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAKvD;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,YAAY,CAAC,WAAW,EAAE,WAAW,EAAE,UAAU,SAAoB,GAAG,MAAM,CAsB7F;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEnD"}
|
|
1
|
+
{"version":3,"file":"cell.d.ts","sourceRoot":"","sources":["../../lib/h3/cell.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAEvC;;GAEG;AACH,eAAO,MAAM,iBAAiB,KAAK,CAAA;AAEnC;;;;;;;;;;GAUG;AACH,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;AAE7C;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,MAAM,CAEvD;AAED;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;AAYvD;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAKvD;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,YAAY,CAAC,WAAW,EAAE,WAAW,EAAE,UAAU,SAAoB,GAAG,MAAM,CAsB7F;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAEhF;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,OAAO,SAAmB,GAAG,MAAM,CA2CvG;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAExF"}
|
package/out/h3/cell.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* point-valued helpers there do. `geometries/point.ts` needs the primitives and is itself imported
|
|
9
9
|
* by `./index.ts`, so keeping them together closed an import cycle.
|
|
10
10
|
*/
|
|
11
|
-
import { isValidCell } from "h3-js";
|
|
11
|
+
import { cellToParent, isValidCell } from "h3-js";
|
|
12
12
|
/**
|
|
13
13
|
* The finest resolution H3 defines. Resolutions run `[0, H3_MAX_RESOLUTION]`.
|
|
14
14
|
*/
|
|
@@ -80,6 +80,15 @@ export function expandH3Cell(h3CellShort, resolution = H3_MAX_RESOLUTION) {
|
|
|
80
80
|
}
|
|
81
81
|
return cell;
|
|
82
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* The full H3 index for a short cell held as an integer, stored at `resolution`.
|
|
85
|
+
*
|
|
86
|
+
* Through {@link expandH3Cell} rather than a string concatenation, because it VALIDATES: a short cell that does not name
|
|
87
|
+
* a valid cell at the stated resolution throws here instead of reaching `compactCells` as a plausible-looking index.
|
|
88
|
+
*/
|
|
89
|
+
export function expandShortCellInt(shortCell, resolution) {
|
|
90
|
+
return expandH3Cell(shortCell.toString(16).padStart(SHORT_CELL_HEX_LENGTH, "0"), resolution);
|
|
91
|
+
}
|
|
83
92
|
/**
|
|
84
93
|
* Pack an H3 cell into the short-cell integer used as a clustered B-tree key across layer databases (poi.db, bdc.db,
|
|
85
94
|
* address-id). 52 bits, so it stays inside `Number.MAX_SAFE_INTEGER` and SQLite's signed 64-bit integer column alike.
|
|
@@ -87,4 +96,62 @@ export function expandH3Cell(h3CellShort, resolution = H3_MAX_RESOLUTION) {
|
|
|
87
96
|
export function shortCellToInt(cell) {
|
|
88
97
|
return Number(BigInt(`0x${shortenH3Cell(cell)}`));
|
|
89
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* The one resolution a set of stored short cells was captured at.
|
|
101
|
+
*
|
|
102
|
+
* A short cell drops the resolution nibble, so a table of them does not say what resolution it is keyed at — and every
|
|
103
|
+
* `layer_coverage` reader needs that number to derive a probe's coverage cell. It is recoverable because
|
|
104
|
+
* {@link expandH3Cell} validates: a short cell expands to a valid index at EXACTLY ONE resolution, so trying all
|
|
105
|
+
* sixteen and keeping the one that survives is an exact answer rather than an inference.
|
|
106
|
+
*
|
|
107
|
+
* SHARED RATHER THAN COPIED, because both failure modes it names are silent in a second copy. A table that mixes
|
|
108
|
+
* resolutions read at one of them reports every cell at the other as unsurveyed, and an empty table read as "resolution
|
|
109
|
+
* 0" puts every probe in the same cell. `packages/mailwoman/lib/observations/absence-route.ts` re-exports this under
|
|
110
|
+
* its own name; `@mailwoman/coastal` calls it directly.
|
|
111
|
+
*
|
|
112
|
+
* @param context Names the caller in both messages, so a failure says which reader refused.
|
|
113
|
+
* @throws {Error} When `cells` is empty, when a value is not a short cell, or when the set mixes resolutions.
|
|
114
|
+
*/
|
|
115
|
+
export function recoverShortCellResolution(cells, context = "layer coverage") {
|
|
116
|
+
if (!cells.length) {
|
|
117
|
+
throw new Error(`${context}: the coverage layer holds no cells — there is no resolution to recover`);
|
|
118
|
+
}
|
|
119
|
+
let recovered;
|
|
120
|
+
for (const cell of cells) {
|
|
121
|
+
const short = BigInt(cell).toString(16).padStart(SHORT_CELL_HEX_LENGTH, "0");
|
|
122
|
+
const valid = [];
|
|
123
|
+
for (let resolution = 0; resolution <= H3_MAX_RESOLUTION; resolution++) {
|
|
124
|
+
try {
|
|
125
|
+
expandH3Cell(short, resolution);
|
|
126
|
+
valid.push(resolution);
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
// A resolution the short cell does not expand at. Every cell expands at exactly one, so this is the
|
|
130
|
+
// ordinary case for fifteen of the sixteen probes.
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (valid.length !== 1) {
|
|
134
|
+
throw new Error(`${context}: coverage cell ${cell} expands at ${valid.length} resolutions (${valid.join(", ") || "none"}) — it is not a short H3 cell this layer can be probed by`);
|
|
135
|
+
}
|
|
136
|
+
const resolution = valid[0];
|
|
137
|
+
if (recovered === undefined) {
|
|
138
|
+
recovered = resolution;
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
if (recovered !== resolution) {
|
|
142
|
+
throw new Error(`${context}: the coverage table mixes resolutions (${recovered} and ${resolution}) — a single-resolution probe would read every cell at the other resolution as unsurveyed`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return recovered;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Reconstruct a short-cell int's ancestor at a coarser resolution WITHOUT going through a centroid.
|
|
149
|
+
*
|
|
150
|
+
* The centroid is the wrong input: re-deriving a parent from a stored cell's center can land in a different parent than
|
|
151
|
+
* the original cell belonged to (measured at ~6% of CONUS blocks between res 9 and res 6), so a coverage read and the
|
|
152
|
+
* build that wrote it disagree on a fraction of cells. Reconstructing from the stored cell itself is exact.
|
|
153
|
+
*/
|
|
154
|
+
export function shortCellToParentInt(shortCell, from, to) {
|
|
155
|
+
return shortCellToInt(cellToParent(expandShortCellInt(shortCell, from), to));
|
|
156
|
+
}
|
|
90
157
|
//# sourceMappingURL=cell.js.map
|
package/out/h3/cell.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cell.js","sourceRoot":"","sources":["../../h3/cell.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"cell.js","sourceRoot":"","sources":["../../lib/h3/cell.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,OAAO,CAAA;AAGjD;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,CAAA;AAenC;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAa;IACrC,OAAO,WAAW,CAAC,KAAK,CAAC,CAAA;AAC1B,CAAC;AAWD;;GAEG;AACH,MAAM,qBAAqB,GAAG,EAAE,CAAA;AAEhC;;GAEG;AACH,MAAM,eAAe,GAAG,gBAAsB,CAAA;AAE9C;;;;;;;;;;GAUG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY;IACzC,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC,CAAA;IACtC,MAAM,iBAAiB,GAAG,UAAU,GAAG,eAAe,CAAA;IAEtD,OAAO,iBAAiB,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,qBAAqB,EAAE,GAAG,CAAgB,CAAA;AAC1F,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,YAAY,CAAC,WAAwB,EAAE,UAAU,GAAG,iBAAiB;IACpF,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,UAAU,GAAG,CAAC,IAAI,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kBAAkB,CAAC,SAAS,EAAE,IAAI,CAAC,EAAE,EAAE,CAAW,CAAC,CAAA;AACvF,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software.
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* The coverage probe every polygon layer's reader repeats: an index cell's parent at the coverage
|
|
7
|
+
* resolution, read through the layer contract's shared row mapping.
|
|
8
|
+
*
|
|
9
|
+
* NOT exported from this package's main barrel on purpose — it reaches `@mailwoman/core/layers`, and the
|
|
10
|
+
* barrel serves browser bundles that must not carry the layer contract's Kysely graph. Import it from the
|
|
11
|
+
* `@mailwoman/spatial/h3/coverage` subpath.
|
|
12
|
+
*/
|
|
13
|
+
import { type CoverageCell } from "@mailwoman/core/layers";
|
|
14
|
+
import { type H3Cell } from "#h3/cell";
|
|
15
|
+
/**
|
|
16
|
+
* The one capability the probe needs of a prepared statement.
|
|
17
|
+
*/
|
|
18
|
+
export interface CoverageRowProbe {
|
|
19
|
+
get(shortCell: number): unknown;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The coverage row for `indexCell`'s parent at the coverage resolution, or `undefined` when the cell was never surveyed
|
|
23
|
+
* — which a caller must read as UNKNOWN, never as `{completeness: 0}`.
|
|
24
|
+
*
|
|
25
|
+
* The NULL-basis rule lives in the shared mapping: a NULL column is an artifact built before `basis` existed, and it
|
|
26
|
+
* was recording source presence — never a stronger basis than the builder actually had.
|
|
27
|
+
*/
|
|
28
|
+
export declare function readCoverageAt(select: CoverageRowProbe, indexCell: H3Cell, coverageResolution: number): (CoverageCell & {
|
|
29
|
+
h3CellIndex: string;
|
|
30
|
+
resolution: number;
|
|
31
|
+
}) | undefined;
|
|
32
|
+
//# sourceMappingURL=coverage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coverage.d.ts","sourceRoot":"","sources":["../../lib/h3/coverage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAkB,KAAK,YAAY,EAAoB,MAAM,wBAAwB,CAAA;AAG5F,OAAO,EAAkB,KAAK,MAAM,EAAE,MAAM,UAAU,CAAA;AAEtD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAChC,GAAG,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAA;CAC/B;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC7B,MAAM,EAAE,gBAAgB,EACxB,SAAS,EAAE,MAAM,EACjB,kBAAkB,EAAE,MAAM,GACxB,CAAC,YAAY,GAAG;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC,GAAG,SAAS,CAQ1E"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software.
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* The coverage probe every polygon layer's reader repeats: an index cell's parent at the coverage
|
|
7
|
+
* resolution, read through the layer contract's shared row mapping.
|
|
8
|
+
*
|
|
9
|
+
* NOT exported from this package's main barrel on purpose — it reaches `@mailwoman/core/layers`, and the
|
|
10
|
+
* barrel serves browser bundles that must not carry the layer contract's Kysely graph. Import it from the
|
|
11
|
+
* `@mailwoman/spatial/h3/coverage` subpath.
|
|
12
|
+
*/
|
|
13
|
+
import { toCoverageCell } from "@mailwoman/core/layers";
|
|
14
|
+
import { cellToParent } from "h3-js";
|
|
15
|
+
import { shortCellToInt } from "#h3/cell";
|
|
16
|
+
/**
|
|
17
|
+
* The coverage row for `indexCell`'s parent at the coverage resolution, or `undefined` when the cell was never surveyed
|
|
18
|
+
* — which a caller must read as UNKNOWN, never as `{completeness: 0}`.
|
|
19
|
+
*
|
|
20
|
+
* The NULL-basis rule lives in the shared mapping: a NULL column is an artifact built before `basis` existed, and it
|
|
21
|
+
* was recording source presence — never a stronger basis than the builder actually had.
|
|
22
|
+
*/
|
|
23
|
+
export function readCoverageAt(select, indexCell, coverageResolution) {
|
|
24
|
+
const coverageCell = cellToParent(indexCell, coverageResolution);
|
|
25
|
+
return toCoverageCell(select.get(shortCellToInt(coverageCell)), coverageCell, coverageResolution);
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=coverage.js.map
|