@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,57 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * Acquire the Department's bulk GeoJSON export — a 247,452,342-byte file streamed to disk.
7
+ *
8
+ * THIS IS A FILE TRANSFER, NOT AN API REQUEST, AND IT KEEPS RAW `fetch` ON PURPOSE. The repo's rule sends
9
+ * HTTP clients through `@mailwoman/core/api`'s `APIClient`, and the rule draws its line at what that class
10
+ * is for: pacing, bounded retry, response caching and error mapping over small bodies and repeated calls.
11
+ * None of it applies here. Caching a 247 MB body through a JSON-validating disk cache would write a second,
12
+ * unreadable copy of a file already on disk; there is nothing to pace, because this runs once per product
13
+ * vintage; and axios buffers any non-stream response type in memory. `packages/osm/lib/sdk/fetch.ts`,
14
+ * `packages/tiger/lib/sdk/download.ts`, `packages/flood/lib/sdk/download.ts` and `packages/coastal/lib/sdk/download.ts`
15
+ * are the existing transfers that say the same thing in the same place. The JOB that produces this URL, and
16
+ * every other metadata read around it, DO go through `APIClient` — see `client.ts`.
17
+ *
18
+ * THE RESULT URL REDIRECTS AND THE FETCH MUST FOLLOW IT. The Hub download job answers
19
+ * `{"status":"Completed","resultUrl":…}`; the result URL itself 302s to the generated file. Node's `fetch`
20
+ * follows redirects by default, and the option is passed explicitly anyway — a transfer that stopped at the
21
+ * redirect would write a short body to disk and report a successful download.
22
+ *
23
+ * FRESHNESS IS THE ITEM'S OWN MODIFIED DATE, NEVER A LENGTH PROBE. The cache is keyed on the vintage the
24
+ * item declares, so a re-run against the same vintage never re-transfers and a new vintage never overwrites
25
+ * the old one in place.
26
+ */
27
+ import { tryStat } from "@mailwoman/core/fs/readers";
28
+ import { makeDirectories } from "@mailwoman/core/fs/writers";
29
+ import { streamToDisk } from "@mailwoman/core/utils";
30
+ import { join } from "path-ts";
31
+ /**
32
+ * The file name one vintage's export is kept under.
33
+ */
34
+ export const GZT_EXPORT_FILE = "gzt-current-plan.geojson";
35
+ /**
36
+ * Download the bulk export for one product vintage, returning the path of the GeoJSON file.
37
+ *
38
+ * Downloads to a `.part` file and renames only on a clean finish, so an interrupted transfer never presents as a
39
+ * complete export — the same discipline the database build uses, for the same reason.
40
+ */
41
+ export async function downloadZoningExport(options) {
42
+ const vintageDir = join(options.cacheRoot, options.vintage);
43
+ const exportPath = join(vintageDir, GZT_EXPORT_FILE);
44
+ if (await tryStat(exportPath)) {
45
+ options.onProgress?.(`export for ${options.vintage} already downloaded`);
46
+ return exportPath;
47
+ }
48
+ await makeDirectories(vintageDir);
49
+ await streamToDisk({
50
+ url: options.url,
51
+ destination: exportPath,
52
+ context: "zoning download",
53
+ ...(options.onProgress ? { onProgress: options.onProgress } : {}),
54
+ });
55
+ return exportPath;
56
+ }
57
+ //# sourceMappingURL=download.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"download.js","sourceRoot":"","sources":["../../lib/sdk/download.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAE9B;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,0BAA0B,CAAA;AAgBzD;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,OAAoC;IAC9E,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;IAC3D,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,EAAE,eAAe,CAAC,CAAA;IAEpD,IAAI,MAAM,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QAC/B,OAAO,CAAC,UAAU,EAAE,CAAC,cAAc,OAAO,CAAC,OAAO,qBAAqB,CAAC,CAAA;QAExE,OAAO,UAAU,CAAA;IAClB,CAAC;IAED,MAAM,eAAe,CAAC,UAAU,CAAC,CAAA;IAEjC,MAAM,YAAY,CAAC;QAClB,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,WAAW,EAAE,UAAU;QACvB,OAAO,EAAE,iBAAiB;QAC1B,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACjE,CAAC,CAAA;IAEF,OAAO,UAAU,CAAA;AAClB,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ * @file The acquisition + build surface for the Irish zoning layer. The READER is the package root.
6
+ */
7
+ export * from "#sdk/build-zoning";
8
+ export * from "#sdk/cells";
9
+ export * from "#sdk/client";
10
+ export * from "#sdk/download";
11
+ export * from "#sdk/ingest";
12
+ export * from "#sdk/ingest-chunk";
13
+ export * from "#sdk/measure-resolutions";
14
+ export * from "#sdk/verify";
15
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/sdk/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,mBAAmB,CAAA;AACjC,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,mBAAmB,CAAA;AACjC,cAAc,0BAA0B,CAAA;AACxC,cAAc,aAAa,CAAA"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ * @file The acquisition + build surface for the Irish zoning layer. The READER is the package root.
6
+ */
7
+ export * from "#sdk/build-zoning";
8
+ export * from "#sdk/cells";
9
+ export * from "#sdk/client";
10
+ export * from "#sdk/download";
11
+ export * from "#sdk/ingest";
12
+ export * from "#sdk/ingest-chunk";
13
+ export * from "#sdk/measure-resolutions";
14
+ export * from "#sdk/verify";
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/sdk/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,mBAAmB,CAAA;AACjC,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,mBAAmB,CAAA;AACjC,cAAc,0BAA0B,CAAA;AACxC,cAAc,aAAa,CAAA"}
@@ -0,0 +1,130 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * The streaming pass — every feature into `zoning_area` and into `zoning_cell` — as a unit of work that can
7
+ * run over PART of the source.
8
+ *
9
+ * WHY THIS IS A CHUNK RATHER THAN THE WHOLE FILE. h3's WASM heap cannot be reset from JavaScript, and it
10
+ * does not survive an unbounded number of polyfill calls: over a sibling product, runs died after roughly
11
+ * 510,000 and 798,000 features on geometry that classifies in milliseconds in a fresh process. A build that
12
+ * completes only when fragmentation happens to stay low is not a reproducible build, so the classification
13
+ * is bounded BY CONSTRUCTION — one process per range of the authority's own feature ids. This product's
14
+ * 85,330 features fit inside the default bound; the bound ships anyway, because determinism by construction
15
+ * is not the same fact as determinism by luck.
16
+ *
17
+ * THE VOCABULARY IS A CENSUS, NOT A CHECK. The declared generic-type domain is closed and the source
18
+ * already breaks it — `N/A` appears on 4 rows and in no domain — so an undeclared value is RECORDED as
19
+ * observed-but-undeclared rather than throwing. That is the opposite of the sibling layers' rule and it is
20
+ * the publisher's own doing: refusing here would refuse the Department's own data. What DOES throw is a
21
+ * blank local code, because the local code is the claim.
22
+ *
23
+ * THE CROSSWALK PAIRS ARE COUNTED HERE BECAUSE THEY ARE THE ARGUMENT FOR THE SCHEMA. If a local code
24
+ * determined a generic type, the mapping could ship as an edge table and the local column would be
25
+ * redundant. It does not: measured nationally, 52 of 795 (authority, local code) pairs take more than one
26
+ * generic type. The chunk reports the pairs it saw and the build refuses to write an edge table while any
27
+ * such pair exists, so the empty `zoning_crosswalk_edge` is a checked consequence rather than an omission.
28
+ *
29
+ * THE CHUNK OWNS NO ARTIFACT. It appends rows to a database the parent created and will seal, and returns
30
+ * counts the parent adds up. Chunks run one at a time against that file, so there is no concurrent writer
31
+ * and no locking to reason about. The jurisdiction, plan and vocabulary rows are RETURNED rather than
32
+ * written: they are per-chunk partials that have to be merged before insertion, and 30 authorities, 63
33
+ * plans and about 880 vocabulary rows cross a process boundary for nothing.
34
+ */
35
+ import type { DatabaseClient } from "@mailwoman/sqlite/client";
36
+ import type { ZoningDatabase } from "#schema";
37
+ import type { ZoningFeatureSource, ZoningSourceFeature } from "#sdk/ingest";
38
+ /**
39
+ * One observed vocabulary value: which scheme, which code, the publisher's own label for it, and how many rows carry
40
+ * it.
41
+ */
42
+ export type ObservedTerm = [scheme: string, code: string, label: string, rows: number];
43
+ /**
44
+ * One (authority, local code) pair and every generic type the publisher assigned to it.
45
+ */
46
+ export type CrosswalkPair = [authorityCode: string, localCode: string, crosswalkCodes: string[]];
47
+ /**
48
+ * What one chunk produced. Every field is JSON-serializable, because a chunk normally reports across a process
49
+ * boundary.
50
+ */
51
+ export interface ZoningChunkResult {
52
+ features: number;
53
+ /**
54
+ * Features whose bounding box forced a resolution coarser than the target.
55
+ */
56
+ coarsened: number;
57
+ /**
58
+ * Cell rows written, split by tier.
59
+ */
60
+ wholeCellRows: number;
61
+ partialCellRows: number;
62
+ /**
63
+ * `[coverageCell, polygonsReachingIt]` pairs — an array rather than a `Map` so it survives the process boundary.
64
+ */
65
+ observedByCoverageCell: Array<[number, number]>;
66
+ /**
67
+ * Square metres. `signed` is the raw ring sum as published; `nested` is the per-polygon hole-aware reading;
68
+ * `allExterior` is what the same rings say read WITHOUT their holes.
69
+ */
70
+ area: {
71
+ signedM2: number;
72
+ nestedM2: number;
73
+ allExteriorM2: number;
74
+ };
75
+ /**
76
+ * The ring-role census — the receipt that the orientation was read rather than assumed.
77
+ */
78
+ rings: {
79
+ total: number;
80
+ exteriors: number;
81
+ holes: number;
82
+ nestedHoles: number;
83
+ adjacentHoles: number;
84
+ /**
85
+ * Features whose exterior was chosen by MAGNITUDE because no ring read as one by orientation — measured at one of
86
+ * 85,330. See `ResolvedRingRoles.exteriorByMagnitude`.
87
+ */
88
+ exteriorByMagnitude: number;
89
+ };
90
+ /**
91
+ * The authorities this chunk saw, by their own code.
92
+ */
93
+ jurisdictions: Array<[code: string, name: string]>;
94
+ /**
95
+ * The plans this chunk saw.
96
+ */
97
+ plans: Array<{
98
+ planID: string;
99
+ authorityCode: string;
100
+ name: string;
101
+ level: string;
102
+ from: string | null;
103
+ to: string | null;
104
+ currentPlan: number;
105
+ }>;
106
+ vocabulary: ObservedTerm[];
107
+ crosswalkPairs: CrosswalkPair[];
108
+ }
109
+ export interface IngestZoningChunkOptions {
110
+ source: ZoningFeatureSource;
111
+ indexResolution: number;
112
+ coverageResolution: number;
113
+ onProgress?: (message: string) => void;
114
+ }
115
+ /**
116
+ * Stream one chunk of the source into `database`.
117
+ *
118
+ * @throws {Error} On a feature the classifier or the ring-role resolver refuses.
119
+ */
120
+ export declare function ingestZoningChunk(database: DatabaseClient<ZoningDatabase>, options: IngestZoningChunkOptions): Promise<ZoningChunkResult>;
121
+ /**
122
+ * One feature's own contribution, for a caller that wants the numbers without a database — the fixture rung's
123
+ * arithmetic and nothing else.
124
+ */
125
+ export declare function featureAreaReadings(feature: ZoningSourceFeature): {
126
+ signed: number;
127
+ nested: number;
128
+ allExterior: number;
129
+ };
130
+ //# sourceMappingURL=ingest-chunk.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ingest-chunk.d.ts","sourceRoot":"","sources":["../../lib/sdk/ingest-chunk.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;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CAAA;IAClD;;OAEG;IACH,KAAK,EAAE,KAAK,CAAC;QACZ,MAAM,EAAE,MAAM,CAAA;QACd,aAAa,EAAE,MAAM,CAAA;QACrB,IAAI,EAAE,MAAM,CAAA;QACZ,KAAK,EAAE,MAAM,CAAA;QACb,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;QACnB,EAAE,EAAE,MAAM,GAAG,IAAI,CAAA;QACjB,WAAW,EAAE,MAAM,CAAA;KACnB,CAAC,CAAA;IACF,UAAU,EAAE,YAAY,EAAE,CAAA;IAC1B,cAAc,EAAE,aAAa,EAAE,CAAA;CAC/B;AAED,MAAM,WAAW,wBAAwB;IACxC,MAAM,EAAE,mBAAmB,CAAA;IAC3B,eAAe,EAAE,MAAM,CAAA;IACvB,kBAAkB,EAAE,MAAM,CAAA;IAC1B,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;CACtC;AAED;;;;GAIG;AACH,wBAAsB,iBAAiB,CACtC,QAAQ,EAAE,cAAc,CAAC,cAAc,CAAC,EACxC,OAAO,EAAE,wBAAwB,GAC/B,OAAO,CAAC,iBAAiB,CAAC,CA6M5B;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,mBAAmB,GAAG;IAClE,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,WAAW,EAAE,MAAM,CAAA;CACnB,CAIA"}
@@ -0,0 +1,206 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * The streaming pass — every feature into `zoning_area` and into `zoning_cell` — as a unit of work that can
7
+ * run over PART of the source.
8
+ *
9
+ * WHY THIS IS A CHUNK RATHER THAN THE WHOLE FILE. h3's WASM heap cannot be reset from JavaScript, and it
10
+ * does not survive an unbounded number of polyfill calls: over a sibling product, runs died after roughly
11
+ * 510,000 and 798,000 features on geometry that classifies in milliseconds in a fresh process. A build that
12
+ * completes only when fragmentation happens to stay low is not a reproducible build, so the classification
13
+ * is bounded BY CONSTRUCTION — one process per range of the authority's own feature ids. This product's
14
+ * 85,330 features fit inside the default bound; the bound ships anyway, because determinism by construction
15
+ * is not the same fact as determinism by luck.
16
+ *
17
+ * THE VOCABULARY IS A CENSUS, NOT A CHECK. The declared generic-type domain is closed and the source
18
+ * already breaks it — `N/A` appears on 4 rows and in no domain — so an undeclared value is RECORDED as
19
+ * observed-but-undeclared rather than throwing. That is the opposite of the sibling layers' rule and it is
20
+ * the publisher's own doing: refusing here would refuse the Department's own data. What DOES throw is a
21
+ * blank local code, because the local code is the claim.
22
+ *
23
+ * THE CROSSWALK PAIRS ARE COUNTED HERE BECAUSE THEY ARE THE ARGUMENT FOR THE SCHEMA. If a local code
24
+ * determined a generic type, the mapping could ship as an edge table and the local column would be
25
+ * redundant. It does not: measured nationally, 52 of 795 (authority, local code) pairs take more than one
26
+ * generic type. The chunk reports the pairs it saw and the build refuses to write an edge table while any
27
+ * such pair exists, so the empty `zoning_crosswalk_edge` is a checked consequence rather than an omission.
28
+ *
29
+ * THE CHUNK OWNS NO ARTIFACT. It appends rows to a database the parent created and will seal, and returns
30
+ * counts the parent adds up. Chunks run one at a time against that file, so there is no concurrent writer
31
+ * and no locking to reason about. The jurisdiction, plan and vocabulary rows are RETURNED rather than
32
+ * written: they are per-chunk partials that have to be merged before insertion, and 30 authorities, 63
33
+ * plans and about 880 vocabulary rows cross a process boundary for nothing.
34
+ */
35
+ import { addCoverageCells, encodeRings, ringAreaReadings, ringsBoundingBox } from "@mailwoman/spatial";
36
+ import { beginBatched } from "@mailwoman/sqlite/batched";
37
+ import { classifyFeatureCells, featureCellRows } from "#sdk/cells";
38
+ import { GZT_CROSSWALK_SCHEME, GZT_PROVENANCE_GRADE, GZT_ROLLUP_SCHEME, localSchemeFor } from "#vocabulary";
39
+ /**
40
+ * Rows per bulk-insert transaction. Chosen for the geometry table, whose rows carry a blob: a larger transaction grows
41
+ * the write-ahead file without improving throughput.
42
+ */
43
+ const INSERT_TRANSACTION_ROWS = 5000;
44
+ /**
45
+ * Features between progress reports.
46
+ */
47
+ const PROGRESS_STRIDE = 5000;
48
+ /**
49
+ * Stream one chunk of the source into `database`.
50
+ *
51
+ * @throws {Error} On a feature the classifier or the ring-role resolver refuses.
52
+ */
53
+ export async function ingestZoningChunk(database, options) {
54
+ const insertArea = database.prepare("INSERT INTO zoning_area (area_id, jurisdiction_id, plan_id, local_code, local_description, local_code_url, " +
55
+ "crosswalk_code, crosswalk_scheme, crosswalk_description, crosswalk_rollup, provenance_grade, " +
56
+ "min_lat, min_lon, max_lat, max_lon, ring_count, signed_area_m2, rings) " +
57
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
58
+ const insertCell = database.prepare("INSERT INTO zoning_cell (h3_cell, resolution, area_id, containment) VALUES (?, ?, ?, ?)");
59
+ const observedByCoverageCell = new Map();
60
+ const jurisdictions = new Map();
61
+ const plans = new Map();
62
+ // KEYED ON A NUL-JOINED PAIR AND NEVER SPLIT BACK APART. A local code is free text that routinely contains spaces —
63
+ // `Special Policy Area`, `RA - Rural Area` — so a key a reader had to re-split would mangle exactly the vocabulary
64
+ // this layer exists to carry verbatim. The parts ride on the value instead.
65
+ const vocabulary = new Map();
66
+ const crosswalkPairs = new Map();
67
+ let features = 0;
68
+ let coarsened = 0;
69
+ let wholeCellRows = 0;
70
+ let partialCellRows = 0;
71
+ let signedArea = 0;
72
+ let nestedArea = 0;
73
+ let allExteriorArea = 0;
74
+ let ringsTotal = 0;
75
+ let exteriors = 0;
76
+ let holes = 0;
77
+ let nestedHoles = 0;
78
+ let exteriorByMagnitude = 0;
79
+ let adjacentHoles = 0;
80
+ /**
81
+ * Record one observed vocabulary value. The FIRST label wins, because a later row's description is the publisher's
82
+ * word for the same code and choosing between them would be this package editing the publisher's vocabulary.
83
+ */
84
+ const observe = (scheme, code, label) => {
85
+ const key = `${scheme}\u0000${code}`;
86
+ const existing = vocabulary.get(key);
87
+ if (existing) {
88
+ existing.rows++;
89
+ return;
90
+ }
91
+ vocabulary.set(key, { scheme, code, label, rows: 1 });
92
+ };
93
+ const batch = beginBatched(database, { rowsPerCommit: INSERT_TRANSACTION_ROWS });
94
+ try {
95
+ for await (const feature of options.source.features()) {
96
+ const bbox = ringsBoundingBox(feature.rings.polygons);
97
+ const areas = ringAreaReadings(feature.rings.polygons);
98
+ signedArea += feature.rings.signedAreaM2;
99
+ nestedArea += areas.nested;
100
+ allExteriorArea += areas.allExterior;
101
+ ringsTotal += feature.rings.ringCount;
102
+ exteriors += feature.rings.exteriorCount;
103
+ holes += feature.rings.holeCount;
104
+ nestedHoles += feature.rings.nestedHoles;
105
+ exteriorByMagnitude += feature.rings.exteriorByMagnitude;
106
+ adjacentHoles += feature.rings.adjacentHoles;
107
+ insertArea.run(feature.areaID, feature.authorityCode, feature.planID, feature.localCode, feature.localDescription, feature.localCodeURL, feature.crosswalkCode, feature.crosswalkCode === null ? null : GZT_CROSSWALK_SCHEME, feature.crosswalkDescription, feature.crosswalkRollup,
108
+ // ONE GRADE PER CLAIM. Every row of THIS artifact is `authoritative` — a government department republishing
109
+ // local authorities' adopted plans — and an observed land-use layer is a different database with a different
110
+ // `layer_manifest.name`, never a row with a second grade in this table.
111
+ GZT_PROVENANCE_GRADE, bbox.minLat, bbox.minLon, bbox.maxLat, bbox.maxLon, feature.rings.ringCount, feature.rings.signedAreaM2, encodeRings(feature.rings.polygons));
112
+ const classified = classifyFeatureCells(feature.rings.polygons, options.indexResolution, feature.areaID, "zoning cells");
113
+ if (classified.resolution !== options.indexResolution) {
114
+ coarsened++;
115
+ }
116
+ for (const row of featureCellRows(classified)) {
117
+ insertCell.run(row.h3Cell, row.resolution, feature.areaID, row.containment);
118
+ if (row.containment === "whole") {
119
+ wholeCellRows++;
120
+ }
121
+ else {
122
+ partialCellRows++;
123
+ }
124
+ }
125
+ // COVERAGE IS DERIVED FROM THE UNCOMPACTED CLASSIFICATION, not from the stored rows. A compacted parent spans
126
+ // several coverage cells and `addCoverageCells` handles that, but the fringe is where this product's cells almost
127
+ // all are — so counting off the stored rows and counting off the classification agree here, and the classification
128
+ // is the one that cannot be changed by a compaction decision.
129
+ const coverageCells = new Set();
130
+ for (const cell of classified.whole) {
131
+ addCoverageCells(coverageCells, cell, classified.resolution, options.coverageResolution);
132
+ }
133
+ for (const cell of classified.partial) {
134
+ addCoverageCells(coverageCells, cell, classified.resolution, options.coverageResolution);
135
+ }
136
+ for (const coverageCell of coverageCells) {
137
+ observedByCoverageCell.set(coverageCell, (observedByCoverageCell.get(coverageCell) ?? 0) + 1);
138
+ }
139
+ jurisdictions.set(feature.authorityCode, feature.authorityName);
140
+ if (!plans.has(feature.planID)) {
141
+ plans.set(feature.planID, {
142
+ planID: feature.planID,
143
+ authorityCode: feature.authorityCode,
144
+ name: feature.planName,
145
+ level: feature.planLevel,
146
+ from: feature.planFrom,
147
+ to: feature.planTo,
148
+ currentPlan: feature.currentPlan,
149
+ });
150
+ }
151
+ // The local vocabulary is per AUTHORITY, because the codes collide across them: `Residential` means one thing in
152
+ // Cork County Council's plan and another in Westmeath's.
153
+ observe(localSchemeFor(feature.authorityCode), feature.localCode, feature.localDescription ?? feature.localCode);
154
+ if (feature.crosswalkCode !== null) {
155
+ observe(GZT_CROSSWALK_SCHEME, feature.crosswalkCode, feature.crosswalkDescription ?? feature.crosswalkCode);
156
+ const key = `${feature.authorityCode}\u0000${feature.localCode}`;
157
+ const pair = crosswalkPairs.get(key);
158
+ if (pair) {
159
+ pair.codes.add(feature.crosswalkCode);
160
+ }
161
+ else {
162
+ crosswalkPairs.set(key, {
163
+ authorityCode: feature.authorityCode,
164
+ localCode: feature.localCode,
165
+ codes: new Set([feature.crosswalkCode]),
166
+ });
167
+ }
168
+ }
169
+ if (feature.crosswalkRollup !== null) {
170
+ observe(GZT_ROLLUP_SCHEME, feature.crosswalkRollup, feature.crosswalkRollup);
171
+ }
172
+ features++;
173
+ batch.rowWritten();
174
+ if (features % PROGRESS_STRIDE === 0) {
175
+ options.onProgress?.(`${features.toLocaleString()} features in this chunk`);
176
+ }
177
+ }
178
+ batch.commit();
179
+ }
180
+ catch (error) {
181
+ batch.rollbackQuietly();
182
+ throw error;
183
+ }
184
+ return {
185
+ features,
186
+ coarsened,
187
+ wholeCellRows,
188
+ partialCellRows,
189
+ observedByCoverageCell: [...observedByCoverageCell],
190
+ area: { signedM2: signedArea, nestedM2: nestedArea, allExteriorM2: allExteriorArea },
191
+ rings: { total: ringsTotal, exteriors, holes, nestedHoles, adjacentHoles, exteriorByMagnitude },
192
+ jurisdictions: [...jurisdictions],
193
+ plans: [...plans.values()],
194
+ vocabulary: [...vocabulary.values()].map((term) => [term.scheme, term.code, term.label, term.rows]),
195
+ crosswalkPairs: [...crosswalkPairs.values()].map((pair) => [pair.authorityCode, pair.localCode, [...pair.codes].toSorted()]),
196
+ };
197
+ }
198
+ /**
199
+ * One feature's own contribution, for a caller that wants the numbers without a database — the fixture rung's
200
+ * arithmetic and nothing else.
201
+ */
202
+ export function featureAreaReadings(feature) {
203
+ const areas = ringAreaReadings(feature.rings.polygons);
204
+ return { signed: feature.rings.signedAreaM2, nested: areas.nested, allExterior: areas.allExterior };
205
+ }
206
+ //# sourceMappingURL=ingest-chunk.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ingest-chunk.js","sourceRoot":"","sources":["../../lib/sdk/ingest-chunk.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACtG,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAIxD,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAElE,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,iBAAiB,EA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G,CAAC"}
@@ -0,0 +1,191 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * Read the Department's bulk export as a stream of WGS84 features, through ogr2ogr.
7
+ *
8
+ * OGR IS BUILD TOOLING, NEVER A SERVE DEPENDENCY (SCOPE invariant 6). It converts the authority's geometry
9
+ * into the structure the runtime probes, and nothing downstream of this module knows GDAL exists.
10
+ *
11
+ * THE STREAM IS WKT, NOT GEOJSON, AND THAT IS A CORRECTNESS CHOICE RATHER THAN A TASTE ONE. This service
12
+ * encodes hole roles by ring ORIENTATION — clockwise exterior, the inverse of RFC 7946 — and puts each ring
13
+ * in its own `MultiPolygon` part on the features that carry holes that way. GDAL's GeoJSON writer enforces
14
+ * the RFC 7946 winding unconditionally: `-lco RFC7946=NO` is not a GeoJSONSeq option, and
15
+ * `--config OGR_ORGANIZE_POLYGONS SKIP` changes nothing. Measured on the largest feature in the country,
16
+ * Meath's `RA - Rural Area`: through GeoJSONSeq it arrives as 107 counter-clockwise rings totalling
17
+ * 2,371.9 km², through CSV/WKT as the source's own 5 clockwise and 102 counter-clockwise totalling
18
+ * 2,223.1 km² against the Department's published 2,232.1 km². The GeoJSON path has silently turned 102
19
+ * holes into 102 zoned areas.
20
+ *
21
+ * AND THE TRANSPORT IS NOT THE SLOW HALF. Measured on this lab over the whole national export: ogr2ogr
22
+ * reprojects to 224,066,621 bytes of WKT CSV in 13.2 s, and `CSVSpliterator` plus the WKT parse reads
23
+ * 85,330 rows, 93,483 rings and 6,327,256 positions back out of it in 2.2 s.
24
+ *
25
+ * THE SOURCE IS NOT IN WGS84 AND SAYING SO IS THE CHECK. The bulk export is IRENET95 / Irish Transverse
26
+ * Mercator — metres, easting/northing, EPSG:2157 — declared in a top-level `crs` member RFC 7946 removed
27
+ * from the format. GDAL honours the legacy member; a strict reader ignores it and places Ireland's zoning
28
+ * at latitude 735,435. So the projection is asserted against the source's declared authority code before a
29
+ * single feature is read, and every reprojected vertex is asserted inside the Department's own declared
30
+ * extent — which is the check that catches a coordinate-order mistake the projection check cannot see.
31
+ *
32
+ * THE DATUM SHIFT NEEDS A GRID, AND ITS ABSENCE IS SILENT. PROJ substitutes a ballpark offset when the
33
+ * accurate transformation is unavailable and produces coordinates that are metres wrong and
34
+ * indistinguishable from correct ones. {@linkcode assertDatumTransformationAvailable} asks `projinfo` what
35
+ * PROJ would choose and refuses a ballpark; for this source it names
36
+ * `Inverse of Irish Transverse Mercator + IRENET95 to WGS 84 (1), 1 m`.
37
+ *
38
+ * THE PUBLISHER'S OWN AREA COLUMN IS NOT IN THE ARCHIVE. `Shape__Area` is a service field and the export
39
+ * drops it, so the area cross-check reads it from the live service instead — which makes it a genuine
40
+ * two-path check rather than the archive agreeing with itself. See `sdk/client.ts`.
41
+ */
42
+ import { type ResolvedRingRoles } from "#rings";
43
+ /**
44
+ * The ring types and the PROJ guard, both re-exported from `@mailwoman/spatial`: neither is zoning-specific, and a
45
+ * second copy of the `projinfo` parse would be a second place for the ballpark check to stop refusing.
46
+ */
47
+ export { assessDatumTransformation, type DatumTransformationVerdict } from "@mailwoman/spatial/projection-transform";
48
+ export type { MultiPolygonRings, PolygonRings } from "#rings";
49
+ /**
50
+ * One zoning feature, reprojected to WGS84 with its hole roles resolved.
51
+ */
52
+ export interface ZoningSourceFeature {
53
+ /**
54
+ * The authority's own `OBJECTID`, as a string.
55
+ */
56
+ areaID: string;
57
+ /**
58
+ * `LA_CODE`, verbatim — `Fl` for Fingal, and never repaired.
59
+ */
60
+ authorityCode: string;
61
+ authorityName: string;
62
+ planID: string;
63
+ planName: string;
64
+ planLevel: string;
65
+ planFrom: string | null;
66
+ planTo: string | null;
67
+ currentPlan: number;
68
+ /**
69
+ * `ZONE_ORIG`, verbatim, including case and any trailing space.
70
+ */
71
+ localCode: string;
72
+ localDescription: string | null;
73
+ localCodeURL: string | null;
74
+ /**
75
+ * `ZONE_GZT` — the Department's national generic type for THIS polygon.
76
+ */
77
+ crosswalkCode: string | null;
78
+ crosswalkDescription: string | null;
79
+ /**
80
+ * `SZO` — the coarser national code, as published.
81
+ */
82
+ crosswalkRollup: string | null;
83
+ /**
84
+ * The rings, with hole roles resolved from orientation, plus the receipt of that resolution.
85
+ */
86
+ rings: ResolvedRingRoles;
87
+ }
88
+ /**
89
+ * What the ingest was pointed at.
90
+ */
91
+ export interface ZoningIngestOptions {
92
+ /**
93
+ * Path to the bulk GeoJSON export.
94
+ */
95
+ exportPath: string;
96
+ /**
97
+ * Stop after this many features — the fixtures and smoke rungs use it; a full build does not set it.
98
+ */
99
+ limit?: number;
100
+ /**
101
+ * The EPSG code the source must declare. A source declaring anything else is a product change, not a variation to
102
+ * absorb.
103
+ */
104
+ expectEPSG?: number;
105
+ /**
106
+ * The extent every reprojected vertex must land inside. Defaults to the Department's own declaration.
107
+ */
108
+ declaredBBox?: readonly [number, number, number, number];
109
+ /**
110
+ * Read only the authority's feature ids in `[objectIDFrom, objectIDTo]`, inclusive.
111
+ *
112
+ * This is what makes a bounded build possible: h3's WASM heap cannot be reset from JavaScript, so the classification
113
+ * runs one child process per range of the authority's OWN ids. Ranges rather than an offset because `OBJECTID` is the
114
+ * source's stable key — a range names the same features on every run, which an offset into a result set does not.
115
+ *
116
+ * A NARROWER RANGE COSTS A WHOLE PASS. The source is one GeoJSON document rather than an indexed store, so ogr2ogr
117
+ * scans all 247 MB for every range. The national set fits inside one chunk at the default bound, so that cost is not
118
+ * paid on a full build.
119
+ */
120
+ objectIDFrom?: number;
121
+ objectIDTo?: number;
122
+ /**
123
+ * Restrict to one local authority's own `LA_CODE` — the smoke rung.
124
+ */
125
+ authorityCode?: string;
126
+ }
127
+ /**
128
+ * What the source declares about itself, read before any feature is.
129
+ */
130
+ export interface ZoningSourceIdentity {
131
+ epsg: number;
132
+ featureCount: number;
133
+ layer: string;
134
+ /**
135
+ * The source's own attribute field names. A `-select` naming a column this set does not hold makes ogr2ogr write an
136
+ * empty column rather than refuse, so the query is built from the set rather than from a schema read off a sibling
137
+ * publication.
138
+ */
139
+ fields: ReadonlySet<string>;
140
+ }
141
+ /**
142
+ * The attribute columns the ingest reads. Every one is required: this product publishes a single schema, and a column
143
+ * that vanished would be a product change rather than a variation to absorb.
144
+ */
145
+ export declare const ZONING_SOURCE_FIELDS: ReadonlyArray<string>;
146
+ /**
147
+ * What the source declares about itself: its authority code, its feature count and its field list.
148
+ *
149
+ * @throws {Error} When the export is unreadable, its declared EPSG is not `expectEPSG`, or it is missing a field the
150
+ * ingest reads.
151
+ */
152
+ export declare function readZoningSourceIdentity(options: ZoningIngestOptions): Promise<ZoningSourceIdentity>;
153
+ /**
154
+ * Stream the export through ogr2ogr as reprojected WKT, checking every vertex against the declared extent.
155
+ *
156
+ * A swapped coordinate order survives a projection check — both axes are still numbers in a plausible range — and shows
157
+ * up here immediately, before 85,330 polygons are written to the wrong side of the planet.
158
+ *
159
+ * @throws {Error} When ogr2ogr fails, when a feature carries no geometry, when a reprojected vertex falls outside the
160
+ * declared extent, or when a feature's rings cannot be resolved into at least one exterior.
161
+ */
162
+ export declare function readZoningFeatures(options: ZoningIngestOptions): AsyncGenerator<ZoningSourceFeature>;
163
+ /**
164
+ * Where a build's features come from, and what the source declares about itself.
165
+ *
166
+ * The builder takes ONE of these rather than a path, which is what makes the fixture rung possible: hand-built geometry
167
+ * with no network and no GDAL still exercises the whole database half — the domain checks, the ring-role resolution,
168
+ * the cell classification, the coverage rows, the manifest and the seal. A fixture rung that could only run through
169
+ * ogr2ogr would test the conversion on the machines that have it and nothing at all on the ones that do not.
170
+ */
171
+ export interface ZoningFeatureSource {
172
+ /**
173
+ * What the source says it holds. The build compares its own streamed total against this, so a short read throws
174
+ * instead of building a smaller country.
175
+ */
176
+ declaredFeatureCount: number;
177
+ epsg: number;
178
+ /**
179
+ * A description of where these features came from, for the receipt.
180
+ */
181
+ origin: string;
182
+ features: () => AsyncIterable<ZoningSourceFeature>;
183
+ }
184
+ export interface ExportSourceOptions extends ZoningIngestOptions {
185
+ declaredFeatureCount?: number;
186
+ }
187
+ /**
188
+ * The bulk export as a feature source — identity read up front, features streamed on demand.
189
+ */
190
+ export declare function createExportFeatureSource(options: ExportSourceOptions): Promise<ZoningFeatureSource>;
191
+ //# sourceMappingURL=ingest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ingest.d.ts","sourceRoot":"","sources":["../../lib/sdk/ingest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAQH,OAAO,EAA4C,KAAK,iBAAiB,EAAE,MAAM,QAAQ,CAAA;AAGzF;;;GAGG;AACH,OAAO,EAAE,yBAAyB,EAAE,KAAK,0BAA0B,EAAE,MAAM,yCAAyC,CAAA;AACpH,YAAY,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AAE7D;;GAEG;AACH,MAAM,WAAW,mBAAmB;IACnC;;OAEG;IACH,MAAM,EAAE,MAAM,CAAA;IACd;;OAEG;IACH,aAAa,EAAE,MAAM,CAAA;IACrB,aAAa,EAAE,MAAM,CAAA;IACrB,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;IACrB,WAAW,EAAE,MAAM,CAAA;IACnB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAA;IACjB,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAA;IAC/B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B;;OAEG;IACH,aAAa,EAAE,MAAM,GAAG,IAAI,CAAA;IAC5B,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAA;IACnC;;OAEG;IACH,eAAe,EAAE,MAAM,GAAG,IAAI,CAAA;IAC9B;;OAEG;IACH,KAAK,EAAE,iBAAiB,CAAA;CACxB;AAED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