@mailwoman/zoning 9.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 (82) hide show
  1. package/README.md +315 -0
  2. package/lib/index.ts +616 -0
  3. package/lib/ring-roles.ts +233 -0
  4. package/lib/rings.ts +34 -0
  5. package/lib/schema.ts +449 -0
  6. package/lib/scripts/ingest-chunk.ts +41 -0
  7. package/lib/sdk/build-zoning.ts +790 -0
  8. package/lib/sdk/cells.ts +276 -0
  9. package/lib/sdk/client.ts +335 -0
  10. package/lib/sdk/download.ts +78 -0
  11. package/lib/sdk/index.ts +15 -0
  12. package/lib/sdk/ingest-chunk.ts +360 -0
  13. package/lib/sdk/ingest.ts +402 -0
  14. package/lib/sdk/measure-resolutions.ts +100 -0
  15. package/lib/sdk/verify.ts +350 -0
  16. package/lib/test-kit.ts +207 -0
  17. package/lib/vocabulary.ts +342 -0
  18. package/out/index.d.ts +257 -0
  19. package/out/index.d.ts.map +1 -0
  20. package/out/index.js +325 -0
  21. package/out/index.js.map +1 -0
  22. package/out/ring-roles.d.ts +88 -0
  23. package/out/ring-roles.d.ts.map +1 -0
  24. package/out/ring-roles.js +151 -0
  25. package/out/ring-roles.js.map +1 -0
  26. package/out/rings.d.ts +22 -0
  27. package/out/rings.d.ts.map +1 -0
  28. package/out/rings.js +22 -0
  29. package/out/rings.js.map +1 -0
  30. package/out/schema.d.ts +325 -0
  31. package/out/schema.d.ts.map +1 -0
  32. package/out/schema.js +186 -0
  33. package/out/schema.js.map +1 -0
  34. package/out/scripts/ingest-chunk.d.ts +11 -0
  35. package/out/scripts/ingest-chunk.d.ts.map +1 -0
  36. package/out/scripts/ingest-chunk.js +36 -0
  37. package/out/scripts/ingest-chunk.js.map +1 -0
  38. package/out/sdk/build-zoning.d.ts +283 -0
  39. package/out/sdk/build-zoning.d.ts.map +1 -0
  40. package/out/sdk/build-zoning.js +462 -0
  41. package/out/sdk/build-zoning.js.map +1 -0
  42. package/out/sdk/cells.d.ts +137 -0
  43. package/out/sdk/cells.d.ts.map +1 -0
  44. package/out/sdk/cells.js +176 -0
  45. package/out/sdk/cells.js.map +1 -0
  46. package/out/sdk/client.d.ts +151 -0
  47. package/out/sdk/client.d.ts.map +1 -0
  48. package/out/sdk/client.js +239 -0
  49. package/out/sdk/client.js.map +1 -0
  50. package/out/sdk/download.d.ts +51 -0
  51. package/out/sdk/download.d.ts.map +1 -0
  52. package/out/sdk/download.js +57 -0
  53. package/out/sdk/download.js.map +1 -0
  54. package/out/sdk/index.d.ts +15 -0
  55. package/out/sdk/index.d.ts.map +1 -0
  56. package/out/sdk/index.js +15 -0
  57. package/out/sdk/index.js.map +1 -0
  58. package/out/sdk/ingest-chunk.d.ts +130 -0
  59. package/out/sdk/ingest-chunk.d.ts.map +1 -0
  60. package/out/sdk/ingest-chunk.js +206 -0
  61. package/out/sdk/ingest-chunk.js.map +1 -0
  62. package/out/sdk/ingest.d.ts +191 -0
  63. package/out/sdk/ingest.d.ts.map +1 -0
  64. package/out/sdk/ingest.js +238 -0
  65. package/out/sdk/ingest.js.map +1 -0
  66. package/out/sdk/measure-resolutions.d.ts +51 -0
  67. package/out/sdk/measure-resolutions.d.ts.map +1 -0
  68. package/out/sdk/measure-resolutions.js +64 -0
  69. package/out/sdk/measure-resolutions.js.map +1 -0
  70. package/out/sdk/verify.d.ts +176 -0
  71. package/out/sdk/verify.d.ts.map +1 -0
  72. package/out/sdk/verify.js +202 -0
  73. package/out/sdk/verify.js.map +1 -0
  74. package/out/test-kit.d.ts +97 -0
  75. package/out/test-kit.d.ts.map +1 -0
  76. package/out/test-kit.js +180 -0
  77. package/out/test-kit.js.map +1 -0
  78. package/out/vocabulary.d.ts +221 -0
  79. package/out/vocabulary.d.ts.map +1 -0
  80. package/out/vocabulary.js +299 -0
  81. package/out/vocabulary.js.map +1 -0
  82. package/package.json +245 -0
@@ -0,0 +1,350 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * The two-path agreement check, and its negative half.
7
+ *
8
+ * POSITIVE HALF. A sample of points is answered from the sealed artifact and then re-asked of the
9
+ * Department's own feature service — the same authority, a different distribution channel, and geometry
10
+ * this package has never touched. The point test is run again on the service's own rings, so what is
11
+ * compared is a verdict against a verdict rather than a file against itself. That is what makes it a check
12
+ * on OUR CONVERSION rather than on the authority.
13
+ *
14
+ * AND THE SERVICE ANSWERS IN THE PUBLISHER'S OWN RING CONVENTION, so the comparison exercises the hole
15
+ * handling twice over. `outSR=4326` on the query path returns the same clockwise-exterior rings the bulk
16
+ * export carries, so this side re-derives the roles the same way the ingest did — and a point inside a hole
17
+ * comes back OUTSIDE on both paths or on neither.
18
+ *
19
+ * NEGATIVE HALF, AND IT MATTERS MORE HERE THAN FOR ANY SIBLING LAYER. Donegal is the one local authority of
20
+ * 31 the Department does not publish, and Northern Ireland is outside the product entirely — so points in
21
+ * both must come back `unknown` with NO designation. A positive-only check would pass on an artifact that
22
+ * reported the whole island as zoned, and this layer's entire coverage posture exists because an absent
23
+ * polygon is not a statement.
24
+ *
25
+ * THE CHANNELS DIFFER IN COORDINATE PRECISION AND THAT IS WHY A BOUNDARY POINT IS NOT A FAILURE. The
26
+ * archive publishes nine decimals through this package's ingest; the service's own JSON rounds. A point
27
+ * within roughly a metre of a zone boundary can land on opposite sides of two renderings of the same edge.
28
+ * Those are reported as `boundary_tolerance` with their distance to the nearest edge, and the count is part
29
+ * of the receipt.
30
+ *
31
+ * THE DISTANCE IS TO THE EDGE, NOT TO THE NEAREST VERTEX. A point a centimetre from a long edge can be
32
+ * metres from every vertex of it — a sibling layer's one near-miss read 1.58 m to vertices and 0.009 m to
33
+ * edges, an overstatement of 175-fold — so measuring vertices makes the boundary tolerance far stricter than
34
+ * it reads, which is how a rendering difference gets reported as a conversion defect.
35
+ */
36
+
37
+ import { nearestRingEdgeMetres, pointInEncodedRings, strideSampleInteriorPoints } from "@mailwoman/spatial"
38
+ import { DatabaseClient } from "@mailwoman/sqlite/client"
39
+
40
+ import { ZoningLookup, ZoningReadingKind, type ZoningReading } from "#index"
41
+ import { encodeRings, resolveRingRoles, type MultiPolygonRings, type PolygonRings } from "#rings"
42
+ import type { ZoningDatabase } from "#schema"
43
+ import type { GZTClient } from "#sdk/client"
44
+
45
+ /**
46
+ * One point, both verdicts, and whether they agree.
47
+ */
48
+ export interface AgreementRow {
49
+ label: string
50
+ latitude: number
51
+ longitude: number
52
+ /**
53
+ * The artifact's answer.
54
+ */
55
+ local: ZoningReading
56
+ /**
57
+ * Whether the service's own geometry places the point inside a zoning polygon.
58
+ */
59
+ serviceInside: boolean
60
+ /**
61
+ * The local code the SERVICE reports at the point, where it reports one. Compared verbatim against the artifact's,
62
+ * because carrying the code verbatim is what this layer is for: two paths that agree on containment and disagree on
63
+ * the code would be a silent vocabulary defect.
64
+ */
65
+ serviceLocalCode?: string
66
+ outcome: "agree" | "disagree" | "boundary_tolerance"
67
+ /**
68
+ * Metres from the point to the nearest EDGE of any polygon the service returned nearby.
69
+ *
70
+ * Carried on every row rather than only the tolerated ones, because it is what separates a real defect from the two
71
+ * channels rendering the same edge differently — and a receipt that omits it forces a re-run. `undefined` means the
72
+ * service returned no polygon at all near the point.
73
+ */
74
+ nearestEdgeMetres?: number
75
+ }
76
+
77
+ /**
78
+ * The negative half: a point this product's publication does not reach.
79
+ */
80
+ export interface OutsideRow {
81
+ label: string
82
+ latitude: number
83
+ longitude: number
84
+ kind: string
85
+ designations: number
86
+ /**
87
+ * True when the artifact answered `unknown` with no designation — the only acceptable reading here.
88
+ */
89
+ passed: boolean
90
+ }
91
+
92
+ export interface VerifyZoningResult {
93
+ agreement: AgreementRow[]
94
+ agreed: number
95
+ disagreed: number
96
+ boundaryTolerance: number
97
+ /**
98
+ * Points where both paths placed the location inside a zone and the local codes differed.
99
+ */
100
+ codeMismatches: number
101
+ outside: OutsideRow[]
102
+ outsidePassed: number
103
+ }
104
+
105
+ /**
106
+ * Points this product's publication does not reach, named. Each is a place, not a bare pair of numbers: a coordinate a
107
+ * reader cannot name is a coordinate nobody can check.
108
+ *
109
+ * TWO POPULATIONS, AND BOTH ARE LOAD-BEARING. The Donegal points are the case this layer's coverage posture exists for
110
+ * — the Department has not published that authority's zoning, and a builder that read absence as "unrestricted" would
111
+ * answer them confidently. The Northern Irish points confirm the artifact is clipped to the Republic rather than to the
112
+ * island: zoning there is a different jurisdiction's instrument under a different planning act.
113
+ */
114
+ export const OUTSIDE_PUBLICATION_POINTS: ReadonlyArray<{ label: string; latitude: number; longitude: number }> = [
115
+ { label: "Letterkenny town centre, Donegal", latitude: 54.9503, longitude: -7.7345 },
116
+ { label: "Buncrana, Donegal", latitude: 55.1367, longitude: -7.4561 },
117
+ { label: "Donegal Town", latitude: 54.6538, longitude: -8.1096 },
118
+ { label: "Belfast city centre, Northern Ireland", latitude: 54.5973, longitude: -5.9301 },
119
+ { label: "Derry city centre, Northern Ireland", latitude: 54.9966, longitude: -7.3086 },
120
+ { label: "Enniskillen, Northern Ireland", latitude: 54.3438, longitude: -7.6316 },
121
+ ]
122
+
123
+ /**
124
+ * Half-width of the bounding box the service is asked for, in degrees. About 11 m at this latitude — wide enough that a
125
+ * polygon containing the point is certainly returned, narrow enough that the response stays small.
126
+ */
127
+ const PROBE_HALF_WIDTH_DEGREES = 0.0001
128
+
129
+ /**
130
+ * How close to a service-polygon edge a disagreement is attributed to the channels' differing coordinate precision
131
+ * rather than to the conversion.
132
+ *
133
+ * Half a metre. The two channels render the same edge from the same source coordinates through different rounding, so a
134
+ * point between the two renderings lands on opposite sides; half a metre is far below any real zoning boundary and far
135
+ * above the rounding difference.
136
+ */
137
+ const BOUNDARY_TOLERANCE_METRES = 0.5
138
+
139
+ /**
140
+ * One feature as the service publishes it — the only shape the comparison reads.
141
+ */
142
+ export interface ServiceFeature {
143
+ properties?: Record<string, unknown>
144
+ geometry?: { type: string; coordinates: unknown }
145
+ }
146
+
147
+ /**
148
+ * The ONE call the verification makes against the service: the features it publishes near a point.
149
+ *
150
+ * A function rather than the client, and that is what makes the check's own logic testable. The comparison's value is
151
+ * that it decides which of three outcomes a point gets; expressed against an HTTP client it could only ever be watched
152
+ * on a live run, and a scripted reader lets those decisions be pinned. {@link createServiceReader} builds the real
153
+ * one.
154
+ */
155
+ export type ServiceFeatureReader = (latitude: number, longitude: number) => Promise<ServiceFeature[]>
156
+
157
+ /**
158
+ * The reader the live check uses: a bounding-box query against the Department's own service.
159
+ *
160
+ * The service answers a BOX, not a point, so this returns what it published nearby and the containment decision is made
161
+ * in {@link readServiceContainment} against those rings — comparing the artifact's verdict against a bare "the service
162
+ * returned something here" would pass on any polygon within eleven metres.
163
+ */
164
+ export function createServiceReader(client: Pick<GZTClient, "readFeaturesNear">): ServiceFeatureReader {
165
+ return async (latitude, longitude) => client.readFeaturesNear(latitude, longitude, PROBE_HALF_WIDTH_DEGREES)
166
+ }
167
+
168
+ export interface VerifyZoningOptions {
169
+ databasePath: string
170
+ readServiceFeatures: ServiceFeatureReader
171
+ /**
172
+ * Points to re-ask the service about. A caller samples them from the artifact — see {@link sampleAgreementPoints}.
173
+ */
174
+ points: ReadonlyArray<{ label: string; latitude: number; longitude: number; localCode?: string }>
175
+ outsidePoints?: ReadonlyArray<{ label: string; latitude: number; longitude: number }>
176
+ onProgress?: (message: string) => void
177
+ }
178
+
179
+ /**
180
+ * Run both halves.
181
+ */
182
+ export async function verifyZoningDatabase(options: VerifyZoningOptions): Promise<VerifyZoningResult> {
183
+ const lookup = new ZoningLookup({ databasePath: options.databasePath })
184
+
185
+ try {
186
+ const agreement: AgreementRow[] = []
187
+
188
+ for (const point of options.points) {
189
+ const local = lookup.lookup(point.latitude, point.longitude)
190
+ const service = await readServiceContainment(options.readServiceFeatures, point.latitude, point.longitude)
191
+ const localInside = local.kind === ZoningReadingKind.Designated
192
+ const nearEdge = service.nearestEdgeMetres !== undefined && service.nearestEdgeMetres <= BOUNDARY_TOLERANCE_METRES
193
+
194
+ agreement.push({
195
+ label: point.label,
196
+ latitude: point.latitude,
197
+ longitude: point.longitude,
198
+ local,
199
+ serviceInside: service.inside,
200
+ ...(service.localCode === undefined ? {} : { serviceLocalCode: service.localCode }),
201
+ outcome: localInside === service.inside ? "agree" : nearEdge ? "boundary_tolerance" : "disagree",
202
+ ...(service.nearestEdgeMetres === undefined ? {} : { nearestEdgeMetres: service.nearestEdgeMetres }),
203
+ })
204
+
205
+ options.onProgress?.(`${agreement.length}/${options.points.length} points compared`)
206
+ }
207
+
208
+ const outside: OutsideRow[] = []
209
+
210
+ for (const point of options.outsidePoints ?? OUTSIDE_PUBLICATION_POINTS) {
211
+ const reading = lookup.lookup(point.latitude, point.longitude)
212
+
213
+ outside.push({
214
+ label: point.label,
215
+ latitude: point.latitude,
216
+ longitude: point.longitude,
217
+ kind: reading.kind,
218
+ designations: reading.designations.length,
219
+ passed: reading.kind === ZoningReadingKind.Unknown && reading.designations.length === 0,
220
+ })
221
+ }
222
+
223
+ return {
224
+ agreement,
225
+ agreed: agreement.filter((row) => row.outcome === "agree").length,
226
+ disagreed: agreement.filter((row) => row.outcome === "disagree").length,
227
+ boundaryTolerance: agreement.filter((row) => row.outcome === "boundary_tolerance").length,
228
+ codeMismatches: agreement.filter(
229
+ (row) =>
230
+ row.outcome === "agree" &&
231
+ row.serviceInside &&
232
+ row.serviceLocalCode !== undefined &&
233
+ !row.local.designations.some((designation) => designation.localCode === row.serviceLocalCode)
234
+ ).length,
235
+ outside,
236
+ outsidePassed: outside.filter((row) => row.passed).length,
237
+ }
238
+ } finally {
239
+ lookup[Symbol.dispose]()
240
+ }
241
+ }
242
+
243
+ /**
244
+ * Whether the SERVICE's own geometry contains the point, decided here with the same ring-role resolution and the same
245
+ * even-odd rule the artifact's reader uses — so what is compared is a verdict against a verdict.
246
+ */
247
+ async function readServiceContainment(
248
+ readServiceFeatures: ServiceFeatureReader,
249
+ latitude: number,
250
+ longitude: number
251
+ ): Promise<{ inside: boolean; localCode?: string; nearestEdgeMetres?: number }> {
252
+ const features = await readServiceFeatures(latitude, longitude)
253
+
254
+ let nearest = Infinity
255
+ let inside = false
256
+ let localCode: string | undefined
257
+
258
+ for (const feature of features) {
259
+ const geometry = feature.geometry
260
+
261
+ if (!geometry) continue
262
+
263
+ const raw: MultiPolygonRings =
264
+ geometry.type === "MultiPolygon"
265
+ ? (geometry.coordinates as MultiPolygonRings)
266
+ : [geometry.coordinates as PolygonRings]
267
+
268
+ const distance = nearestRingEdgeMetres(geometry, longitude, latitude)
269
+
270
+ if (distance < nearest) {
271
+ nearest = distance
272
+ }
273
+
274
+ // THE SERVICE'S RINGS GET THE SAME ROLE RESOLUTION THE INGEST GAVE THE ARCHIVE'S. The publisher uses one convention on
275
+ // both channels, so reading this side as nested GeoJSON would answer "inside" for a point in a hole and report the
276
+ // artifact as wrong at exactly the locations the hole handling exists for.
277
+ const resolved = resolveRingRoles(raw, `service feature near ${latitude},${longitude}`)
278
+
279
+ // ENCODED AND RE-READ RATHER THAN RAY-CAST DIRECTLY, deliberately: the artifact answers through
280
+ // `pointInEncodedRings`, and running the service's geometry through a different predicate would compare two answers
281
+ // that were never asked the same question.
282
+ if (pointInEncodedRings(encodeRings(resolved.polygons), longitude, latitude)) {
283
+ inside = true
284
+
285
+ const code = feature.properties?.ZONE_ORIG
286
+
287
+ if (typeof code === "string" && localCode === undefined) {
288
+ localCode = code
289
+ }
290
+ }
291
+ }
292
+
293
+ return {
294
+ inside,
295
+ ...(localCode === undefined ? {} : { localCode }),
296
+ ...(Number.isFinite(nearest) ? { nearestEdgeMetres: nearest } : {}),
297
+ }
298
+ }
299
+
300
+ /**
301
+ * Draw a reproducible sample of points from the artifact — interior points of stored polygons, spread across
302
+ * authorities.
303
+ *
304
+ * SPREAD ACROSS AUTHORITIES RATHER THAN DRAWN FROM ONE, because 30 local authorities publish 581 distinct local codes
305
+ * between them and a sample from one would verify one authority's conversion while reporting on all of them. The stride
306
+ * discipline — keys chosen before any geometry is read, deterministic rather than random — is
307
+ * `strideSampleInteriorPoints`'s.
308
+ */
309
+ export function sampleAgreementPoints(
310
+ databasePath: string,
311
+ options: { count?: number } = {}
312
+ ): Array<{ label: string; latitude: number; longitude: number; localCode: string }> {
313
+ const count = options.count ?? 48
314
+ using database = new DatabaseClient<ZoningDatabase>(databasePath, { readOnly: true })
315
+
316
+ // ORDERED BY THE AUTHORITY FIRST, so a stride walks across the 30 of them rather than down one. A stride over
317
+ // `area_id` alone would follow the publisher's own feature numbering, which is grouped by authority — and would draw
318
+ // every sample from whichever authorities happen to sit on the stride.
319
+ const areaIDs = (
320
+ database.prepare("SELECT area_id FROM zoning_area ORDER BY jurisdiction_id, area_id").all() as Array<{
321
+ area_id: string
322
+ }>
323
+ ).map((row) => row.area_id)
324
+
325
+ const selectArea = database.prepare(
326
+ "SELECT area_id, jurisdiction_id, local_code, min_lat, min_lon, max_lat, max_lon, rings FROM zoning_area WHERE area_id = ?"
327
+ )
328
+
329
+ return strideSampleInteriorPoints(areaIDs, count, {
330
+ fetch: (key) =>
331
+ selectArea.get(key) as
332
+ | {
333
+ area_id: string
334
+ jurisdiction_id: string
335
+ local_code: string
336
+ min_lat: number
337
+ min_lon: number
338
+ max_lat: number
339
+ max_lon: number
340
+ rings: Uint8Array
341
+ }
342
+ | undefined,
343
+ gridSteps: 17,
344
+ toPoint: (area, interior) => ({
345
+ label: `${area.jurisdiction_id} ${JSON.stringify(area.local_code)} polygon ${area.area_id}`,
346
+ localCode: area.local_code,
347
+ ...interior,
348
+ }),
349
+ })
350
+ }
@@ -0,0 +1,207 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * `@mailwoman/zoning/test-kit` — hand-built geometry for the fixture rung: zones in two plans over the same
7
+ * ground, one with a hole encoded the way this service encodes them, one smaller than a cell, and one the
8
+ * authority states as UNZONED.
9
+ *
10
+ * A PACKAGE SUBPATH RATHER THAN A `test/` FILE, for the same reason `packages/mailwoman/lib/test-kit` is one:
11
+ * the observation route's suite lives in another workspace, and a relative import across two TypeScript
12
+ * projects is refused outright (`TS2878`) because the compiled layout would not match the source layout.
13
+ *
14
+ * NO NETWORK AND NO GDAL. The builder takes a {@linkcode ZoningFeatureSource}, so a fixture is a list of
15
+ * features — which is what lets this rung exercise the ring-role resolution, the vocabulary census, the cell
16
+ * classification, the coverage rows, the manifest and the seal on every machine rather than only the ones
17
+ * with ogr2ogr.
18
+ *
19
+ * THE EXTERIOR RING IS THE CLOCKWISE ONE, WHICH IS THE INVERSE OF THE GEOJSON CONVENTION AND OF EVERY
20
+ * SIBLING FIXTURE. `@mailwoman/spatial`'s `rectangleRing` winds counter-clockwise and its `reversedRing`
21
+ * clockwise, so this file aliases them the other way round from the flood and coastal test kits: under this
22
+ * service a clockwise ring is the EXTERIOR and a counter-clockwise one is a HOLE. A fixture that used the
23
+ * sibling naming would build geometry the ingest reads inside-out, and every assertion on it would pass.
24
+ *
25
+ * THE COORDINATES ARE IN THE IRISH SEA east of Dublin — inside the Department's declared extent, so a
26
+ * fixture stays in the coordinate space the product occupies, and clear of every real zoning polygon.
27
+ */
28
+
29
+ import { rectangleRing as counterClockwiseRing, reversedRing as clockwiseRing } from "@mailwoman/spatial"
30
+
31
+ import { resolveRingRoles, type MultiPolygonRings } from "#rings"
32
+ import type { ZoningFeatureSource, ZoningSourceFeature } from "#sdk/ingest"
33
+ import { GZT_SOURCE_EPSG, GZT_UNZONED_LOCAL_CODE } from "#vocabulary"
34
+
35
+ /**
36
+ * The exterior ring builder, under THIS service's convention. Clockwise.
37
+ */
38
+ export const exteriorRing = clockwiseRing
39
+
40
+ /**
41
+ * The hole ring builder, under THIS service's convention. Counter-clockwise.
42
+ */
43
+ export const holeRing = counterClockwiseRing
44
+
45
+ /**
46
+ * South-west corner of the fixture world, in the Irish Sea east of Dublin.
47
+ */
48
+ export const FIXTURE_ORIGIN = { lon: -5.99, lat: 53.3 } as const
49
+
50
+ /**
51
+ * Side of a fixture zone, in degrees. About 1.1 km at this latitude — several res-10 cells across, so a zone has a real
52
+ * interior AND a real fringe.
53
+ */
54
+ export const FIXTURE_SIDE = 0.01
55
+
56
+ /**
57
+ * The fixture authority and its two plans.
58
+ */
59
+ export const FIXTURE_AUTHORITY = { code: "Fx", name: "Fixture County Council" } as const
60
+
61
+ /**
62
+ * The two plans the fixture set uses, shaped like the real product's: a Development Plan and a Local Area Plan, each
63
+ * with its own stated window, both able to zone the same ground.
64
+ *
65
+ * The dates are in the source's own RFC 1123 form, because that is what the export publishes and this layer carries
66
+ * them as published rather than re-formatting them.
67
+ */
68
+ export const FIXTURE_PLANS = {
69
+ development: {
70
+ id: "FX-DP-2024",
71
+ name: "Fixture County Development Plan 2024-2030",
72
+ level: "DP",
73
+ from: "Mon, 01 Jan 2024 00:00:00 GMT",
74
+ to: "Sun, 31 Dec 2030 00:00:00 GMT",
75
+ },
76
+ localArea: {
77
+ id: "FX-LAP-2022",
78
+ name: "Fixture Town Local Area Plan 2022-2028",
79
+ level: "LAP",
80
+ from: "Sat, 01 Jan 2022 00:00:00 GMT",
81
+ to: "Sun, 31 Dec 2028 00:00:00 GMT",
82
+ },
83
+ } as const
84
+
85
+ /**
86
+ * One fixture feature, with its rings resolved the way the real ingest resolves them.
87
+ */
88
+ export function fixtureFeature(
89
+ objectID: number,
90
+ polygons: MultiPolygonRings,
91
+ overrides: Partial<Omit<ZoningSourceFeature, "rings">> = {}
92
+ ): ZoningSourceFeature {
93
+ const plan = FIXTURE_PLANS.development
94
+
95
+ return {
96
+ areaID: String(objectID),
97
+ authorityCode: FIXTURE_AUTHORITY.code,
98
+ authorityName: FIXTURE_AUTHORITY.name,
99
+ planID: plan.id,
100
+ planName: plan.name,
101
+ planLevel: plan.level,
102
+ planFrom: plan.from,
103
+ planTo: plan.to,
104
+ currentPlan: 1,
105
+ localCode: "R2 - Existing Residential",
106
+ localDescription: "Existing residential",
107
+ localCodeURL: "https://example.invalid/fixture-plan",
108
+ crosswalkCode: "R2",
109
+ crosswalkDescription: "Existing residential",
110
+ crosswalkRollup: "RE",
111
+ ...overrides,
112
+ // RESOLVED THROUGH THE REAL RESOLVER, never hand-assembled: a fixture that nested its own holes would test the
113
+ // assertion rather than the resolution, and the resolution is the part of this layer no sibling already has.
114
+ rings: resolveRingRoles(polygons, String(objectID)),
115
+ }
116
+ }
117
+
118
+ /**
119
+ * The fixture set: two adjacent zones, one of them holed the way this service encodes holes; a second plan over the
120
+ * SAME ground as the first; a zone smaller than a cell; and a zone the authority states as unzoned.
121
+ *
122
+ * THE OVERLAP BETWEEN PLANS IS THE POINT. A point inside the first zone must answer with BOTH rows, each naming its own
123
+ * plan — which is what proves a plan is part of the claim rather than a parameter of it.
124
+ */
125
+ export function fixtureFeatures(): ZoningSourceFeature[] {
126
+ const { lon, lat } = FIXTURE_ORIGIN
127
+
128
+ const zoneA = exteriorRing(lon, lat, lon + FIXTURE_SIDE, lat + FIXTURE_SIDE)
129
+ const zoneB = exteriorRing(lon + FIXTURE_SIDE, lat, lon + 2 * FIXTURE_SIDE, lat + FIXTURE_SIDE)
130
+
131
+ // THE HOLE IS A SEPARATE PART, not a nested ring — which is how the real service encodes it on the features that carry
132
+ // one, and the encoding a nesting-aware reader turns into a second zoned area.
133
+ const holed: MultiPolygonRings = [
134
+ [exteriorRing(lon, lat + 2 * FIXTURE_SIDE, lon + FIXTURE_SIDE, lat + 3 * FIXTURE_SIDE)],
135
+ [
136
+ holeRing(
137
+ lon + FIXTURE_SIDE * 0.35,
138
+ lat + 2 * FIXTURE_SIDE + FIXTURE_SIDE * 0.35,
139
+ lon + FIXTURE_SIDE * 0.65,
140
+ lat + 2 * FIXTURE_SIDE + FIXTURE_SIDE * 0.65
141
+ ),
142
+ ],
143
+ ]
144
+
145
+ // About 5.5 m across — smaller than a res-11 cell, let alone a res-9 one. `polygonToCells` returns nothing for a shape
146
+ // this size, so it is the fixture that proves the index takes cell-touches-polygon rather than centre-in-polygon.
147
+ const sliver = exteriorRing(lon + 3 * FIXTURE_SIDE, lat, lon + 3 * FIXTURE_SIDE + 0.00005, lat + 0.00005)
148
+
149
+ const unzoned = exteriorRing(lon + 4 * FIXTURE_SIDE, lat, lon + 5 * FIXTURE_SIDE, lat + FIXTURE_SIDE)
150
+
151
+ const localAreaPlan = FIXTURE_PLANS.localArea
152
+
153
+ return [
154
+ fixtureFeature(1, [[zoneA]]),
155
+ fixtureFeature(2, [[zoneB]], {
156
+ localCode: "C2.1 - Industrial",
157
+ localDescription: "Industrial, enterprise and employment",
158
+ crosswalkCode: "C2.1",
159
+ crosswalkDescription: "Industrial, enterprise, employment",
160
+ }),
161
+ fixtureFeature(3, holed, {
162
+ localCode: "G1 - Open Space",
163
+ localDescription: "Open space and park",
164
+ crosswalkCode: "G1",
165
+ crosswalkDescription: "Open space, park",
166
+ }),
167
+ fixtureFeature(4, [[sliver]], {
168
+ localCode: "N1.1 - Road",
169
+ localDescription: "Road reservation",
170
+ crosswalkCode: "N1.1",
171
+ crosswalkDescription: "Road",
172
+ }),
173
+ // The authority states unzoned land POSITIVELY, and uses a code its own domain never declares for it.
174
+ fixtureFeature(5, [[unzoned]], {
175
+ localCode: GZT_UNZONED_LOCAL_CODE,
176
+ localDescription: "Unzoned",
177
+ crosswalkCode: "N/A",
178
+ crosswalkDescription: null,
179
+ crosswalkRollup: "N/A",
180
+ }),
181
+ // The SAME ground as zone A under a second plan, and the same local code mapped to a DIFFERENT generic type — which
182
+ // is the shape that makes the crosswalk non-functional over an (authority, code) pair.
183
+ fixtureFeature(6, [[zoneA]], {
184
+ planID: localAreaPlan.id,
185
+ planName: localAreaPlan.name,
186
+ planLevel: localAreaPlan.level,
187
+ planFrom: localAreaPlan.from,
188
+ planTo: localAreaPlan.to,
189
+ crosswalkCode: "R3",
190
+ crosswalkDescription: "Residential, mixed residential and other uses",
191
+ }),
192
+ ]
193
+ }
194
+
195
+ /**
196
+ * A feature source over an explicit feature list.
197
+ */
198
+ export function fixtureSource(features: ZoningSourceFeature[]): ZoningFeatureSource {
199
+ return {
200
+ declaredFeatureCount: features.length,
201
+ epsg: GZT_SOURCE_EPSG,
202
+ origin: "fixture",
203
+ async *features() {
204
+ yield* features
205
+ },
206
+ }
207
+ }