@mailwoman/zoning 10.0.0 → 10.1.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 +89 -120
- package/lib/paths.ts +24 -0
- package/lib/ring-roles.ts +30 -71
- package/lib/rings.ts +2 -13
- package/lib/schema.ts +96 -114
- package/lib/vocabulary.ts +52 -130
- package/out/index.d.ts +75 -95
- package/out/index.d.ts.map +1 -1
- package/out/index.js +25 -82
- 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 +93 -108
- package/out/schema.d.ts.map +1 -1
- package/out/schema.js +16 -44
- 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 +47 -136
- package/out/sdk/build-zoning.js.map +1 -1
- package/out/sdk/cells.d.ts +20 -61
- package/out/sdk/cells.d.ts.map +1 -1
- package/out/sdk/cells.js +13 -50
- 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 +7 -27
- 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 +16 -49
- 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} +5 -7
- package/out/sdk/ingest/worker.js.map +1 -0
- package/out/sdk/ingest.d.ts +162 -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 -24
- package/out/sdk/measure-resolutions.d.ts.map +1 -1
- package/out/sdk/measure-resolutions.js +5 -22
- 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 +74 -56
- package/out/sdk/verify.d.ts.map +1 -1
- package/out/sdk/verify.js +70 -57
- 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 +37 -161
- package/{lib/sdk → sdk}/build-zoning.ts +99 -185
- package/{lib/sdk → sdk}/cells.ts +24 -63
- package/{lib/sdk → sdk}/client.ts +34 -82
- package/sdk/download.ts +58 -0
- package/{lib/sdk → sdk}/ingest/chunk.ts +33 -62
- package/{lib/scripts/ingest-chunk.ts → sdk/ingest/worker.ts} +4 -6
- package/sdk/ingest.ts +366 -0
- package/{lib/sdk → sdk}/measure-resolutions.ts +9 -26
- package/{lib → sdk}/test-kit.ts +21 -44
- package/{lib/sdk → sdk}/verify.ts +102 -75
- package/lib/sdk/download.ts +0 -78
- package/lib/sdk/index.ts +0 -15
- package/lib/sdk/ingest/index.ts +0 -393
- 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
package/lib/ring-roles.ts
CHANGED
|
@@ -3,32 +3,8 @@
|
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* THE SERVICE ENCODES HOLE ROLES BY ORIENTATION RATHER THAN BY NESTING, AND IT DOES IT ON MOST FEATURES.
|
|
10
|
-
* Measured over the whole national export (85,330 features, 93,483 rings): 89,967 rings are clockwise and
|
|
11
|
-
* 3,516 counter-clockwise; 84,021 features are wholly clockwise; and 1,309 features carry both windings.
|
|
12
|
-
* Of those, 1,210 nest their holes inside one polygon part the way RFC 7946 expects, and the rest put every
|
|
13
|
-
* ring in its own `MultiPolygon` part — the largest feature in the country, Meath's `RA - Rural Area`,
|
|
14
|
-
* arrives as 107 single-ring parts of which 5 are clockwise and 102 counter-clockwise. So the source uses
|
|
15
|
-
* BOTH encodings, the orientation is the only signal common to them, and a reader that took the nesting at
|
|
16
|
-
* face value would read 102 holes as 102 separate zoned areas.
|
|
17
|
-
*
|
|
18
|
-
* CLOCKWISE IS EXTERIOR, WHICH IS THE INVERSE OF RFC 7946, AND THE PUBLISHER'S OWN ARITHMETIC PROVES IT.
|
|
19
|
-
* Summing every ring's signed area over the export gives 5,444.492956 km²; the Department's own
|
|
20
|
-
* `Shape__Area` column sums to 5,444.492956 km². Summing the same rings' ABSOLUTE areas gives 5,666.569
|
|
21
|
-
* km². The signed reading matches the publisher to eight significant figures and the absolute one is 4.1%
|
|
22
|
-
* too large, so the counter-clockwise rings subtract under the publisher's own accounting: they are holes.
|
|
23
|
-
*
|
|
24
|
-
* THE HARMLESS HALF OF GETTING IT WRONG IS THE AREA. The harmful half is that a ray cast reading all 107 of
|
|
25
|
-
* Meath's rings as exteriors answers "inside `P5` rural zoning" for every location the plan carved out.
|
|
26
|
-
*
|
|
27
|
-
* AND GDAL CANNOT BE ASKED TO PRESERVE THIS. Its GeoJSON writer enforces the RFC 7946 winding
|
|
28
|
-
* unconditionally — `-lco RFC7946=NO` is not a GeoJSONSeq option and `--config OGR_ORGANIZE_POLYGONS SKIP`
|
|
29
|
-
* changes nothing — so a reprojected GeoJSON stream returns Meath as 107 counter-clockwise exteriors
|
|
30
|
-
* totalling 2,371.9 km² against the Department's 2,232.1 km². The same conversion written as WKT keeps the
|
|
31
|
-
* source's 5/102 split intact, which is why `sdk/ingest.ts` streams WKT.
|
|
6
|
+
* Clockwise is exterior — the inverse of RFC 7946 — because the service encodes hole roles by
|
|
7
|
+
* orientation rather than nesting.
|
|
32
8
|
*/
|
|
33
9
|
|
|
34
10
|
import { pointInRing, ringSignedAreaM2, type MultiPolygonRings } from "@mailwoman/spatial"
|
|
@@ -36,11 +12,9 @@ import { pointInRing, ringSignedAreaM2, type MultiPolygonRings } from "@mailwoma
|
|
|
36
12
|
/**
|
|
37
13
|
* How many of a hole's vertices are tested against a candidate exterior.
|
|
38
14
|
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* is a degenerate sliver of between 0.0008 m² and 1.7 m², and the publisher's own area accounting subtracts all of
|
|
43
|
-
* them.
|
|
15
|
+
* A hole and its exterior share vertices.
|
|
16
|
+
* One vertex cannot distinguish them.
|
|
17
|
+
* A ray cast on an edge is implementation-defined.
|
|
44
18
|
*/
|
|
45
19
|
const HOLE_VERTEX_SAMPLES = 9
|
|
46
20
|
|
|
@@ -49,7 +23,8 @@ const HOLE_VERTEX_SAMPLES = 9
|
|
|
49
23
|
*/
|
|
50
24
|
export interface ResolvedRingRoles {
|
|
51
25
|
/**
|
|
52
|
-
* `[exterior, ...holes]` per polygon
|
|
26
|
+
* `[exterior, ...holes]` per polygon.
|
|
27
|
+
* The shape the ring blob stores and the point test reads.
|
|
53
28
|
*/
|
|
54
29
|
polygons: MultiPolygonRings
|
|
55
30
|
exteriorCount: number
|
|
@@ -59,43 +34,31 @@ export interface ResolvedRingRoles {
|
|
|
59
34
|
*/
|
|
60
35
|
nestedHoles: number
|
|
61
36
|
/**
|
|
62
|
-
* Holes
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* carried rather than dropped: the publisher's own area accounting subtracts them, so dropping one would add ground
|
|
66
|
-
* the plan carved out, and a feature with exactly one exterior — 8 of the 9 — has no ambiguity at all.
|
|
37
|
+
* Holes no exterior contains a majority of, placed under the smallest exterior
|
|
38
|
+
* of the same feature and counted here: they are retained rather than dropped,
|
|
39
|
+
* because dropping one would add ground the plan carved out.
|
|
67
40
|
*/
|
|
68
41
|
adjacentHoles: number
|
|
69
42
|
/**
|
|
70
|
-
* `1` where the feature's exterior was chosen by
|
|
43
|
+
* `1` where the feature's exterior was chosen by magnitude because no ring read as one by orientation.
|
|
71
44
|
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
* stated: the same ring reads clockwise in the source's own Irish Transverse Mercator metres and counter-clockwise
|
|
76
|
-
* after reprojection. Refusing it would fail the build on the publisher's own data; dropping it would invent an
|
|
77
|
-
* absence. So the largest ring by magnitude becomes the exterior, which is also the correct reading for a feature
|
|
78
|
-
* published wholly inverted, and the count rides on the receipt rather than being implied to be zero.
|
|
45
|
+
* The largest ring becomes the exterior.
|
|
46
|
+
* This also handles a feature published wholly inverted.
|
|
47
|
+
* The receipt reports the count explicitly.
|
|
79
48
|
*/
|
|
80
49
|
exteriorByMagnitude: number
|
|
81
50
|
/**
|
|
82
|
-
* The signed ring sum over the source's rings
|
|
83
|
-
* clockwise-exterior convention.
|
|
84
|
-
*
|
|
85
|
-
* The ingest's own receipt, stored on the row. It is what the build compares against the Department's `Shape__Area`
|
|
86
|
-
* sum, and its SIGN is the record that the orientation was read: a source that started publishing counter-clockwise
|
|
87
|
-
* exteriors would flip it, which is a fact about the source rather than a rounding difference.
|
|
51
|
+
* The signed ring sum over the source's rings as published, in square meters,
|
|
52
|
+
* positive under this service's clockwise-exterior convention.
|
|
53
|
+
* Its sign is the record that the orientation was read.
|
|
88
54
|
*/
|
|
89
55
|
signedAreaM2: number
|
|
90
56
|
ringCount: number
|
|
91
57
|
}
|
|
92
58
|
|
|
93
59
|
/**
|
|
94
|
-
* Flatten a feature's rings,
|
|
95
|
-
*
|
|
96
|
-
* DELIBERATELY DISCARDS THE ARRIVING NESTING. Both encodings reach here — a properly nested polygon and a pile of
|
|
97
|
-
* single-ring parts — and the orientation is the only signal that means the same thing in both. Keeping the nesting for
|
|
98
|
-
* the features that have it and inferring it for the ones that do not would put two rules over one artifact.
|
|
60
|
+
* Flatten a feature's rings, discarding the arriving nesting because orientation is
|
|
61
|
+
* the only signal that means the same thing in both encodings.
|
|
99
62
|
*/
|
|
100
63
|
function flattenRings(polygons: MultiPolygonRings): ReadonlyArray<ReadonlyArray<readonly number[]>> {
|
|
101
64
|
const rings: Array<ReadonlyArray<readonly number[]>> = []
|
|
@@ -132,10 +95,8 @@ function containsMajority(ring: ReadonlyArray<readonly number[]>, outer: Readonl
|
|
|
132
95
|
/**
|
|
133
96
|
* Resolve one feature's hole roles from ring orientation.
|
|
134
97
|
*
|
|
135
|
-
* @param featureID
|
|
136
|
-
* @throws {Error} When the feature
|
|
137
|
-
* nothing reads downstream as an absence of zoning, which is the one answer this layer must never invent. A feature
|
|
138
|
-
* whose rings all read as holes DOES have a reading — see {@link ResolvedRingRoles.exteriorByMagnitude}.
|
|
98
|
+
* @param featureID Included in every refusal, so a build log identifies which feature failed.
|
|
99
|
+
* @throws {Error} When the feature has no ring at all, the one case with no reading.
|
|
139
100
|
*/
|
|
140
101
|
export function resolveRingRoles(polygons: MultiPolygonRings, featureID: string): ResolvedRingRoles {
|
|
141
102
|
const rings = flattenRings(polygons)
|
|
@@ -159,8 +120,10 @@ export function resolveRingRoles(polygons: MultiPolygonRings, featureID: string)
|
|
|
159
120
|
|
|
160
121
|
signedAreaM2 += signed
|
|
161
122
|
|
|
162
|
-
//
|
|
163
|
-
//
|
|
123
|
+
// `ringSignedAreaM2` signs clockwise positive.
|
|
124
|
+
// This service treats clockwise rings as exteriors.
|
|
125
|
+
// A zero-area ring is degenerate and stays a hole.
|
|
126
|
+
// It cannot enclose anything.
|
|
164
127
|
if (signed > 0) {
|
|
165
128
|
exteriors.push({ ring, area: signed, holes: [] })
|
|
166
129
|
} else {
|
|
@@ -170,10 +133,7 @@ export function resolveRingRoles(polygons: MultiPolygonRings, featureID: string)
|
|
|
170
133
|
|
|
171
134
|
let exteriorByMagnitude = 0
|
|
172
135
|
|
|
173
|
-
//
|
|
174
|
-
// the one that encloses the area, which is the correct reading both for a degenerate sliver whose winding is
|
|
175
|
-
// floating-point noise and for a feature published wholly inverted. Refusing here would fail the build on the
|
|
176
|
-
// publisher's own data, and skipping the feature would invent an absence.
|
|
136
|
+
// No ring read as an exterior, so magnitude decides: the largest ring is the one that encloses the area.
|
|
177
137
|
if (!exteriors.length) {
|
|
178
138
|
let largestIndex = 0
|
|
179
139
|
let largestArea = Math.abs(ringSignedAreaM2(holes[0]!))
|
|
@@ -194,8 +154,8 @@ export function resolveRingRoles(polygons: MultiPolygonRings, featureID: string)
|
|
|
194
154
|
exteriorByMagnitude = 1
|
|
195
155
|
}
|
|
196
156
|
|
|
197
|
-
//
|
|
198
|
-
//
|
|
157
|
+
// Smallest containing exterior, so a hole inside an island inside a hole lands on the island.
|
|
158
|
+
// One sort makes the choice deterministic on a tie.
|
|
199
159
|
const bySize = [...exteriors].toSorted((left, right) => left.area - right.area)
|
|
200
160
|
|
|
201
161
|
let nestedHoles = 0
|
|
@@ -212,9 +172,8 @@ export function resolveRingRoles(polygons: MultiPolygonRings, featureID: string)
|
|
|
212
172
|
continue
|
|
213
173
|
}
|
|
214
174
|
|
|
215
|
-
// A hole no exterior contains a majority of sits
|
|
216
|
-
//
|
|
217
|
-
// 9, and is counted so a receipt can carry the number rather than imply it is zero.
|
|
175
|
+
// A hole no exterior contains a majority of sits on its parent's boundary and goes to the smallest
|
|
176
|
+
// exterior of the same feature, so a receipt can report the number rather than imply it is zero.
|
|
218
177
|
bySize[0]!.holes.push(hole)
|
|
219
178
|
|
|
220
179
|
adjacentHoles++
|
package/lib/rings.ts
CHANGED
|
@@ -3,19 +3,8 @@
|
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
|
-
* `zoning_area.rings` — the blob layout and
|
|
7
|
-
*
|
|
8
|
-
* THE CODE ITSELF LIVES IN `@mailwoman/spatial`, re-exported here so this package's call sites and its
|
|
9
|
-
* `@mailwoman/zoning/rings` subpath keep reading the same. Nothing in it is zoning-specific: it is byte
|
|
10
|
-
* layout plus spherical geometry, and a second copy of the alignment arithmetic or of the signed-area
|
|
11
|
-
* reading is a second place for either to stop being right. Both failure modes are silent — a mis-read blob
|
|
12
|
-
* answers a containment question wrongly, and a hole-blind area reading answers "inside" for every point in
|
|
13
|
-
* a hole.
|
|
14
|
-
*
|
|
15
|
-
* WHAT IS NOT SHARED IS {@linkcode resolveRingRoles}, and the reason is that it is a fact about THIS
|
|
16
|
-
* PUBLISHER rather than about geometry: the service encodes hole roles by ring ORIENTATION, clockwise
|
|
17
|
-
* exterior, which is the inverse of RFC 7946's convention. `ring-roles.ts` carries it with the measurement
|
|
18
|
-
* that establishes it.
|
|
6
|
+
* `zoning_area.rings` — the blob layout and point test re-exported from `@mailwoman/spatial`;
|
|
7
|
+
* `resolveRingRoles` stays local because the clockwise-exterior role encoding belongs to this publisher rather than to geometry.
|
|
19
8
|
*/
|
|
20
9
|
|
|
21
10
|
export { resolveRingRoles, type ResolvedRingRoles } from "#ring-roles"
|
package/lib/schema.ts
CHANGED
|
@@ -2,38 +2,9 @@
|
|
|
2
2
|
* @copyright Sister Software
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
|
-
*
|
|
6
|
-
* Typed schema for `zoning-ireland.db` — the two-tier polygon layer: the authority's unsimplified rings as
|
|
7
|
-
* the truth table, an H3 cell table above them as the summary, the plan and jurisdiction a zone belongs to,
|
|
8
|
-
* the published vocabularies, and the layer-contract tables from `@mailwoman/core/layers`.
|
|
9
|
-
*
|
|
10
|
-
* THE LOCAL CODE IS `NOT NULL` AND THE CROSSWALK IS NULLABLE, WHICH IS THE VOCABULARY DECISION AS A
|
|
11
|
-
* CONSTRAINT. A source with no crosswalk produces a complete row; a source with no local code does not. The
|
|
12
|
-
* Department's own item description is what this transcribes: its national scheme "complements (rather than
|
|
13
|
-
* replaces) the existing statutory zoning used for each individual plan".
|
|
14
|
-
*
|
|
15
|
-
* `provenance_grade` IS A COLUMN WITH A `CHECK`, NOT A CONVENTION. `NOT NULL` alone accepts `''`, and a
|
|
16
|
-
* blank matches neither half of every read that splits on grade — so the constraint refuses a blank as well
|
|
17
|
-
* as an unknown value. This is `packages/filer`'s discipline applied unchanged, and the reason it is
|
|
18
|
-
* compulsory here is licensing as much as epistemics: an observed land-use layer is ODbL, and merging one
|
|
19
|
-
* of its rows into this table would relicense the table.
|
|
20
|
-
*
|
|
21
|
-
* `signed_area_m2` IS THE INGEST'S OWN RECEIPT AND ITS SIGN IS LOAD-BEARING. The service encodes hole roles
|
|
22
|
-
* by ring orientation with clockwise as the exterior, so a correctly-read feature stores a POSITIVE signed
|
|
23
|
-
* sum; the national total of those sums is what the build compares against the Department's own
|
|
24
|
-
* `Shape__Area` statistic. Read with the holes it is 5,444.5 km²; read without them, 5,666.6 km².
|
|
25
|
-
*
|
|
26
|
-
* `WITHOUT ROWID` ON THE CELL TABLE AND NEVER ON THE GEOMETRY TABLE. Small fixed-width rows probed by their
|
|
27
|
-
* exact primary key belong in the B-tree; a row carrying a geometry blob does not — clustering it into the
|
|
28
|
-
* B-tree makes every index page a geometry page.
|
|
29
|
-
*
|
|
30
|
-
* THE WHOLE-CELL SET IS COMPACTED PER FEATURE, SO IT IS MIXED-RESOLUTION. A row therefore carries its own
|
|
31
|
-
* `resolution`, and a probe walks `cellToParent` from the index resolution up to the coarsest resolution
|
|
32
|
-
* present. `layer_coverage` is NOT compacted and stays single-resolution, because `recoverShortCellResolution`
|
|
33
|
-
* recovers one resolution from the stored cells and throws on a table that mixes them.
|
|
34
5
|
*/
|
|
35
6
|
|
|
36
|
-
import type {
|
|
7
|
+
import type { layerschemadatabase } from "@mailwoman/core/layers"
|
|
37
8
|
import { addBoundingBoxColumns, addCellIndexColumns, addRingsColumn } from "@mailwoman/sqlite/schema-columns"
|
|
38
9
|
import { sql, type Kysely } from "kysely"
|
|
39
10
|
|
|
@@ -42,11 +13,12 @@ import { sql, type Kysely } from "kysely"
|
|
|
42
13
|
*/
|
|
43
14
|
export const ZoningCellContainment = {
|
|
44
15
|
/**
|
|
45
|
-
* Every point in the cell is inside the zone.
|
|
16
|
+
* Every point in the cell is inside the zone.
|
|
17
|
+
* The index answers this without reading geometry.
|
|
46
18
|
*/
|
|
47
19
|
Whole: "whole",
|
|
48
20
|
/**
|
|
49
|
-
* The zone boundary crosses the cell
|
|
21
|
+
* The zone boundary crosses the cell, so the point test decides after the index narrows the candidates.
|
|
50
22
|
*/
|
|
51
23
|
Partial: "partial",
|
|
52
24
|
} as const
|
|
@@ -54,29 +26,33 @@ export const ZoningCellContainment = {
|
|
|
54
26
|
export type ZoningCellContainment = (typeof ZoningCellContainment)[keyof typeof ZoningCellContainment]
|
|
55
27
|
|
|
56
28
|
/**
|
|
57
|
-
* One authority zoning polygon, verbatim.
|
|
58
|
-
*
|
|
29
|
+
* One authority zoning polygon, verbatim.
|
|
30
|
+
*
|
|
31
|
+
* A rowid table that holds a geometry blob.
|
|
32
|
+
* `WITHOUT ROWID` performs poorly for this shape.
|
|
59
33
|
*/
|
|
60
34
|
export interface ZoningAreaTable {
|
|
61
35
|
/**
|
|
62
|
-
* The authority's own feature id, as published
|
|
63
|
-
*
|
|
64
|
-
* to be the publisher's.
|
|
36
|
+
* The authority's own feature id, as published and unique across the product,
|
|
37
|
+
* so it needs no scoping prefix.
|
|
65
38
|
*/
|
|
66
39
|
area_id: string
|
|
67
40
|
/**
|
|
68
|
-
* The authority that adopted the plan.
|
|
41
|
+
* The authority that adopted the plan.
|
|
42
|
+
*
|
|
43
|
+
* FK to `zoning_jurisdiction`.
|
|
69
44
|
*/
|
|
70
45
|
jurisdiction_id: string
|
|
71
46
|
/**
|
|
72
|
-
* The plan this zone belongs to
|
|
73
|
-
* Development Plan or Local Area Plan with a stated validity window, and a layer that dropped the plan and kept the
|
|
74
|
-
* zone would be answering a question no authority asked.
|
|
47
|
+
* The plan this zone belongs to, keyed to `zoning_plan`: a zone without its plan is not a claim.
|
|
75
48
|
*/
|
|
76
49
|
plan_id: string
|
|
77
50
|
/**
|
|
78
|
-
* `ZONE_ORIG` —
|
|
79
|
-
*
|
|
51
|
+
* `ZONE_ORIG` — the authority'S own zone code, verbatim, in its own spelling
|
|
52
|
+
* including case and trailing space.
|
|
53
|
+
*
|
|
54
|
+
* Compared case-insensitively where it must be compared.
|
|
55
|
+
* Never stored normalized.
|
|
80
56
|
*/
|
|
81
57
|
local_code: string
|
|
82
58
|
/**
|
|
@@ -84,16 +60,21 @@ export interface ZoningAreaTable {
|
|
|
84
60
|
*/
|
|
85
61
|
local_description: string | null
|
|
86
62
|
/**
|
|
87
|
-
* `ZONE_LINK` — the authority's own link to the plan text.
|
|
63
|
+
* `ZONE_LINK` — the authority's own link to the plan text.
|
|
64
|
+
*
|
|
65
|
+
* A live host, unlike the crosswalk's.
|
|
88
66
|
*/
|
|
89
67
|
local_code_url: string | null
|
|
90
68
|
/**
|
|
91
|
-
* `ZONE_GZT` — the Department's national generic type,
|
|
92
|
-
*
|
|
69
|
+
* `ZONE_GZT` — the Department's national generic type, beside the local code and never instead of it.
|
|
70
|
+
*
|
|
71
|
+
* NULL where a publisher ships no crosswalk.
|
|
93
72
|
*/
|
|
94
73
|
crosswalk_code: string | null
|
|
95
74
|
/**
|
|
96
|
-
* Which crosswalk `crosswalk_code` belongs to.
|
|
75
|
+
* Which crosswalk `crosswalk_code` belongs to.
|
|
76
|
+
*
|
|
77
|
+
* NULL with the above.
|
|
97
78
|
*/
|
|
98
79
|
crosswalk_scheme: string | null
|
|
99
80
|
/**
|
|
@@ -101,11 +82,13 @@ export interface ZoningAreaTable {
|
|
|
101
82
|
*/
|
|
102
83
|
crosswalk_description: string | null
|
|
103
84
|
/**
|
|
104
|
-
* `SZO` — a coarser code from the
|
|
85
|
+
* `SZO` — a coarser code from the same authority, stored as published rather than derived.
|
|
105
86
|
*/
|
|
106
87
|
crosswalk_rollup: string | null
|
|
107
88
|
/**
|
|
108
|
-
* One of {@link ProvenanceGrade}.
|
|
89
|
+
* One of {@link ProvenanceGrade}.
|
|
90
|
+
*
|
|
91
|
+
* `not NULL` with a `check` that refuses a blank.
|
|
109
92
|
*/
|
|
110
93
|
provenance_grade: string
|
|
111
94
|
min_lat: number
|
|
@@ -113,17 +96,18 @@ export interface ZoningAreaTable {
|
|
|
113
96
|
max_lat: number
|
|
114
97
|
max_lon: number
|
|
115
98
|
/**
|
|
116
|
-
* How many rings the source published for this feature
|
|
117
|
-
* orientation was read rather than assumed.
|
|
99
|
+
* How many rings the source published for this feature, with `signed_area_m2`,
|
|
100
|
+
* the ingest's own receipt that the orientation was read rather than assumed.
|
|
118
101
|
*/
|
|
119
102
|
ring_count: number
|
|
120
103
|
/**
|
|
121
|
-
* The signed ring sum, in square
|
|
104
|
+
* The signed ring sum, in square meters, positive under this service's clockwise-exterior convention.
|
|
122
105
|
*/
|
|
123
106
|
signed_area_m2: number
|
|
124
107
|
/**
|
|
125
|
-
* The authority's ring coordinates,
|
|
126
|
-
*
|
|
108
|
+
* The authority's ring coordinates, unsimplified, with hole roles resolved.
|
|
109
|
+
*
|
|
110
|
+
* See `ring-roles.ts` for the resolution and `rings.ts` for the layout and the point test.
|
|
127
111
|
*/
|
|
128
112
|
rings: Uint8Array
|
|
129
113
|
}
|
|
@@ -148,11 +132,10 @@ export interface ZoningPlanTable {
|
|
|
148
132
|
*/
|
|
149
133
|
valid_to: string | null
|
|
150
134
|
/**
|
|
151
|
-
* `CURRENT_PLAN`,
|
|
135
|
+
* `CURRENT_PLAN`, stored as published.
|
|
152
136
|
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
* plan's own window has closed is `valid_to`, and it is a separate fact.
|
|
137
|
+
* `1` means the publisher has not superseded the plan.
|
|
138
|
+
* `valid_to` records whether it remains in force today.
|
|
156
139
|
*/
|
|
157
140
|
current_plan: number
|
|
158
141
|
}
|
|
@@ -164,25 +147,27 @@ export interface ZoningJurisdictionTable {
|
|
|
164
147
|
jurisdiction_id: string
|
|
165
148
|
name: string
|
|
166
149
|
/**
|
|
167
|
-
* The publisher's own code, verbatim
|
|
150
|
+
* The publisher's own code, verbatim — `Fl` for Fingal against `CL`, `CO`, `DU` — never repaired.
|
|
168
151
|
*/
|
|
169
152
|
source_code: string
|
|
170
153
|
country: string
|
|
171
154
|
}
|
|
172
155
|
|
|
173
156
|
/**
|
|
174
|
-
* A publisher's declared vocabulary, as shipped, per scheme — plus the values
|
|
175
|
-
* declared.
|
|
157
|
+
* A publisher's declared vocabulary, as shipped, per scheme — plus the values
|
|
158
|
+
* the data uses that the publisher never declared.
|
|
176
159
|
*/
|
|
177
160
|
export interface ZoningVocabularyTable {
|
|
178
161
|
/**
|
|
179
|
-
* `IE-GZT`, `IE-SZO`, `IE-
|
|
162
|
+
* `IE-GZT`, `IE-SZO`, `IE-plan-level`, or `IE-local:<authority code>`.
|
|
180
163
|
*/
|
|
181
164
|
scheme: string
|
|
182
165
|
code: string
|
|
183
166
|
/**
|
|
184
|
-
* The publisher's own words.
|
|
185
|
-
*
|
|
167
|
+
* The publisher's own words.
|
|
168
|
+
*
|
|
169
|
+
* For an observed-but-undeclared code this is the description stored on its rows,
|
|
170
|
+
* or the code itself where the data stores none, never a label this package wrote.
|
|
186
171
|
*/
|
|
187
172
|
label: string
|
|
188
173
|
/**
|
|
@@ -190,34 +175,31 @@ export interface ZoningVocabularyTable {
|
|
|
190
175
|
*/
|
|
191
176
|
definition: string | null
|
|
192
177
|
/**
|
|
193
|
-
* NULL for the Irish generic types
|
|
194
|
-
*
|
|
195
|
-
*
|
|
178
|
+
* NULL for the Irish generic types because their definitions were unavailable.
|
|
179
|
+
*
|
|
180
|
+
* The column stays NULL until a source supplies the definition.
|
|
196
181
|
*/
|
|
197
182
|
definition_url: string | null
|
|
198
183
|
/**
|
|
199
|
-
* `1` where the publisher
|
|
184
|
+
* `1` where the publisher declares this code in its own domain, `0`
|
|
185
|
+
* where the code appears only in the data.
|
|
200
186
|
*
|
|
201
|
-
*
|
|
202
|
-
* and its data uses 55: `N/A` appears on 4 rows and in no domain.
|
|
187
|
+
* A merged value would hide a source-schema change or invent a declaration.
|
|
203
188
|
*/
|
|
204
189
|
declared: number
|
|
205
190
|
/**
|
|
206
|
-
* How many rows of this artifact
|
|
207
|
-
*
|
|
191
|
+
* How many rows of this artifact contain the code.
|
|
192
|
+
*
|
|
193
|
+
* A census a reader checks a closed domain against, rather than a claim about the world.
|
|
208
194
|
*/
|
|
209
195
|
observed_rows: number
|
|
210
196
|
}
|
|
211
197
|
|
|
212
198
|
/**
|
|
213
|
-
* A publisher's
|
|
199
|
+
* A publisher's own mapping between two schemes, where it publishes one as a table.
|
|
214
200
|
*
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
* County Council's `Special Policy Area` takes 14 and its `Green Infrastructure` 12 — so the mapping is not a function
|
|
218
|
-
* of the pair and no edge table can carry it without inventing one. The mapping lives on `zoning_area`, per row, where
|
|
219
|
-
* the Department put it. {@linkcode assertCrosswalkIsNotATable} refuses a build that would write edges while such a
|
|
220
|
-
* pair exists.
|
|
201
|
+
* Empty for Ireland: the mapping is not a function of the (authority, local code) pair, so it lives on
|
|
202
|
+
* `zoning_area` per row and {@linkcode assertCrosswalkIsNotATable} refuses a build that writes edges.
|
|
221
203
|
*/
|
|
222
204
|
export interface ZoningCrosswalkEdgeTable {
|
|
223
205
|
from_scheme: string
|
|
@@ -225,7 +207,9 @@ export interface ZoningCrosswalkEdgeTable {
|
|
|
225
207
|
to_scheme: string
|
|
226
208
|
to_code: string
|
|
227
209
|
/**
|
|
228
|
-
* The body that authored
|
|
210
|
+
* The body that authored this edge.
|
|
211
|
+
*
|
|
212
|
+
* Never us.
|
|
229
213
|
*/
|
|
230
214
|
authored_by: string
|
|
231
215
|
}
|
|
@@ -233,18 +217,22 @@ export interface ZoningCrosswalkEdgeTable {
|
|
|
233
217
|
/**
|
|
234
218
|
* Per (cell, polygon): does the polygon cover the whole cell, or only part of it?
|
|
235
219
|
*
|
|
236
|
-
*
|
|
237
|
-
*
|
|
220
|
+
* Keyed on the polygon rather than a code, because a zoning answer is the polygon
|
|
221
|
+
* and two authorities' plans can name the same code for different things.
|
|
238
222
|
*/
|
|
239
223
|
export interface ZoningCellTable {
|
|
240
224
|
/**
|
|
241
|
-
* 48-bit short H3 cell.
|
|
242
|
-
*
|
|
225
|
+
* 48-bit short H3 cell.
|
|
226
|
+
*
|
|
227
|
+
* Mixed-resolution: `whole` rows are compacted parent-ward, `partial` rows stay
|
|
228
|
+
* at the resolution the feature was indexed at.
|
|
243
229
|
*/
|
|
244
230
|
h3_cell: number
|
|
245
231
|
/**
|
|
246
|
-
* The resolution this row's cell was captured at.
|
|
247
|
-
*
|
|
232
|
+
* The resolution this row's cell was captured at.
|
|
233
|
+
*
|
|
234
|
+
* Short H3 cell values omit their resolution.
|
|
235
|
+
* Queries against a table with mixed resolutions require this field.
|
|
248
236
|
*/
|
|
249
237
|
resolution: number
|
|
250
238
|
area_id: string
|
|
@@ -255,20 +243,12 @@ export interface ZoningCellTable {
|
|
|
255
243
|
}
|
|
256
244
|
|
|
257
245
|
/**
|
|
258
|
-
* The authority's own statement of what it
|
|
259
|
-
*
|
|
260
|
-
* EMPTY IN THIS EDITION, AND ITS EMPTINESS IS THE CLAIM. The Department states "Awaiting data for some Local
|
|
261
|
-
* Authorities
|
|
246
|
+
* The authority's own statement of what it mapped.
|
|
262
247
|
*
|
|
263
|
-
*
|
|
264
|
-
*
|
|
265
|
-
* one local authority of 31 missing from the layer — was recovered by measuring `LA_CODE`, not read from a
|
|
266
|
-
* statement.
|
|
248
|
+
* One row per authority statement.
|
|
249
|
+
* The zoning polygons describe individual zones.
|
|
267
250
|
*
|
|
268
|
-
*
|
|
269
|
-
* authority examined, and the difference is the whole content of a negative answer. One authority's drafting convention
|
|
270
|
-
* moves the national zoned-area figure by 41% on its own — Meath County Council zones its entire rural remainder as one
|
|
271
|
-
* 2,232 km² polygon, against 32.5 km² for the next largest in the country — so the union is not even a stable shape.
|
|
251
|
+
* Use the authority statement for mapped extent instead of deriving the extent from the polygon union.
|
|
272
252
|
*/
|
|
273
253
|
export interface ZoningMappedExtentTable {
|
|
274
254
|
extent_id: string
|
|
@@ -285,7 +265,7 @@ export interface ZoningMappedExtentTable {
|
|
|
285
265
|
/**
|
|
286
266
|
* Pass to `new DatabaseClient<ZoningDatabase>(...)`.
|
|
287
267
|
*/
|
|
288
|
-
export interface ZoningDatabase extends
|
|
268
|
+
export interface ZoningDatabase extends layerschemadatabase {
|
|
289
269
|
zoning_area: ZoningAreaTable
|
|
290
270
|
zoning_plan: ZoningPlanTable
|
|
291
271
|
zoning_jurisdiction: ZoningJurisdictionTable
|
|
@@ -296,14 +276,18 @@ export interface ZoningDatabase extends LayerContractDatabase {
|
|
|
296
276
|
}
|
|
297
277
|
|
|
298
278
|
/**
|
|
299
|
-
* The
|
|
300
|
-
*
|
|
279
|
+
* The subset of a Kysely handle the DDL touches.
|
|
280
|
+
*
|
|
281
|
+
* Same reasoning as `layerschemahandle`: Kysely is invariant in its schema parameter,
|
|
282
|
+
* so naming only the members these functions call lets a caller pass its own wider handle.
|
|
301
283
|
*/
|
|
302
284
|
export type ZoningSchemaHandle = Pick<Kysely<ZoningDatabase>, "schema">
|
|
303
285
|
|
|
304
286
|
/**
|
|
305
|
-
* Create `zoning_area`.
|
|
306
|
-
*
|
|
287
|
+
* Create `zoning_area`.
|
|
288
|
+
*
|
|
289
|
+
* A plain rowid table on purpose.
|
|
290
|
+
* The `rings` blob is exactly the payload `without rowid` penalizes.
|
|
307
291
|
*/
|
|
308
292
|
export async function createZoningAreaTable(db: ZoningSchemaHandle): Promise<void> {
|
|
309
293
|
const table = db.schema
|
|
@@ -325,15 +309,12 @@ export async function createZoningAreaTable(db: ZoningSchemaHandle): Promise<voi
|
|
|
325
309
|
.addColumn("signed_area_m2", "real", (c) => c.notNull())
|
|
326
310
|
|
|
327
311
|
await addRingsColumn(bounded)
|
|
328
|
-
//
|
|
329
|
-
// read that splits on grade — so the value set and the blank are refused separately, and the second half is the one
|
|
330
|
-
// a schema without it loses.
|
|
312
|
+
// `not NULL` by itself accepts `''`, so the value set and the blank are refused separately.
|
|
331
313
|
.addCheckConstraint(
|
|
332
314
|
"zoning_area_provenance_grade_declared",
|
|
333
315
|
sql`provenance_grade in ('authoritative', 'inferred') and trim(provenance_grade) != ''`
|
|
334
316
|
)
|
|
335
|
-
//
|
|
336
|
-
// only at the ingest: a blank would read as a zone the authority named nothing.
|
|
317
|
+
// A blank local code would read as a zone the authority left unnamed, so storage refuses it.
|
|
337
318
|
.addCheckConstraint("zoning_area_local_code_not_blank", sql`trim(local_code) != ''`)
|
|
338
319
|
.execute()
|
|
339
320
|
}
|
|
@@ -385,7 +366,7 @@ export async function createZoningVocabularyTable(db: ZoningSchemaHandle): Promi
|
|
|
385
366
|
}
|
|
386
367
|
|
|
387
368
|
/**
|
|
388
|
-
* Create `zoning_crosswalk_edge
|
|
369
|
+
* Create `zoning_crosswalk_edge`, empty for Ireland.
|
|
389
370
|
*/
|
|
390
371
|
export async function createZoningCrosswalkEdgeTable(db: ZoningSchemaHandle): Promise<void> {
|
|
391
372
|
await db.schema
|
|
@@ -400,22 +381,23 @@ export async function createZoningCrosswalkEdgeTable(db: ZoningSchemaHandle): Pr
|
|
|
400
381
|
}
|
|
401
382
|
|
|
402
383
|
/**
|
|
403
|
-
* Create `zoning_cell` — the summary tier.
|
|
404
|
-
*
|
|
384
|
+
* Create `zoning_cell` — the summary tier.
|
|
385
|
+
*
|
|
386
|
+
* This table stores small fixed-width rows.
|
|
387
|
+
* Queries use exact primary keys, the pattern supported by `WITHOUT ROWID`.
|
|
405
388
|
*/
|
|
406
389
|
export async function createZoningCellTable(db: ZoningSchemaHandle): Promise<void> {
|
|
407
390
|
const table = db.schema.createTable("zoning_cell")
|
|
408
391
|
|
|
409
392
|
await addCellIndexColumns(table, "area_id")
|
|
410
393
|
.addPrimaryKeyConstraint("zoning_cell_pk", ["h3_cell", "area_id"])
|
|
411
|
-
// `
|
|
394
|
+
// `without rowid` has no first-class builder, so the raw modifier is the fallback.
|
|
412
395
|
.modifyEnd(sql`without rowid`)
|
|
413
396
|
.execute()
|
|
414
397
|
}
|
|
415
398
|
|
|
416
399
|
/**
|
|
417
|
-
* Create `zoning_mapped_extent
|
|
418
|
-
* way — see the interface's docstring.
|
|
400
|
+
* Create `zoning_mapped_extent`, empty while the reader refuses a stronger coverage basis.
|
|
419
401
|
*/
|
|
420
402
|
export async function createZoningMappedExtentTable(db: ZoningSchemaHandle): Promise<void> {
|
|
421
403
|
const table = db.schema
|