@mailwoman/zoning 10.1.0 → 10.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +1 -1
  2. package/lib/index.ts +16 -17
  3. package/lib/schema.ts +11 -34
  4. package/out/index.d.ts +8 -8
  5. package/out/index.d.ts.map +1 -1
  6. package/out/index.js +12 -14
  7. package/out/index.js.map +1 -1
  8. package/out/schema.d.ts +6 -33
  9. package/out/schema.d.ts.map +1 -1
  10. package/out/schema.js +1 -1
  11. package/out/schema.js.map +1 -1
  12. package/out/sdk/build-zoning.js +3 -3
  13. package/out/sdk/build-zoning.js.map +1 -1
  14. package/out/sdk/cells.d.ts +2 -2
  15. package/out/sdk/cells.d.ts.map +1 -1
  16. package/out/sdk/cells.js +2 -2
  17. package/out/sdk/cells.js.map +1 -1
  18. package/out/sdk/download.js +1 -1
  19. package/out/sdk/download.js.map +1 -1
  20. package/out/sdk/ingest/chunk.js +3 -3
  21. package/out/sdk/ingest/chunk.js.map +1 -1
  22. package/out/sdk/ingest/worker.js +3 -3
  23. package/out/sdk/ingest/worker.js.map +1 -1
  24. package/out/sdk/ingest.d.ts +4 -14
  25. package/out/sdk/ingest.d.ts.map +1 -1
  26. package/out/sdk/ingest.js +3 -3
  27. package/out/sdk/ingest.js.map +1 -1
  28. package/out/sdk/measure-resolutions.d.ts +2 -12
  29. package/out/sdk/measure-resolutions.d.ts.map +1 -1
  30. package/out/sdk/measure-resolutions.js +0 -1
  31. package/out/sdk/measure-resolutions.js.map +1 -1
  32. package/out/sdk/verify.d.ts +9 -28
  33. package/out/sdk/verify.d.ts.map +1 -1
  34. package/out/sdk/verify.js +13 -13
  35. package/out/sdk/verify.js.map +1 -1
  36. package/package.json +7 -7
  37. package/sdk/build-zoning.ts +3 -3
  38. package/sdk/cells.ts +4 -4
  39. package/sdk/download.ts +1 -1
  40. package/sdk/ingest/chunk.ts +3 -3
  41. package/sdk/ingest/worker.ts +3 -3
  42. package/sdk/ingest.ts +8 -20
  43. package/sdk/measure-resolutions.ts +2 -14
  44. package/sdk/verify.ts +24 -41
package/sdk/ingest.ts CHANGED
@@ -12,7 +12,7 @@
12
12
 
13
13
  import { declaredFeatureCount } from "@mailwoman/core/layers"
14
14
  import { assertRingsInsideExtent, requireArealPolygons, type MultiPolygonRings } from "@mailwoman/spatial"
15
- import { readOGRLayerIdentity } from "@mailwoman/spatial/tools/ogr"
15
+ import { readOGRLayerIdentity, type OGRLayerSchema } from "@mailwoman/spatial/tools/ogr"
16
16
  import { spawnOGR2OGR } from "@mailwoman/spatial/tools/ogr/stream"
17
17
  import { wellKnownGeometryToGeoJSON } from "@mailwoman/spatial/well-known-text"
18
18
  import { CSVSpliterator } from "spliterator"
@@ -86,7 +86,8 @@ export interface ZoningIngestOptions {
86
86
  expectEPSG?: number
87
87
  /**
88
88
  * The extent that every reprojected vertex must fall inside.
89
- * The default is the Department's declared extent.
89
+ *
90
+ * @defaultValue the Department's declared extent.
90
91
  */
91
92
  declaredBBox?: readonly [number, number, number, number]
92
93
  /**
@@ -105,19 +106,6 @@ export interface ZoningIngestOptions {
105
106
  authorityCode?: string
106
107
  }
107
108
 
108
- /**
109
- * The metadata that the source declares, read before any feature.
110
- */
111
- export interface ZoningSourceIdentity {
112
- epsg: number
113
- featureCount: number
114
- layer: string
115
- /**
116
- * The source's attribute field names.
117
- */
118
- fields: ReadonlySet<string>
119
- }
120
-
121
109
  /**
122
110
  * The number of coordinate decimals that ogr2ogr writes.
123
111
  * Nine decimals is far finer than the source's precision.
@@ -160,7 +148,7 @@ export const ZONING_SOURCE_FIELDS: ReadonlyArray<string> = [
160
148
  * @throws {Error} When the export is unreadable, when its declared EPSG code differs
161
149
  * from `expectEPSG`, or when it lacks a field that the ingest reads.
162
150
  */
163
- export async function readZoningSourceIdentity(options: ZoningIngestOptions): Promise<ZoningSourceIdentity> {
151
+ export async function readZoningSourceIdentity(options: ZoningIngestOptions): Promise<OGRLayerSchema> {
164
152
  const identity = await readOGRLayerIdentity({
165
153
  path: options.exportPath,
166
154
  expectEPSG: options.expectEPSG ?? GZT_SOURCE_EPSG,
@@ -195,7 +183,7 @@ function whereClause(options: ZoningIngestOptions): string[] {
195
183
  bounds.push(`OBJECTID <= ${options.objectIDTo}`)
196
184
  }
197
185
 
198
- if (options.authorityCode !== undefined) {
186
+ if (options.authorityCode) {
199
187
  bounds.push(`LA_CODE = '${options.authorityCode.replaceAll("'", "''")}'`)
200
188
  }
201
189
 
@@ -205,10 +193,10 @@ function whereClause(options: ZoningIngestOptions): string[] {
205
193
  /**
206
194
  * Returns the value, or null when it is undefined or empty.
207
195
  */
208
- function blankToNull(value: string | undefined): string | null {
209
- if (value === undefined) return null
196
+ function blankToNull(value: string | null | undefined): string | null {
197
+ if (!value) return null
210
198
 
211
- return value.length ? value : null
199
+ return value ?? null
212
200
  }
213
201
 
214
202
  /**
@@ -6,7 +6,7 @@
6
6
  * The `partial` share cannot choose between candidate resolutions, so each is reported by candidates per cell and by the polyfill-only zero-cell count.
7
7
  */
8
8
 
9
- import type { ResolutionMeasurementOptions } from "@mailwoman/core/layers"
9
+ import type { ResolutionMeasurementOptions, ResolutionMeasurementReport } from "@mailwoman/core/layers"
10
10
  import { classifyFeatureCells } from "@mailwoman/spatial"
11
11
 
12
12
  import { polyfillFindsNothing, ZoningCellIndex, type CellIndexMeasurement } from "#sdk/cells"
@@ -20,16 +20,6 @@ export interface MeasureResolutionsOptions extends ZoningIngestOptions, Resoluti
20
20
  measurePolyfill?: boolean
21
21
  }
22
22
 
23
- export interface ResolutionMeasurementReport {
24
- features: number
25
- /**
26
- * The count the source declares for itself.
27
- * A run whose streamed total differs read a truncated file.
28
- */
29
- declaredFeatureCount: number
30
- measurements: CellIndexMeasurement[]
31
- }
32
-
33
23
  const DEFAULT_PROGRESS_EVERY = 5000
34
24
 
35
25
  /**
@@ -39,7 +29,7 @@ const DEFAULT_PROGRESS_EVERY = 5000
39
29
  */
40
30
  export async function measureZoningCellResolutions(
41
31
  options: MeasureResolutionsOptions
42
- ): Promise<ResolutionMeasurementReport> {
32
+ ): Promise<ResolutionMeasurementReport<CellIndexMeasurement>> {
43
33
  const identity = await readZoningSourceIdentity(options)
44
34
  const indexes = options.resolutions.map((resolution) => new ZoningCellIndex(resolution))
45
35
  const progressEvery = options.progressEvery ?? DEFAULT_PROGRESS_EVERY
@@ -80,5 +70,3 @@ export async function measureZoningCellResolutions(
80
70
  measurements: indexes.map((index) => index.finish()),
81
71
  }
82
72
  }
83
-
84
- export { formatResolutionRows } from "#sdk/cells"
package/sdk/verify.ts CHANGED
@@ -30,7 +30,9 @@
30
30
  * tolerance stricter and report a rendering difference as a conversion defect.
31
31
  */
32
32
 
33
+ import type { OGCFeature } from "@mailwoman/core/api"
33
34
  import { stringifyJSON } from "@mailwoman/core/json"
35
+ import type { OutsideCoverageRow } from "@mailwoman/core/layers"
34
36
  import {
35
37
  nearestRingEdgeMetres,
36
38
  pointInEncodedRings,
@@ -70,8 +72,8 @@ export interface AgreementRow {
70
72
  * is what this layer is for: two paths that agree on containment and disagree
71
73
  * on the code would be a silent vocabulary defect.
72
74
  */
73
- serviceLocalCode?: string
74
- outcome: "agree" | "disagree" | "boundary_tolerance"
75
+ serviceLocalCode: string | null
76
+ result: "agree" | "disagree" | "boundary_tolerance"
75
77
  /**
76
78
  * Meters from the point to the nearest edge of any polygon the service returned nearby.
77
79
  *
@@ -80,25 +82,9 @@ export interface AgreementRow {
80
82
  * rendering the same edge differently.
81
83
  *
82
84
  * A receipt without it forces a re-run.
83
- * `undefined` means the service returned no polygon at all near the point.
85
+ * `null` means the service returned no polygon at all near the point.
84
86
  */
85
- nearestEdgeMetres?: number
86
- }
87
-
88
- /**
89
- * The negative half: a point this product's publication does not reach.
90
- */
91
- export interface OutsideRow {
92
- label: string
93
- latitude: number
94
- longitude: number
95
- kind: string
96
- designations: number
97
- /**
98
- * True when the artifact answered `unknown` with no designation.
99
- * The only acceptable reading here.
100
- */
101
- passed: boolean
87
+ nearestEdgeMetres: number | null
102
88
  }
103
89
 
104
90
  export interface VerifyZoningResult {
@@ -110,7 +96,7 @@ export interface VerifyZoningResult {
110
96
  * Points where both paths placed the location inside a zone and the local codes differed.
111
97
  */
112
98
  codeMismatches: number
113
- outside: OutsideRow[]
99
+ outside: OutsideCoverageRow[]
114
100
  outsidePassed: number
115
101
  }
116
102
 
@@ -162,10 +148,7 @@ const BOUNDARY_TOLERANCE_METRES = 0.5
162
148
  * One feature as the service publishes it.
163
149
  * The only shape the comparison reads.
164
150
  */
165
- export interface ServiceFeature {
166
- properties?: Record<string, unknown>
167
- geometry?: { type: string; coordinates: unknown }
168
- }
151
+ export type ServiceFeature = OGCFeature
169
152
 
170
153
  /**
171
154
  * The one call the verification makes against the service: the features it publishes near a point.
@@ -173,7 +156,7 @@ export interface ServiceFeature {
173
156
  * The function exposes only the service read.
174
157
  * This keeps the check's own logic testable.
175
158
  *
176
- * The comparison's value is that it decides which of three outcomes a point gets.
159
+ * The comparison's value is that it decides which of three results a point gets.
177
160
  *
178
161
  * An HTTP client would let tests observe these decisions only during a live run.
179
162
  * A scripted reader pins the decisions. {@link createServiceReader} builds the real reader.
@@ -218,7 +201,7 @@ export async function verifyZoningDatabase(options: VerifyZoningOptions): Promis
218
201
  const local = lookup.lookup(point.latitude, point.longitude)
219
202
  const service = await readServiceContainment(options.readServiceFeatures, point.latitude, point.longitude)
220
203
  const localInside = local.kind === ZoningReadingKind.Designated
221
- const nearEdge = service.nearestEdgeMetres !== undefined && service.nearestEdgeMetres <= BOUNDARY_TOLERANCE_METRES
204
+ const nearEdge = service.nearestEdgeMetres !== null && service.nearestEdgeMetres <= BOUNDARY_TOLERANCE_METRES
222
205
 
223
206
  agreement.push({
224
207
  label: point.label,
@@ -226,15 +209,15 @@ export async function verifyZoningDatabase(options: VerifyZoningOptions): Promis
226
209
  longitude: point.longitude,
227
210
  local,
228
211
  serviceInside: service.inside,
229
- ...(service.localCode === undefined ? {} : { serviceLocalCode: service.localCode }),
230
- outcome: localInside === service.inside ? "agree" : nearEdge ? "boundary_tolerance" : "disagree",
231
- ...(service.nearestEdgeMetres === undefined ? {} : { nearestEdgeMetres: service.nearestEdgeMetres }),
212
+ serviceLocalCode: service.localCode,
213
+ result: localInside === service.inside ? "agree" : nearEdge ? "boundary_tolerance" : "disagree",
214
+ nearestEdgeMetres: service.nearestEdgeMetres,
232
215
  })
233
216
 
234
217
  options.onProgress?.(`${agreement.length}/${options.points.length} points compared`)
235
218
  }
236
219
 
237
- const outside: OutsideRow[] = []
220
+ const outside: OutsideCoverageRow[] = []
238
221
 
239
222
  for (const point of options.outsidePoints ?? OUTSIDE_PUBLICATION_POINTS) {
240
223
  const reading = lookup.lookup(point.latitude, point.longitude)
@@ -251,14 +234,14 @@ export async function verifyZoningDatabase(options: VerifyZoningOptions): Promis
251
234
 
252
235
  return {
253
236
  agreement,
254
- agreed: agreement.filter((row) => row.outcome === "agree").length,
255
- disagreed: agreement.filter((row) => row.outcome === "disagree").length,
256
- boundaryTolerance: agreement.filter((row) => row.outcome === "boundary_tolerance").length,
237
+ agreed: agreement.filter((row) => row.result === "agree").length,
238
+ disagreed: agreement.filter((row) => row.result === "disagree").length,
239
+ boundaryTolerance: agreement.filter((row) => row.result === "boundary_tolerance").length,
257
240
  codeMismatches: agreement.filter(
258
241
  (row) =>
259
- row.outcome === "agree" &&
242
+ row.result === "agree" &&
260
243
  row.serviceInside &&
261
- row.serviceLocalCode !== undefined &&
244
+ row.serviceLocalCode !== null &&
262
245
  !row.local.designations.some((designation) => designation.localCode === row.serviceLocalCode)
263
246
  ).length,
264
247
  outside,
@@ -278,12 +261,12 @@ async function readServiceContainment(
278
261
  readServiceFeatures: ServiceFeatureReader,
279
262
  latitude: number,
280
263
  longitude: number
281
- ): Promise<{ inside: boolean; localCode?: string; nearestEdgeMetres?: number }> {
264
+ ): Promise<{ inside: boolean; localCode: string | null; nearestEdgeMetres: number | null }> {
282
265
  const features = await readServiceFeatures(latitude, longitude)
283
266
 
284
267
  let nearest = Infinity
285
268
  let inside = false
286
- let localCode: string | undefined
269
+ let localCode: string | null = null
287
270
 
288
271
  for (const feature of features) {
289
272
  const geometry = feature.geometry
@@ -315,7 +298,7 @@ async function readServiceContainment(
315
298
 
316
299
  const code = feature.properties?.ZONE_ORIG
317
300
 
318
- if (typeof code === "string" && localCode === undefined) {
301
+ if (typeof code === "string" && !localCode) {
319
302
  localCode = code
320
303
  }
321
304
  }
@@ -323,8 +306,8 @@ async function readServiceContainment(
323
306
 
324
307
  return {
325
308
  inside,
326
- ...(localCode === undefined ? {} : { localCode }),
327
- ...(Number.isFinite(nearest) ? { nearestEdgeMetres: nearest } : {}),
309
+ localCode,
310
+ nearestEdgeMetres: Number.isFinite(nearest) ? nearest : null,
328
311
  }
329
312
  }
330
313