@mailwoman/zoning 10.0.0 → 10.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +169 -163
- package/lib/index.ts +103 -135
- package/lib/paths.ts +24 -0
- package/lib/ring-roles.ts +30 -71
- package/lib/rings.ts +2 -13
- package/lib/schema.ts +98 -139
- package/lib/vocabulary.ts +52 -130
- package/out/index.d.ts +81 -101
- package/out/index.d.ts.map +1 -1
- package/out/index.js +37 -96
- package/out/index.js.map +1 -1
- package/out/paths.d.ts +19 -0
- package/out/paths.d.ts.map +1 -0
- package/out/paths.js +21 -0
- package/out/paths.js.map +1 -0
- package/out/ring-roles.d.ts +16 -50
- package/out/ring-roles.d.ts.map +1 -1
- package/out/ring-roles.js +18 -51
- package/out/ring-roles.js.map +1 -1
- package/out/rings.d.ts +2 -13
- package/out/rings.d.ts.map +1 -1
- package/out/rings.js +2 -13
- package/out/rings.js.map +1 -1
- package/out/schema.d.ts +90 -132
- package/out/schema.d.ts.map +1 -1
- package/out/schema.js +17 -45
- package/out/schema.js.map +1 -1
- package/out/sdk/build-zoning.d.ts +58 -111
- package/out/sdk/build-zoning.d.ts.map +1 -1
- package/out/sdk/build-zoning.js +50 -139
- package/out/sdk/build-zoning.js.map +1 -1
- package/out/sdk/cells.d.ts +21 -62
- package/out/sdk/cells.d.ts.map +1 -1
- package/out/sdk/cells.js +15 -52
- package/out/sdk/cells.js.map +1 -1
- package/out/sdk/client.d.ts +23 -67
- package/out/sdk/client.d.ts.map +1 -1
- package/out/sdk/client.js +29 -77
- package/out/sdk/client.js.map +1 -1
- package/out/sdk/download.d.ts +7 -27
- package/out/sdk/download.d.ts.map +1 -1
- package/out/sdk/download.js +8 -28
- package/out/sdk/download.js.map +1 -1
- package/out/sdk/ingest/chunk.d.ts +19 -43
- package/out/sdk/ingest/chunk.d.ts.map +1 -1
- package/out/sdk/ingest/chunk.js +19 -52
- package/out/sdk/ingest/chunk.js.map +1 -1
- package/out/sdk/ingest/worker.d.ts +9 -0
- package/out/sdk/ingest/worker.d.ts.map +1 -0
- package/out/{scripts/ingest-chunk.js → sdk/ingest/worker.js} +8 -10
- package/out/sdk/ingest/worker.js.map +1 -0
- package/out/sdk/ingest.d.ts +152 -0
- package/out/sdk/ingest.d.ts.map +1 -0
- package/out/sdk/ingest.js +200 -0
- package/out/sdk/ingest.js.map +1 -0
- package/out/sdk/measure-resolutions.d.ts +7 -34
- package/out/sdk/measure-resolutions.d.ts.map +1 -1
- package/out/sdk/measure-resolutions.js +5 -23
- package/out/sdk/measure-resolutions.js.map +1 -1
- package/out/sdk/test-kit.d.ts +75 -0
- package/out/sdk/test-kit.d.ts.map +1 -0
- package/out/{test-kit.js → sdk/test-kit.js} +20 -43
- package/out/sdk/test-kit.js.map +1 -0
- package/out/sdk/verify.d.ts +79 -80
- package/out/sdk/verify.d.ts.map +1 -1
- package/out/sdk/verify.js +83 -70
- package/out/sdk/verify.js.map +1 -1
- package/out/vocabulary.d.ts +52 -120
- package/out/vocabulary.d.ts.map +1 -1
- package/out/vocabulary.js +47 -125
- package/out/vocabulary.js.map +1 -1
- package/package.json +38 -162
- package/{lib/sdk → sdk}/build-zoning.ts +102 -188
- package/{lib/sdk → sdk}/cells.ts +27 -66
- package/{lib/sdk → sdk}/client.ts +34 -82
- package/sdk/download.ts +58 -0
- package/{lib/sdk → sdk}/ingest/chunk.ts +36 -65
- package/{lib/scripts/ingest-chunk.ts → sdk/ingest/worker.ts} +7 -9
- package/sdk/ingest.ts +354 -0
- package/sdk/measure-resolutions.ts +72 -0
- package/{lib → sdk}/test-kit.ts +21 -44
- package/sdk/verify.ts +367 -0
- package/lib/sdk/download.ts +0 -78
- package/lib/sdk/index.ts +0 -15
- package/lib/sdk/ingest/index.ts +0 -393
- package/lib/sdk/measure-resolutions.ts +0 -101
- package/lib/sdk/verify.ts +0 -357
- package/out/scripts/ingest-chunk.d.ts +0 -11
- package/out/scripts/ingest-chunk.d.ts.map +0 -1
- package/out/scripts/ingest-chunk.js.map +0 -1
- package/out/sdk/index.d.ts +0 -15
- package/out/sdk/index.d.ts.map +0 -1
- package/out/sdk/index.js +0 -15
- package/out/sdk/index.js.map +0 -1
- package/out/sdk/ingest/index.d.ts +0 -185
- package/out/sdk/ingest/index.d.ts.map +0 -1
- package/out/sdk/ingest/index.js +0 -232
- package/out/sdk/ingest/index.js.map +0 -1
- package/out/test-kit.d.ts +0 -96
- package/out/test-kit.d.ts.map +0 -1
- package/out/test-kit.js.map +0 -1
|
@@ -3,43 +3,15 @@
|
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* THE COVERAGE IS `source_present` AND THE TIER IS `build-local`, AND THE TWO ARE INDEPENDENT REFUSALS.
|
|
9
|
-
* The coverage basis is about what the source can support: the Department publishes its coverage detail only
|
|
10
|
-
* inside a map viewer, so an absent zoning polygon is one of at least four different things and
|
|
11
|
-
* {@linkcode assertNoNegativeClaim} refuses anything stronger before a row is written. The tier is about
|
|
12
|
-
* what the LICENCE supports: three published statements disagree about the grant, so
|
|
13
|
-
* {@linkcode assertTierMatchesLicense} refuses a `shipped` build. Resolving either one does not resolve the
|
|
14
|
-
* other.
|
|
15
|
-
*
|
|
16
|
-
* THE AREA CHECK IS THE HOLE CHECK AND THE ONE THING HERE THAT IS EXACT. The service encodes hole
|
|
17
|
-
* roles by ring orientation, and reading them wrong is silent — a hole read as an exterior produces a
|
|
18
|
-
* well-formed polygon that answers "inside" for every location the plan carved out. Measured over the whole
|
|
19
|
-
* national export: the rings read WITH their holes total 5,444.5 km² and the Department's own `Shape__Area`
|
|
20
|
-
* sums to 5,444.5 km²; the same rings read WITHOUT their holes total 5,666.6 km². The publisher's figure has
|
|
21
|
-
* to come from the live service, because the bulk export drops the column — which is what makes this a
|
|
22
|
-
* two-path check rather than the archive agreeing with itself.
|
|
23
|
-
*
|
|
24
|
-
* THERE IS NO BUILD-TIME TOUCH TABLE. A zoning cell row names ONE POLYGON, so it is final the moment that
|
|
25
|
-
* polygon is classified. The rows go straight in, and memory stays flat in row count with nothing to resolve
|
|
26
|
-
* afterwards.
|
|
27
|
-
*
|
|
28
|
-
* THE INGEST IS BOUNDED ANYWAY. h3's WASM heap cannot be reset from JavaScript and does not survive an
|
|
29
|
-
* unbounded number of polyfill calls; a sibling product died twice on that, after roughly 510,000 and
|
|
30
|
-
* 798,000 features. This product holds 85,330, so the whole country fits inside the 100,000-id default with
|
|
31
|
-
* room to spare — and the bound still ships, because a build that stays inside a ceiling by luck is not the
|
|
32
|
-
* same fact as one that cannot cross it.
|
|
33
|
-
*
|
|
34
|
-
* THE JURISDICTION, PLAN AND VOCABULARY ROWS ARE WRITTEN BY THE PARENT, once, from the merged chunk
|
|
35
|
-
* reports. They are the only tables whose rows are partials across chunks — an authority and a plan appear
|
|
36
|
-
* in every chunk that touches them — and merging them in the parent is what keeps the chunk append-only.
|
|
6
|
+
* Build `zoning-ireland.db`, the sealed two-tier polygon layer. Its coverage basis and license tier can each refuse publication.
|
|
37
7
|
*/
|
|
38
8
|
|
|
39
|
-
import { readFileSize } from "@mailwoman/core/fs/readers"
|
|
9
|
+
import { readFileSize } from "@mailwoman/core/fs/readers/stat"
|
|
10
|
+
import { stringifyJSON } from "@mailwoman/core/json"
|
|
40
11
|
import {
|
|
41
12
|
areaAgreementFrom,
|
|
42
13
|
assertNoNegativeClaim as assertCoverageNoNegativeClaim,
|
|
14
|
+
assertTierMatchesLicense,
|
|
43
15
|
createLayerCoverageTable,
|
|
44
16
|
createLayerManifestTable,
|
|
45
17
|
LayerTier,
|
|
@@ -55,14 +27,14 @@ import { ingestChunkArguments, mergeCountsInto, runChunkProcess } from "@mailwom
|
|
|
55
27
|
import { CoverageBasis } from "@mailwoman/evidence"
|
|
56
28
|
import { M2_PER_KM2 } from "@mailwoman/spatial"
|
|
57
29
|
import type { DatabaseClient } from "@mailwoman/sqlite/client"
|
|
58
|
-
import { buildSealedArtifact } from "@mailwoman/sqlite/sealed
|
|
30
|
+
import { buildSealedArtifact } from "@mailwoman/sqlite/sealed/build"
|
|
31
|
+
import type { PathBuilderLike } from "path-ts"
|
|
59
32
|
|
|
60
33
|
import { createZoningTables, type ZoningDatabase } from "#schema"
|
|
34
|
+
import type { ZoningFeatureSource } from "#sdk/ingest"
|
|
61
35
|
import type { CrosswalkPair, ObservedTerm, ZoningChunkResult } from "#sdk/ingest/chunk"
|
|
62
36
|
import { ingestZoningChunk } from "#sdk/ingest/chunk"
|
|
63
|
-
import type { ZoningFeatureSource } from "#sdk/ingest/index"
|
|
64
37
|
import {
|
|
65
|
-
assertTierMatchesLicense,
|
|
66
38
|
GZT_ATTRIBUTION,
|
|
67
39
|
GZT_COVERAGE_LIMIT,
|
|
68
40
|
GZT_CROSSWALK_SCHEME,
|
|
@@ -71,11 +43,13 @@ import {
|
|
|
71
43
|
GZT_ITEM_ID,
|
|
72
44
|
GZT_LAYER_NAME,
|
|
73
45
|
GZT_LICENSE,
|
|
46
|
+
GZT_LICENSE_CONTRADICTION,
|
|
74
47
|
GZT_PLAN_LEVELS,
|
|
75
48
|
} from "#vocabulary"
|
|
49
|
+
|
|
76
50
|
/**
|
|
77
|
-
* Schema version of the domain tables
|
|
78
|
-
* ignore.
|
|
51
|
+
* Schema version of the domain tables, bumped when a column changes meaning
|
|
52
|
+
* rather than for an added column a reader can ignore.
|
|
79
53
|
*/
|
|
80
54
|
export const ZONING_SCHEMA_VERSION = 1
|
|
81
55
|
|
|
@@ -85,51 +59,43 @@ export const ZONING_SCHEMA_VERSION = 1
|
|
|
85
59
|
export const PLAN_LEVEL_SCHEME = "IE-PLAN-LEVEL"
|
|
86
60
|
|
|
87
61
|
/**
|
|
88
|
-
* Feature ids per chunk process
|
|
89
|
-
*
|
|
90
|
-
* Sized against the measured ceiling on a sibling product rather than guessed: single-process runs over that layer died
|
|
91
|
-
* after roughly 510,000 and 798,000 features as h3's WASM heap fragmented. This product holds 85,330 features, so this
|
|
92
|
-
* default puts the whole country in one process — and it is the ceiling that makes the build reproducible rather than
|
|
93
|
-
* the fact that this product happens to sit below it.
|
|
94
|
-
*
|
|
95
|
-
* A SMALLER CHUNK COSTS A FULL PASS EACH. The source is one 247 MB GeoJSON document rather than an indexed store, so
|
|
96
|
-
* ogr2ogr scans all of it per range: measured at 13.2 s per pass on this lab.
|
|
62
|
+
* Feature ids per chunk process, bounded at 100,000 because h3's wasm heap cannot be
|
|
63
|
+
* reset from JavaScript and does not survive an unbounded number of polyfill calls.
|
|
97
64
|
*/
|
|
98
65
|
export const DEFAULT_CHUNK_SIZE = 100_000
|
|
99
66
|
|
|
100
67
|
/**
|
|
101
|
-
* Where a build gets its features
|
|
68
|
+
* Where a build gets its features.
|
|
69
|
+
* A real build also bounds each process's share of them.
|
|
102
70
|
*/
|
|
103
71
|
export type BuildZoningInput =
|
|
104
72
|
| {
|
|
105
73
|
/**
|
|
106
|
-
* A feature source consumed
|
|
107
|
-
*
|
|
74
|
+
* A feature source consumed in this process.
|
|
75
|
+
* It is the per-chunk fallback of the batched form.
|
|
108
76
|
*/
|
|
109
77
|
source: ZoningFeatureSource
|
|
110
78
|
}
|
|
111
79
|
| {
|
|
112
80
|
/**
|
|
113
|
-
* The bulk export, ingested in bounded chunks — one child process per range
|
|
81
|
+
* The bulk export, ingested in bounded chunks — one child process per range
|
|
82
|
+
* of the authority's own feature ids.
|
|
114
83
|
*/
|
|
115
84
|
batched: {
|
|
116
85
|
exportPath: string
|
|
117
|
-
|
|
118
|
-
* Feature ids per chunk. See {@link DEFAULT_CHUNK_SIZE}.
|
|
119
|
-
*/
|
|
86
|
+
|
|
120
87
|
chunkSize?: number
|
|
121
|
-
|
|
122
|
-
* The feature count the whole build should yield.
|
|
123
|
-
*/
|
|
88
|
+
|
|
124
89
|
declaredFeatureCount: number
|
|
125
90
|
}
|
|
126
91
|
}
|
|
127
92
|
|
|
128
93
|
export type BuildZoningOptions = BuildZoningInput & {
|
|
129
94
|
/**
|
|
130
|
-
* Where the sealed artifact lands.
|
|
95
|
+
* Where the sealed artifact lands.
|
|
96
|
+
* The build writes beside it and swaps.
|
|
131
97
|
*/
|
|
132
|
-
out:
|
|
98
|
+
out: PathBuilderLike
|
|
133
99
|
/**
|
|
134
100
|
* The product vintage — `layer_manifest.version` and `source_vintage`.
|
|
135
101
|
*/
|
|
@@ -137,30 +103,34 @@ export type BuildZoningOptions = BuildZoningInput & {
|
|
|
137
103
|
buildCmd: string
|
|
138
104
|
buildSHA: string
|
|
139
105
|
/**
|
|
140
|
-
* ISO-8601, supplied by the caller
|
|
141
|
-
* makes two builds of the same inputs differ.
|
|
106
|
+
* ISO-8601, supplied by the caller so two builds of the same inputs do not differ.
|
|
142
107
|
*/
|
|
143
108
|
createdAt: string
|
|
144
109
|
/**
|
|
145
|
-
* The resolution the cell index is built at — chosen from the candidates-per-cell
|
|
110
|
+
* The resolution the cell index is built at — chosen from the candidates-per-cell
|
|
111
|
+
* and zero-cell measurement.
|
|
146
112
|
*/
|
|
147
113
|
indexResolution: number
|
|
148
114
|
/**
|
|
149
|
-
* The resolution `layer_coverage`
|
|
115
|
+
* The resolution used for `layer_coverage` row keys.
|
|
116
|
+
* It must be coarser than the index resolution.
|
|
150
117
|
*/
|
|
151
118
|
coverageResolution: number
|
|
152
119
|
/**
|
|
153
|
-
* The publisher's
|
|
154
|
-
*
|
|
120
|
+
* The publisher's own `Shape__Area` sum in square meters, read from the live service.
|
|
121
|
+
*
|
|
122
|
+
* When supplied, the build asserts that its encoded rings agree with this value.
|
|
155
123
|
*/
|
|
156
124
|
expectedSourceAreaM2?: number
|
|
157
125
|
/**
|
|
158
|
-
* The feature count the live service reports.
|
|
126
|
+
* The feature count the live service reports.
|
|
127
|
+
*
|
|
128
|
+
* When supplied, the build asserts its streamed total against this value.
|
|
159
129
|
*/
|
|
160
130
|
expectedFeatureCount?: number
|
|
161
131
|
/**
|
|
162
|
-
* The tier to stamp
|
|
163
|
-
* {@link assertTierMatchesLicense}.
|
|
132
|
+
* The tier to stamp, `build-local` unless the license contradiction is resolved —
|
|
133
|
+
* see {@link assertTierMatchesLicense}.
|
|
164
134
|
*/
|
|
165
135
|
tier?: LayerTier
|
|
166
136
|
onProgress?: (message: string) => void
|
|
@@ -176,27 +146,29 @@ export interface BuildZoningResult {
|
|
|
176
146
|
wholeCellRows: number
|
|
177
147
|
partialCellRows: number
|
|
178
148
|
/**
|
|
179
|
-
*
|
|
180
|
-
*
|
|
149
|
+
* The partial share over the stored rows.
|
|
150
|
+
*
|
|
151
|
+
* This differs from the share used to choose the resolution because the whole
|
|
152
|
+
* side is compacted per feature.
|
|
181
153
|
*/
|
|
182
154
|
storedPartialShare: number
|
|
183
155
|
/**
|
|
184
|
-
* Features
|
|
185
|
-
* rows are actually at
|
|
186
|
-
* at the wrong one and read every coarsened feature as an absence.
|
|
156
|
+
* Features forced coarser than `indexResolution`, and the resolutions the stored
|
|
157
|
+
* cell rows are actually at, reported rather than smoothed over.
|
|
187
158
|
*/
|
|
188
159
|
coarsenedFeatures: number
|
|
189
160
|
storedResolutions: number[]
|
|
190
161
|
coverageCells: number
|
|
191
162
|
/**
|
|
192
|
-
* The basis every coverage row
|
|
163
|
+
* The basis stored in every coverage row, `source_present` while `zoning_mapped_extent` is empty.
|
|
193
164
|
*/
|
|
194
165
|
coverageBasis: CoverageBasis
|
|
195
166
|
tier: LayerTier
|
|
196
167
|
license: string
|
|
197
168
|
/**
|
|
198
|
-
* The ring-role census
|
|
199
|
-
*
|
|
169
|
+
* The ring-role census records the total rings and the exteriors and holes inferred from orientation.
|
|
170
|
+
*
|
|
171
|
+
* It also counts holes placed on their parent's boundary rather than inside it.
|
|
200
172
|
*/
|
|
201
173
|
rings: {
|
|
202
174
|
total: number
|
|
@@ -205,67 +177,58 @@ export interface BuildZoningResult {
|
|
|
205
177
|
nestedHoles: number
|
|
206
178
|
adjacentHoles: number
|
|
207
179
|
/**
|
|
208
|
-
* Features whose exterior was chosen by
|
|
209
|
-
*
|
|
210
|
-
* than something the publisher stated. Reported rather than implied to be zero.
|
|
180
|
+
* Features whose exterior was chosen by magnitude because no ring read as one
|
|
181
|
+
* by orientation, reported rather than implied to be zero.
|
|
211
182
|
*/
|
|
212
183
|
exteriorByMagnitude: number
|
|
213
184
|
}
|
|
214
185
|
/**
|
|
215
|
-
* The area totals in square
|
|
216
|
-
*
|
|
217
|
-
* publisher's figure is never defaulted to this build's own reading: a receipt printing "publisher 205.4 km², 0.000%
|
|
218
|
-
* apart" when nobody asked the publisher is a check reporting itself as passed.
|
|
186
|
+
* The area totals in square kilometers with the witness stated, never defaulting
|
|
187
|
+
* the publisher's figure to this build's own reading.
|
|
219
188
|
*/
|
|
220
189
|
area: AreaAgreementReading & { signedKM2: number }
|
|
221
190
|
/**
|
|
222
|
-
* The vocabulary census, per scheme: how many codes the artifact holds
|
|
223
|
-
* declared.
|
|
191
|
+
* The vocabulary census, per scheme: how many codes the artifact holds
|
|
192
|
+
* and how many of them the publisher never declared.
|
|
224
193
|
*/
|
|
225
194
|
vocabulary: Array<{ scheme: string; codes: number; undeclared: number; undeclaredCodes: string[] }>
|
|
226
195
|
/**
|
|
227
|
-
* (authority, local code) pairs
|
|
228
|
-
* `zoning_crosswalk_edge` empty.
|
|
196
|
+
* (authority, local code) pairs and how many take more than one generic type,
|
|
197
|
+
* the measurement that keeps `zoning_crosswalk_edge` empty.
|
|
229
198
|
*/
|
|
230
199
|
crosswalk: {
|
|
231
200
|
pairs: number
|
|
232
201
|
nonFunctionalPairs: number
|
|
233
|
-
|
|
234
|
-
* The worst offenders, most generic types first, for the receipt.
|
|
235
|
-
*/
|
|
202
|
+
|
|
236
203
|
worst: Array<{ authorityCode: string; localCode: string; crosswalkCodes: string[] }>
|
|
237
204
|
}
|
|
238
205
|
sizeBytes: number
|
|
239
206
|
}
|
|
240
207
|
|
|
241
208
|
/**
|
|
242
|
-
* The relative gap between the two area readings that fails the build
|
|
243
|
-
*
|
|
244
|
-
* The comparison is a SPHERICAL ring area against the publisher's PLANAR figure in Irish Transverse Mercator, so the
|
|
245
|
-
* two never agree exactly: ITM's scale factor runs 0.99982 at its central meridian and above 1 towards the edges of the
|
|
246
|
-
* island, which contributes a few tenths of a percent to an area, and the spherical approximation contributes a similar
|
|
247
|
-
* amount against the ellipsoid. Measured on the largest feature in the country: 2,223.1 km² spherical against the
|
|
248
|
-
* Department's 2,232.1 km², 0.40% apart. One percent leaves that comfortably inside the tolerance while sitting well
|
|
249
|
-
* below the 4.1% a hole-blind read produces over the same set.
|
|
209
|
+
* The relative gap between the two area readings that fails the build,
|
|
210
|
+
* set below the 4.1% a hole-blind read produces.
|
|
250
211
|
*/
|
|
251
212
|
const AREA_TOLERANCE = 0.01
|
|
252
213
|
|
|
253
|
-
/**
|
|
254
|
-
* How many non-functional crosswalk pairs the receipt names.
|
|
255
|
-
*/
|
|
256
214
|
const WORST_PAIRS_REPORTED = 8
|
|
257
215
|
|
|
258
216
|
/**
|
|
259
217
|
* Build the layer.
|
|
260
218
|
*
|
|
261
|
-
* @throws {Error} On a feature that reaches no cell, a feature count that disagrees
|
|
262
|
-
*
|
|
263
|
-
*
|
|
219
|
+
* @throws {Error} On a feature that reaches no cell, a feature count that disagrees
|
|
220
|
+
* with the source's own declaration, an area total that disagrees with the publisher's,
|
|
221
|
+
* a coverage row that would license a negative claim, a crosswalk edge table written while
|
|
222
|
+
* the mapping is not a function, or a `shipped` tier asked for under an unresolved license.
|
|
264
223
|
*/
|
|
265
224
|
export async function buildZoningDatabase(options: BuildZoningOptions): Promise<BuildZoningResult> {
|
|
266
225
|
const tier = options.tier ?? LayerTier.BuildLocal
|
|
267
226
|
|
|
268
|
-
assertTierMatchesLicense(
|
|
227
|
+
assertTierMatchesLicense(
|
|
228
|
+
{ tier, license: GZT_LICENSE },
|
|
229
|
+
"zoning build",
|
|
230
|
+
`${GZT_LICENSE_CONTRADICTION} Resolve the grant in writing first, then change the tier.`
|
|
231
|
+
)
|
|
269
232
|
|
|
270
233
|
if (options.coverageResolution >= options.indexResolution) {
|
|
271
234
|
throw new Error(
|
|
@@ -291,7 +254,7 @@ export async function buildZoningDatabase(options: BuildZoningOptions): Promise<
|
|
|
291
254
|
await createLayerCoverageTable(kdb)
|
|
292
255
|
},
|
|
293
256
|
ingest: async (kdb) => {
|
|
294
|
-
if (!source) return
|
|
257
|
+
if (!source) return null
|
|
295
258
|
|
|
296
259
|
return aggregateChunks([
|
|
297
260
|
await ingestZoningChunk(kdb, {
|
|
@@ -309,10 +272,6 @@ export async function buildZoningDatabase(options: BuildZoningOptions): Promise<
|
|
|
309
272
|
return { ...built, sizeBytes: await readFileSize(options.out) }
|
|
310
273
|
}
|
|
311
274
|
|
|
312
|
-
/**
|
|
313
|
-
* The post-ingest half of the build, under the second handle: the assertions over what was streamed, then every
|
|
314
|
-
* artifact table beyond the truth tables.
|
|
315
|
-
*/
|
|
316
275
|
async function buildZoningResult(
|
|
317
276
|
kdb: DatabaseClient<ZoningDatabase>,
|
|
318
277
|
options: BuildZoningOptions,
|
|
@@ -334,8 +293,7 @@ async function buildZoningResult(
|
|
|
334
293
|
|
|
335
294
|
const area = assertAreaAgreement(ingested, options.expectedSourceAreaM2)
|
|
336
295
|
|
|
337
|
-
//
|
|
338
|
-
// happens not to be a function would be an accident; refusing to write them while it is not is a statement.
|
|
296
|
+
// The crosswalk is not a table: the build checks it rather than assuming it.
|
|
339
297
|
const nonFunctional = nonFunctionalPairs(ingested.crosswalkPairs)
|
|
340
298
|
|
|
341
299
|
assertCrosswalkIsNotATable(ingested.crosswalkPairs, 0)
|
|
@@ -375,15 +333,13 @@ async function buildZoningResult(
|
|
|
375
333
|
}>
|
|
376
334
|
).map((row) => row.resolution)
|
|
377
335
|
|
|
378
|
-
//
|
|
379
|
-
//
|
|
380
|
-
//
|
|
381
|
-
// carries the primary key in every entry, so it would roughly double the cell tier to serve a scan that is already
|
|
382
|
-
// short.
|
|
336
|
+
// Both probes this artifact serves already use primary keys, so it needs no secondary indexes.
|
|
337
|
+
// An index over a `without rowid` table would roughly double the cell tier
|
|
338
|
+
// to serve a scan that is already short.
|
|
383
339
|
const totalCellRows = ingested.wholeCellRows + ingested.partialCellRows
|
|
384
340
|
|
|
385
341
|
return {
|
|
386
|
-
out: options.out,
|
|
342
|
+
out: options.out.toString(),
|
|
387
343
|
features: ingested.features,
|
|
388
344
|
jurisdictions: ingested.jurisdictions.length,
|
|
389
345
|
plans: ingested.plans.length,
|
|
@@ -412,9 +368,6 @@ async function buildZoningResult(
|
|
|
412
368
|
}
|
|
413
369
|
}
|
|
414
370
|
|
|
415
|
-
/**
|
|
416
|
-
* What the whole ingest produced, however many processes it took.
|
|
417
|
-
*/
|
|
418
371
|
interface StreamResult {
|
|
419
372
|
features: number
|
|
420
373
|
coarsened: number
|
|
@@ -429,9 +382,8 @@ interface StreamResult {
|
|
|
429
382
|
nestedHoles: number
|
|
430
383
|
adjacentHoles: number
|
|
431
384
|
/**
|
|
432
|
-
* Features whose exterior was chosen by
|
|
433
|
-
*
|
|
434
|
-
* than something the publisher stated. Reported rather than implied to be zero.
|
|
385
|
+
* Features whose exterior was chosen by magnitude because no ring read as one
|
|
386
|
+
* by orientation, reported rather than implied to be zero.
|
|
435
387
|
*/
|
|
436
388
|
exteriorByMagnitude: number
|
|
437
389
|
}
|
|
@@ -442,11 +394,7 @@ interface StreamResult {
|
|
|
442
394
|
}
|
|
443
395
|
|
|
444
396
|
/**
|
|
445
|
-
* Add up what the chunks reported.
|
|
446
|
-
*
|
|
447
|
-
* Exported for its own test: the coverage-cell arithmetic and the crosswalk-pair merge are the parts of the batched
|
|
448
|
-
* path a fixture build cannot reach, and getting either wrong produces a well-formed artifact — one that under-reports
|
|
449
|
-
* how many polygons a cell holds, or one that reports a mapping as a function because no single chunk saw it break.
|
|
397
|
+
* Add up what the chunks reported, exported for its own test.
|
|
450
398
|
*/
|
|
451
399
|
export function aggregateChunks(chunks: ReadonlyArray<ZoningChunkResult>): StreamResult {
|
|
452
400
|
const observedByCoverageCell = new Map<number, number>()
|
|
@@ -485,8 +433,7 @@ export function aggregateChunks(chunks: ReadonlyArray<ZoningChunkResult>): Strea
|
|
|
485
433
|
adjacentHoles += chunk.rings.adjacentHoles
|
|
486
434
|
exteriorByMagnitude += chunk.rings.exteriorByMagnitude
|
|
487
435
|
|
|
488
|
-
// A coverage cell straddles chunk boundaries, so
|
|
489
|
-
// would report a cell as holding only the last chunk's polygons.
|
|
436
|
+
// A coverage cell straddles chunk boundaries, so counts add rather than replace.
|
|
490
437
|
mergeCountsInto(observedByCoverageCell, chunk.observedByCoverageCell)
|
|
491
438
|
|
|
492
439
|
for (const [code, name] of chunk.jurisdictions) {
|
|
@@ -506,9 +453,7 @@ export function aggregateChunks(chunks: ReadonlyArray<ZoningChunkResult>): Strea
|
|
|
506
453
|
vocabulary.set(key, existing ? [scheme, code, existing[2], existing[3] + rows] : [scheme, code, label, rows])
|
|
507
454
|
}
|
|
508
455
|
|
|
509
|
-
//
|
|
510
|
-
// like one inside any single chunk: Cork's `Special Policy Area` takes 14 generic types across the county, and a
|
|
511
|
-
// chunk holding a prefix of its feature ids may well have seen only one of them.
|
|
456
|
+
// The pairs merge as a union, because a mapping that is not a function can look like one inside any single chunk.
|
|
512
457
|
for (const [authorityCode, localCode, codes] of chunk.crosswalkPairs) {
|
|
513
458
|
const key = `${authorityCode}\u0000${localCode}`
|
|
514
459
|
const existing = crosswalkPairs.get(key)
|
|
@@ -552,12 +497,8 @@ export function nonFunctionalPairs(pairs: ReadonlyArray<CrosswalkPair>): Crosswa
|
|
|
552
497
|
}
|
|
553
498
|
|
|
554
499
|
/**
|
|
555
|
-
* Refuse a crosswalk
|
|
556
|
-
*
|
|
557
|
-
* An edge table asserts that a code determines a type. Measured nationally, 52 of 795 pairs take more than one — Cork
|
|
558
|
-
* County Council's `Special Policy Area` takes 14 — so an edge table built from this data would have to pick one type
|
|
559
|
-
* per pair and would be this package's invention rather than the Department's mapping. The mapping lives per polygon,
|
|
560
|
-
* on `zoning_area`, where the Department put it.
|
|
500
|
+
* Refuse a crosswalk edge table while the publisher's mapping is not a function
|
|
501
|
+
* of the (authority, code) pair.
|
|
561
502
|
*
|
|
562
503
|
* @throws {Error} When edges would be written while any pair is non-functional.
|
|
563
504
|
*/
|
|
@@ -572,30 +513,23 @@ export function assertCrosswalkIsNotATable(pairs: ReadonlyArray<CrosswalkPair>,
|
|
|
572
513
|
|
|
573
514
|
throw new Error(
|
|
574
515
|
`zoning build: ${edgeCount} crosswalk edge(s) would be written while ${broken.length} of ${pairs.length} ` +
|
|
575
|
-
`(authority, local code) pairs take more than one generic type — ${worst[0]} ${
|
|
516
|
+
`(authority, local code) pairs take more than one generic type — ${worst[0]} ${stringifyJSON(worst[1])} takes ` +
|
|
576
517
|
`${worst[2].length} (${worst[2].join(", ")}). An edge table asserts that a code determines a type, and this ` +
|
|
577
518
|
"publisher assigns the type per polygon, so the table would be this build's invention rather than the authority's mapping"
|
|
578
519
|
)
|
|
579
520
|
}
|
|
580
521
|
|
|
581
|
-
/**
|
|
582
|
-
* Refuse an artifact whose rings do not add up to the area the publisher itself reports.
|
|
583
|
-
*
|
|
584
|
-
* The message carries the hole-blind total beside the nested one, because the gap between them is the diagnosis: a hole
|
|
585
|
-
* read as an exterior ring answers "inside" for every point in it.
|
|
586
|
-
*/
|
|
587
522
|
function assertAreaAgreement(
|
|
588
523
|
streamed: StreamResult,
|
|
589
524
|
expectedSourceAreaM2: number | undefined
|
|
590
525
|
): BuildZoningResult["area"] {
|
|
591
526
|
const signedKM2 = streamed.area.signedM2 / M2_PER_KM2
|
|
592
527
|
|
|
593
|
-
//
|
|
594
|
-
// build's own reading would make the receipt print "0.000% apart" for a check that never ran
|
|
595
|
-
// a reader cannot tell from a pass.
|
|
528
|
+
// The publisher's figure is absent rather than defaulted.
|
|
529
|
+
// This build's own reading would make the receipt print "0.000% apart" for a check that never ran.
|
|
596
530
|
const reading = areaAgreementFrom(
|
|
597
531
|
{ nestedM2: streamed.area.nestedM2, allExteriorM2: streamed.area.allExteriorM2 },
|
|
598
|
-
expectedSourceAreaM2
|
|
532
|
+
expectedSourceAreaM2 ?? null
|
|
599
533
|
)
|
|
600
534
|
|
|
601
535
|
const area: BuildZoningResult["area"] = { ...reading, signedKM2 }
|
|
@@ -612,12 +546,9 @@ function assertAreaAgreement(
|
|
|
612
546
|
/**
|
|
613
547
|
* Run the ingest as a sequence of bounded child processes, over ranges of the authority's own feature ids.
|
|
614
548
|
*
|
|
615
|
-
*
|
|
616
|
-
*
|
|
617
|
-
*
|
|
618
|
-
*
|
|
619
|
-
* @throws {Error} When a chunk exits non-zero, or prints no result line — a chunk that died mid-range has written a
|
|
620
|
-
* partial set of rows, and continuing would seal an artifact missing features nobody could name.
|
|
549
|
+
* @throws {Error} When a chunk exits non-zero or prints no result line.
|
|
550
|
+
* A chunk that died mid-range has written a partial set of rows.
|
|
551
|
+
* The parent must stop before sealing that partial artifact.
|
|
621
552
|
*/
|
|
622
553
|
async function runBatchedIngest(
|
|
623
554
|
tmpPath: string,
|
|
@@ -625,11 +556,11 @@ async function runBatchedIngest(
|
|
|
625
556
|
batched: Extract<BuildZoningInput, { batched: unknown }>["batched"]
|
|
626
557
|
): Promise<StreamResult> {
|
|
627
558
|
const chunkSize = batched.chunkSize ?? DEFAULT_CHUNK_SIZE
|
|
628
|
-
const script = resolveModulePath("@mailwoman/zoning/
|
|
559
|
+
const script = resolveModulePath("@mailwoman/zoning/sdk/ingest/worker")
|
|
629
560
|
const chunks: ZoningChunkResult[] = []
|
|
630
561
|
|
|
631
|
-
// The upper bound is deliberately open
|
|
632
|
-
// count would drop every feature
|
|
562
|
+
// The upper bound is deliberately open because the source reports a count instead of a maximum ID.
|
|
563
|
+
// A range that stopped at the count would drop every feature after a numbering gap.
|
|
633
564
|
let from = 1
|
|
634
565
|
|
|
635
566
|
for (;;) {
|
|
@@ -661,19 +592,13 @@ async function runBatchedIngest(
|
|
|
661
592
|
/**
|
|
662
593
|
* Refuse a coverage row that would license a negative claim.
|
|
663
594
|
*
|
|
664
|
-
*
|
|
665
|
-
*
|
|
666
|
-
* `designated` or `surveyed` basis here would let an absent zoning polygon be read as a statement that no restriction
|
|
667
|
-
* applies, over most of the map. The reader checks the same thing at open time, so an artifact built by some other path
|
|
668
|
-
* cannot get past it either.
|
|
595
|
+
* No row of this layer can support that claim because the Department publishes
|
|
596
|
+
* coverage detail only in a map viewer.
|
|
669
597
|
*/
|
|
670
598
|
export function assertNoNegativeClaim(cells: ReadonlyArray<CoverageCell>): void {
|
|
671
599
|
assertCoverageNoNegativeClaim("zoning build", cells, GZT_COVERAGE_LIMIT)
|
|
672
600
|
}
|
|
673
601
|
|
|
674
|
-
/**
|
|
675
|
-
* Insert the authorities.
|
|
676
|
-
*/
|
|
677
602
|
function writeJurisdictionRows(
|
|
678
603
|
database: DatabaseClient<ZoningDatabase>,
|
|
679
604
|
jurisdictions: ReadonlyArray<[string, string]>
|
|
@@ -683,16 +608,12 @@ function writeJurisdictionRows(
|
|
|
683
608
|
)
|
|
684
609
|
|
|
685
610
|
for (const [code, name] of jurisdictions.toSorted((left, right) => (left[0] < right[0] ? -1 : 1))) {
|
|
686
|
-
// The id
|
|
687
|
-
//
|
|
688
|
-
// be the publisher's.
|
|
611
|
+
// The id is the publisher's own code, preserved in both columns rather than repaired in one
|
|
612
|
+
// because a repaired code is this package's spelling in a column that claims to be the publisher's.
|
|
689
613
|
insert.run(code, name, code, "IE")
|
|
690
614
|
}
|
|
691
615
|
}
|
|
692
616
|
|
|
693
|
-
/**
|
|
694
|
-
* Insert the plans.
|
|
695
|
-
*/
|
|
696
617
|
function writePlanRows(database: DatabaseClient<ZoningDatabase>, plans: ZoningChunkResult["plans"]): void {
|
|
697
618
|
const insert = database.prepare(
|
|
698
619
|
"INSERT INTO zoning_plan (plan_id, jurisdiction_id, plan_name, plan_level, valid_from, valid_to, current_plan) " +
|
|
@@ -705,13 +626,8 @@ function writePlanRows(database: DatabaseClient<ZoningDatabase>, plans: ZoningCh
|
|
|
705
626
|
}
|
|
706
627
|
|
|
707
628
|
/**
|
|
708
|
-
* Insert the vocabulary
|
|
709
|
-
*
|
|
710
|
-
*
|
|
711
|
-
* A declared code the data never uses is kept at `observed_rows = 0`, because the domain is the publisher's statement
|
|
712
|
-
* of what a value may be rather than a census of what it is — Ireland's `SDZ` plan level is exactly that. A used code
|
|
713
|
-
* the publisher never declared is kept at `declared = 0`, because inventing a declaration would make a source-schema
|
|
714
|
-
* change indistinguishable from the publisher's own vocabulary.
|
|
629
|
+
* Insert the vocabulary, keeping every code the publisher declares at `observed_rows = 0`
|
|
630
|
+
* and every used code it never declared at `declared = 0`.
|
|
715
631
|
*/
|
|
716
632
|
function writeVocabularyRows(
|
|
717
633
|
database: DatabaseClient<ZoningDatabase>,
|
|
@@ -753,9 +669,9 @@ function writeVocabularyRows(
|
|
|
753
669
|
scheme,
|
|
754
670
|
code,
|
|
755
671
|
label,
|
|
756
|
-
//
|
|
757
|
-
//
|
|
758
|
-
// this column
|
|
672
|
+
// `declared` is a property of the publisher's domain rather than of the scheme,
|
|
673
|
+
// so a local authority's own codes are observed and an undeclared generic
|
|
674
|
+
// type is what this column makes visible.
|
|
759
675
|
declared: scheme === GZT_CROSSWALK_SCHEME && GZT_DECLARED_CODE_SET.has(code) ? 1 : 0,
|
|
760
676
|
observedRows,
|
|
761
677
|
})
|
|
@@ -766,17 +682,15 @@ function writeVocabularyRows(
|
|
|
766
682
|
for (const row of [...rows.values()].toSorted((left, right) =>
|
|
767
683
|
left.scheme === right.scheme ? (left.code < right.code ? -1 : 1) : left.scheme < right.scheme ? -1 : 1
|
|
768
684
|
)) {
|
|
769
|
-
// NULL
|
|
770
|
-
// which has no DNS record, and three candidate replacements on the live host answer HTTP 404 — so the definitions
|
|
771
|
-
// behind the code-to-label pairs were not retrievable and this column says so by being empty.
|
|
685
|
+
// NULL rather than a plausible URL, because the definitions behind the code-to-label pairs were not retrievable.
|
|
772
686
|
insert.run(row.scheme, row.code, row.label, null, null, row.declared, row.observedRows)
|
|
773
687
|
|
|
774
688
|
const census = bySchema.get(row.scheme) ?? { codes: 0, undeclared: 0, undeclaredCodes: [] }
|
|
775
689
|
|
|
776
690
|
census.codes++
|
|
777
691
|
|
|
778
|
-
//
|
|
779
|
-
//
|
|
692
|
+
// The census counts an undeclared code only where the publisher does publish a domain
|
|
693
|
+
// to be outside of, since a local scheme is undeclared by construction.
|
|
780
694
|
if (!row.declared && row.scheme === GZT_CROSSWALK_SCHEME) {
|
|
781
695
|
census.undeclared++
|
|
782
696
|
census.undeclaredCodes.push(row.code)
|