@mailwoman/zoning 10.0.0 → 10.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +169 -163
- package/lib/index.ts +103 -135
- package/lib/paths.ts +24 -0
- package/lib/ring-roles.ts +30 -71
- package/lib/rings.ts +2 -13
- package/lib/schema.ts +98 -139
- package/lib/vocabulary.ts +52 -130
- package/out/index.d.ts +81 -101
- package/out/index.d.ts.map +1 -1
- package/out/index.js +37 -96
- package/out/index.js.map +1 -1
- package/out/paths.d.ts +19 -0
- package/out/paths.d.ts.map +1 -0
- package/out/paths.js +21 -0
- package/out/paths.js.map +1 -0
- package/out/ring-roles.d.ts +16 -50
- package/out/ring-roles.d.ts.map +1 -1
- package/out/ring-roles.js +18 -51
- package/out/ring-roles.js.map +1 -1
- package/out/rings.d.ts +2 -13
- package/out/rings.d.ts.map +1 -1
- package/out/rings.js +2 -13
- package/out/rings.js.map +1 -1
- package/out/schema.d.ts +90 -132
- package/out/schema.d.ts.map +1 -1
- package/out/schema.js +17 -45
- package/out/schema.js.map +1 -1
- package/out/sdk/build-zoning.d.ts +58 -111
- package/out/sdk/build-zoning.d.ts.map +1 -1
- package/out/sdk/build-zoning.js +50 -139
- package/out/sdk/build-zoning.js.map +1 -1
- package/out/sdk/cells.d.ts +21 -62
- package/out/sdk/cells.d.ts.map +1 -1
- package/out/sdk/cells.js +15 -52
- package/out/sdk/cells.js.map +1 -1
- package/out/sdk/client.d.ts +23 -67
- package/out/sdk/client.d.ts.map +1 -1
- package/out/sdk/client.js +29 -77
- package/out/sdk/client.js.map +1 -1
- package/out/sdk/download.d.ts +7 -27
- package/out/sdk/download.d.ts.map +1 -1
- package/out/sdk/download.js +8 -28
- package/out/sdk/download.js.map +1 -1
- package/out/sdk/ingest/chunk.d.ts +19 -43
- package/out/sdk/ingest/chunk.d.ts.map +1 -1
- package/out/sdk/ingest/chunk.js +19 -52
- package/out/sdk/ingest/chunk.js.map +1 -1
- package/out/sdk/ingest/worker.d.ts +9 -0
- package/out/sdk/ingest/worker.d.ts.map +1 -0
- package/out/{scripts/ingest-chunk.js → sdk/ingest/worker.js} +8 -10
- package/out/sdk/ingest/worker.js.map +1 -0
- package/out/sdk/ingest.d.ts +152 -0
- package/out/sdk/ingest.d.ts.map +1 -0
- package/out/sdk/ingest.js +200 -0
- package/out/sdk/ingest.js.map +1 -0
- package/out/sdk/measure-resolutions.d.ts +7 -34
- package/out/sdk/measure-resolutions.d.ts.map +1 -1
- package/out/sdk/measure-resolutions.js +5 -23
- package/out/sdk/measure-resolutions.js.map +1 -1
- package/out/sdk/test-kit.d.ts +75 -0
- package/out/sdk/test-kit.d.ts.map +1 -0
- package/out/{test-kit.js → sdk/test-kit.js} +20 -43
- package/out/sdk/test-kit.js.map +1 -0
- package/out/sdk/verify.d.ts +79 -80
- package/out/sdk/verify.d.ts.map +1 -1
- package/out/sdk/verify.js +83 -70
- package/out/sdk/verify.js.map +1 -1
- package/out/vocabulary.d.ts +52 -120
- package/out/vocabulary.d.ts.map +1 -1
- package/out/vocabulary.js +47 -125
- package/out/vocabulary.js.map +1 -1
- package/package.json +38 -162
- package/{lib/sdk → sdk}/build-zoning.ts +102 -188
- package/{lib/sdk → sdk}/cells.ts +27 -66
- package/{lib/sdk → sdk}/client.ts +34 -82
- package/sdk/download.ts +58 -0
- package/{lib/sdk → sdk}/ingest/chunk.ts +36 -65
- package/{lib/scripts/ingest-chunk.ts → sdk/ingest/worker.ts} +7 -9
- package/sdk/ingest.ts +354 -0
- package/sdk/measure-resolutions.ts +72 -0
- package/{lib → sdk}/test-kit.ts +21 -44
- package/sdk/verify.ts +367 -0
- package/lib/sdk/download.ts +0 -78
- package/lib/sdk/index.ts +0 -15
- package/lib/sdk/ingest/index.ts +0 -393
- package/lib/sdk/measure-resolutions.ts +0 -101
- package/lib/sdk/verify.ts +0 -357
- package/out/scripts/ingest-chunk.d.ts +0 -11
- package/out/scripts/ingest-chunk.d.ts.map +0 -1
- package/out/scripts/ingest-chunk.js.map +0 -1
- package/out/sdk/index.d.ts +0 -15
- package/out/sdk/index.d.ts.map +0 -1
- package/out/sdk/index.js +0 -15
- package/out/sdk/index.js.map +0 -1
- package/out/sdk/ingest/index.d.ts +0 -185
- package/out/sdk/ingest/index.d.ts.map +0 -1
- package/out/sdk/ingest/index.js +0 -232
- package/out/sdk/ingest/index.js.map +0 -1
- package/out/test-kit.d.ts +0 -96
- package/out/test-kit.d.ts.map +0 -1
- package/out/test-kit.js.map +0 -1
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,39 +2,15 @@
|
|
|
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 {
|
|
37
|
-
import {
|
|
7
|
+
import type { layerschemadatabase, MappedExtentTable } from "@mailwoman/core/layers"
|
|
8
|
+
import {
|
|
9
|
+
addBoundingBoxColumns,
|
|
10
|
+
addCellIndexColumns,
|
|
11
|
+
addRingsColumn,
|
|
12
|
+
type AreaCellIndexTable,
|
|
13
|
+
} from "@mailwoman/sqlite/schema-columns"
|
|
38
14
|
import { sql, type Kysely } from "kysely"
|
|
39
15
|
|
|
40
16
|
/**
|
|
@@ -42,11 +18,12 @@ import { sql, type Kysely } from "kysely"
|
|
|
42
18
|
*/
|
|
43
19
|
export const ZoningCellContainment = {
|
|
44
20
|
/**
|
|
45
|
-
* Every point in the cell is inside the zone.
|
|
21
|
+
* Every point in the cell is inside the zone.
|
|
22
|
+
* The index answers this without reading geometry.
|
|
46
23
|
*/
|
|
47
24
|
Whole: "whole",
|
|
48
25
|
/**
|
|
49
|
-
* The zone boundary crosses the cell
|
|
26
|
+
* The zone boundary crosses the cell, so the point test decides after the index narrows the candidates.
|
|
50
27
|
*/
|
|
51
28
|
Partial: "partial",
|
|
52
29
|
} as const
|
|
@@ -54,29 +31,33 @@ export const ZoningCellContainment = {
|
|
|
54
31
|
export type ZoningCellContainment = (typeof ZoningCellContainment)[keyof typeof ZoningCellContainment]
|
|
55
32
|
|
|
56
33
|
/**
|
|
57
|
-
* One authority zoning polygon, verbatim.
|
|
58
|
-
*
|
|
34
|
+
* One authority zoning polygon, verbatim.
|
|
35
|
+
*
|
|
36
|
+
* A rowid table that holds a geometry blob.
|
|
37
|
+
* `WITHOUT ROWID` performs poorly for this shape.
|
|
59
38
|
*/
|
|
60
39
|
export interface ZoningAreaTable {
|
|
61
40
|
/**
|
|
62
|
-
* The authority's own feature id, as published
|
|
63
|
-
*
|
|
64
|
-
* to be the publisher's.
|
|
41
|
+
* The authority's own feature id, as published and unique across the product,
|
|
42
|
+
* so it needs no scoping prefix.
|
|
65
43
|
*/
|
|
66
44
|
area_id: string
|
|
67
45
|
/**
|
|
68
|
-
* The authority that adopted the plan.
|
|
46
|
+
* The authority that adopted the plan.
|
|
47
|
+
*
|
|
48
|
+
* FK to `zoning_jurisdiction`.
|
|
69
49
|
*/
|
|
70
50
|
jurisdiction_id: string
|
|
71
51
|
/**
|
|
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.
|
|
52
|
+
* The plan this zone belongs to, keyed to `zoning_plan`: a zone without its plan is not a claim.
|
|
75
53
|
*/
|
|
76
54
|
plan_id: string
|
|
77
55
|
/**
|
|
78
|
-
* `ZONE_ORIG` —
|
|
79
|
-
*
|
|
56
|
+
* `ZONE_ORIG` — the authority'S own zone code, verbatim, in its own spelling
|
|
57
|
+
* including case and trailing space.
|
|
58
|
+
*
|
|
59
|
+
* Compared case-insensitively where it must be compared.
|
|
60
|
+
* Never stored normalized.
|
|
80
61
|
*/
|
|
81
62
|
local_code: string
|
|
82
63
|
/**
|
|
@@ -84,16 +65,21 @@ export interface ZoningAreaTable {
|
|
|
84
65
|
*/
|
|
85
66
|
local_description: string | null
|
|
86
67
|
/**
|
|
87
|
-
* `ZONE_LINK` — the authority's own link to the plan text.
|
|
68
|
+
* `ZONE_LINK` — the authority's own link to the plan text.
|
|
69
|
+
*
|
|
70
|
+
* A live host, unlike the crosswalk's.
|
|
88
71
|
*/
|
|
89
72
|
local_code_url: string | null
|
|
90
73
|
/**
|
|
91
|
-
* `ZONE_GZT` — the Department's national generic type,
|
|
92
|
-
*
|
|
74
|
+
* `ZONE_GZT` — the Department's national generic type, beside the local code and never instead of it.
|
|
75
|
+
*
|
|
76
|
+
* NULL where a publisher ships no crosswalk.
|
|
93
77
|
*/
|
|
94
78
|
crosswalk_code: string | null
|
|
95
79
|
/**
|
|
96
|
-
* Which crosswalk `crosswalk_code` belongs to.
|
|
80
|
+
* Which crosswalk `crosswalk_code` belongs to.
|
|
81
|
+
*
|
|
82
|
+
* NULL with the above.
|
|
97
83
|
*/
|
|
98
84
|
crosswalk_scheme: string | null
|
|
99
85
|
/**
|
|
@@ -101,11 +87,13 @@ export interface ZoningAreaTable {
|
|
|
101
87
|
*/
|
|
102
88
|
crosswalk_description: string | null
|
|
103
89
|
/**
|
|
104
|
-
* `SZO` — a coarser code from the
|
|
90
|
+
* `SZO` — a coarser code from the same authority, stored as published rather than derived.
|
|
105
91
|
*/
|
|
106
92
|
crosswalk_rollup: string | null
|
|
107
93
|
/**
|
|
108
|
-
* One of {@link ProvenanceGrade}.
|
|
94
|
+
* One of {@link ProvenanceGrade}.
|
|
95
|
+
*
|
|
96
|
+
* `not NULL` with a `check` that refuses a blank.
|
|
109
97
|
*/
|
|
110
98
|
provenance_grade: string
|
|
111
99
|
min_lat: number
|
|
@@ -113,17 +101,18 @@ export interface ZoningAreaTable {
|
|
|
113
101
|
max_lat: number
|
|
114
102
|
max_lon: number
|
|
115
103
|
/**
|
|
116
|
-
* How many rings the source published for this feature
|
|
117
|
-
* orientation was read rather than assumed.
|
|
104
|
+
* How many rings the source published for this feature, with `signed_area_m2`,
|
|
105
|
+
* the ingest's own receipt that the orientation was read rather than assumed.
|
|
118
106
|
*/
|
|
119
107
|
ring_count: number
|
|
120
108
|
/**
|
|
121
|
-
* The signed ring sum, in square
|
|
109
|
+
* The signed ring sum, in square meters, positive under this service's clockwise-exterior convention.
|
|
122
110
|
*/
|
|
123
111
|
signed_area_m2: number
|
|
124
112
|
/**
|
|
125
|
-
* The authority's ring coordinates,
|
|
126
|
-
*
|
|
113
|
+
* The authority's ring coordinates, unsimplified, with hole roles resolved.
|
|
114
|
+
*
|
|
115
|
+
* See `ring-roles.ts` for the resolution and `rings.ts` for the layout and the point test.
|
|
127
116
|
*/
|
|
128
117
|
rings: Uint8Array
|
|
129
118
|
}
|
|
@@ -148,11 +137,10 @@ export interface ZoningPlanTable {
|
|
|
148
137
|
*/
|
|
149
138
|
valid_to: string | null
|
|
150
139
|
/**
|
|
151
|
-
* `CURRENT_PLAN`,
|
|
140
|
+
* `CURRENT_PLAN`, stored as published.
|
|
152
141
|
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
* plan's own window has closed is `valid_to`, and it is a separate fact.
|
|
142
|
+
* `1` means the publisher has not superseded the plan.
|
|
143
|
+
* `valid_to` records whether it remains in force today.
|
|
156
144
|
*/
|
|
157
145
|
current_plan: number
|
|
158
146
|
}
|
|
@@ -164,25 +152,27 @@ export interface ZoningJurisdictionTable {
|
|
|
164
152
|
jurisdiction_id: string
|
|
165
153
|
name: string
|
|
166
154
|
/**
|
|
167
|
-
* The publisher's own code, verbatim
|
|
155
|
+
* The publisher's own code, verbatim — `Fl` for Fingal against `CL`, `CO`, `DU` — never repaired.
|
|
168
156
|
*/
|
|
169
157
|
source_code: string
|
|
170
158
|
country: string
|
|
171
159
|
}
|
|
172
160
|
|
|
173
161
|
/**
|
|
174
|
-
* A publisher's declared vocabulary, as shipped, per scheme — plus the values
|
|
175
|
-
* declared.
|
|
162
|
+
* A publisher's declared vocabulary, as shipped, per scheme — plus the values
|
|
163
|
+
* the data uses that the publisher never declared.
|
|
176
164
|
*/
|
|
177
165
|
export interface ZoningVocabularyTable {
|
|
178
166
|
/**
|
|
179
|
-
* `IE-GZT`, `IE-SZO`, `IE-
|
|
167
|
+
* `IE-GZT`, `IE-SZO`, `IE-plan-level`, or `IE-local:<authority code>`.
|
|
180
168
|
*/
|
|
181
169
|
scheme: string
|
|
182
170
|
code: string
|
|
183
171
|
/**
|
|
184
|
-
* The publisher's own words.
|
|
185
|
-
*
|
|
172
|
+
* The publisher's own words.
|
|
173
|
+
*
|
|
174
|
+
* For an observed-but-undeclared code this is the description stored on its rows,
|
|
175
|
+
* or the code itself where the data stores none, never a label this package wrote.
|
|
186
176
|
*/
|
|
187
177
|
label: string
|
|
188
178
|
/**
|
|
@@ -190,34 +180,31 @@ export interface ZoningVocabularyTable {
|
|
|
190
180
|
*/
|
|
191
181
|
definition: string | null
|
|
192
182
|
/**
|
|
193
|
-
* NULL for the Irish generic types
|
|
194
|
-
*
|
|
195
|
-
*
|
|
183
|
+
* NULL for the Irish generic types because their definitions were unavailable.
|
|
184
|
+
*
|
|
185
|
+
* The column stays NULL until a source supplies the definition.
|
|
196
186
|
*/
|
|
197
187
|
definition_url: string | null
|
|
198
188
|
/**
|
|
199
|
-
* `1` where the publisher
|
|
189
|
+
* `1` where the publisher declares this code in its own domain, `0`
|
|
190
|
+
* where the code appears only in the data.
|
|
200
191
|
*
|
|
201
|
-
*
|
|
202
|
-
* and its data uses 55: `N/A` appears on 4 rows and in no domain.
|
|
192
|
+
* A merged value would hide a source-schema change or invent a declaration.
|
|
203
193
|
*/
|
|
204
194
|
declared: number
|
|
205
195
|
/**
|
|
206
|
-
* How many rows of this artifact
|
|
207
|
-
*
|
|
196
|
+
* How many rows of this artifact contain the code.
|
|
197
|
+
*
|
|
198
|
+
* A census a reader checks a closed domain against, rather than a claim about the world.
|
|
208
199
|
*/
|
|
209
200
|
observed_rows: number
|
|
210
201
|
}
|
|
211
202
|
|
|
212
203
|
/**
|
|
213
|
-
* A publisher's
|
|
204
|
+
* A publisher's own mapping between two schemes, where it publishes one as a table.
|
|
214
205
|
*
|
|
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.
|
|
206
|
+
* Empty for Ireland: the mapping is not a function of the (authority, local code) pair, so it lives on
|
|
207
|
+
* `zoning_area` per row and {@linkcode assertCrosswalkIsNotATable} refuses a build that writes edges.
|
|
221
208
|
*/
|
|
222
209
|
export interface ZoningCrosswalkEdgeTable {
|
|
223
210
|
from_scheme: string
|
|
@@ -225,7 +212,9 @@ export interface ZoningCrosswalkEdgeTable {
|
|
|
225
212
|
to_scheme: string
|
|
226
213
|
to_code: string
|
|
227
214
|
/**
|
|
228
|
-
* The body that authored
|
|
215
|
+
* The body that authored this edge.
|
|
216
|
+
*
|
|
217
|
+
* Never us.
|
|
229
218
|
*/
|
|
230
219
|
authored_by: string
|
|
231
220
|
}
|
|
@@ -233,59 +222,27 @@ export interface ZoningCrosswalkEdgeTable {
|
|
|
233
222
|
/**
|
|
234
223
|
* Per (cell, polygon): does the polygon cover the whole cell, or only part of it?
|
|
235
224
|
*
|
|
236
|
-
*
|
|
237
|
-
*
|
|
225
|
+
* Keyed on the polygon rather than a code, because a zoning answer is the polygon
|
|
226
|
+
* and two authorities' plans can name the same code for different things.
|
|
227
|
+
*
|
|
228
|
+
* `containment` is one of {@link ZoningCellContainment}.
|
|
238
229
|
*/
|
|
239
|
-
export
|
|
240
|
-
/**
|
|
241
|
-
* 48-bit short H3 cell. Mixed-resolution: `whole` rows are compacted parent-ward, `partial` rows stay at the
|
|
242
|
-
* resolution the feature was indexed at.
|
|
243
|
-
*/
|
|
244
|
-
h3_cell: number
|
|
245
|
-
/**
|
|
246
|
-
* The resolution this row's cell was captured at. A short cell does not name its own resolution, and a table that
|
|
247
|
-
* mixes them cannot be probed without it.
|
|
248
|
-
*/
|
|
249
|
-
resolution: number
|
|
250
|
-
area_id: string
|
|
251
|
-
/**
|
|
252
|
-
* One of {@link ZoningCellContainment}.
|
|
253
|
-
*/
|
|
254
|
-
containment: string
|
|
255
|
-
}
|
|
230
|
+
export type ZoningCellTable = AreaCellIndexTable
|
|
256
231
|
|
|
257
232
|
/**
|
|
258
|
-
* The authority's own statement of what it
|
|
233
|
+
* The authority's own statement of what it mapped.
|
|
259
234
|
*
|
|
260
|
-
*
|
|
261
|
-
*
|
|
235
|
+
* One row per authority statement.
|
|
236
|
+
* The zoning polygons describe individual zones.
|
|
262
237
|
*
|
|
263
|
-
*
|
|
264
|
-
* footprint to record and `layer_coverage` carries `basis = source_present`. Donegal County Council's absence — the
|
|
265
|
-
* one local authority of 31 missing from the layer — was recovered by measuring `LA_CODE`, not read from a
|
|
266
|
-
* statement.
|
|
267
|
-
*
|
|
268
|
-
* Deriving a footprint from the union of the zoning polygons is forbidden: the union of zoned areas is not the area the
|
|
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.
|
|
238
|
+
* Use the authority statement for mapped extent instead of deriving the extent from the polygon union.
|
|
272
239
|
*/
|
|
273
|
-
export
|
|
274
|
-
extent_id: string
|
|
275
|
-
source: string
|
|
276
|
-
statement: string
|
|
277
|
-
statement_url: string
|
|
278
|
-
effective_date: string | null
|
|
279
|
-
min_lat: number
|
|
280
|
-
min_lon: number
|
|
281
|
-
max_lat: number
|
|
282
|
-
max_lon: number
|
|
283
|
-
}
|
|
240
|
+
export type ZoningMappedExtentTable = MappedExtentTable
|
|
284
241
|
|
|
285
242
|
/**
|
|
286
243
|
* Pass to `new DatabaseClient<ZoningDatabase>(...)`.
|
|
287
244
|
*/
|
|
288
|
-
export interface ZoningDatabase extends
|
|
245
|
+
export interface ZoningDatabase extends layerschemadatabase {
|
|
289
246
|
zoning_area: ZoningAreaTable
|
|
290
247
|
zoning_plan: ZoningPlanTable
|
|
291
248
|
zoning_jurisdiction: ZoningJurisdictionTable
|
|
@@ -296,14 +253,18 @@ export interface ZoningDatabase extends LayerContractDatabase {
|
|
|
296
253
|
}
|
|
297
254
|
|
|
298
255
|
/**
|
|
299
|
-
* The
|
|
300
|
-
*
|
|
256
|
+
* The subset of a Kysely handle the DDL touches.
|
|
257
|
+
*
|
|
258
|
+
* Same reasoning as `layerschemahandle`: Kysely is invariant in its schema parameter,
|
|
259
|
+
* so naming only the members these functions call lets a caller pass its own wider handle.
|
|
301
260
|
*/
|
|
302
261
|
export type ZoningSchemaHandle = Pick<Kysely<ZoningDatabase>, "schema">
|
|
303
262
|
|
|
304
263
|
/**
|
|
305
|
-
* Create `zoning_area`.
|
|
306
|
-
*
|
|
264
|
+
* Create `zoning_area`.
|
|
265
|
+
*
|
|
266
|
+
* A plain rowid table on purpose.
|
|
267
|
+
* The `rings` blob is exactly the payload `without rowid` penalizes.
|
|
307
268
|
*/
|
|
308
269
|
export async function createZoningAreaTable(db: ZoningSchemaHandle): Promise<void> {
|
|
309
270
|
const table = db.schema
|
|
@@ -325,15 +286,12 @@ export async function createZoningAreaTable(db: ZoningSchemaHandle): Promise<voi
|
|
|
325
286
|
.addColumn("signed_area_m2", "real", (c) => c.notNull())
|
|
326
287
|
|
|
327
288
|
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.
|
|
289
|
+
// `not NULL` by itself accepts `''`, so the value set and the blank are refused separately.
|
|
331
290
|
.addCheckConstraint(
|
|
332
291
|
"zoning_area_provenance_grade_declared",
|
|
333
292
|
sql`provenance_grade in ('authoritative', 'inferred') and trim(provenance_grade) != ''`
|
|
334
293
|
)
|
|
335
|
-
//
|
|
336
|
-
// only at the ingest: a blank would read as a zone the authority named nothing.
|
|
294
|
+
// A blank local code would read as a zone the authority left unnamed, so storage refuses it.
|
|
337
295
|
.addCheckConstraint("zoning_area_local_code_not_blank", sql`trim(local_code) != ''`)
|
|
338
296
|
.execute()
|
|
339
297
|
}
|
|
@@ -385,7 +343,7 @@ export async function createZoningVocabularyTable(db: ZoningSchemaHandle): Promi
|
|
|
385
343
|
}
|
|
386
344
|
|
|
387
345
|
/**
|
|
388
|
-
* Create `zoning_crosswalk_edge
|
|
346
|
+
* Create `zoning_crosswalk_edge`, empty for Ireland.
|
|
389
347
|
*/
|
|
390
348
|
export async function createZoningCrosswalkEdgeTable(db: ZoningSchemaHandle): Promise<void> {
|
|
391
349
|
await db.schema
|
|
@@ -400,22 +358,23 @@ export async function createZoningCrosswalkEdgeTable(db: ZoningSchemaHandle): Pr
|
|
|
400
358
|
}
|
|
401
359
|
|
|
402
360
|
/**
|
|
403
|
-
* Create `zoning_cell` — the summary tier.
|
|
404
|
-
*
|
|
361
|
+
* Create `zoning_cell` — the summary tier.
|
|
362
|
+
*
|
|
363
|
+
* This table stores small fixed-width rows.
|
|
364
|
+
* Queries use exact primary keys, the pattern supported by `WITHOUT ROWID`.
|
|
405
365
|
*/
|
|
406
366
|
export async function createZoningCellTable(db: ZoningSchemaHandle): Promise<void> {
|
|
407
367
|
const table = db.schema.createTable("zoning_cell")
|
|
408
368
|
|
|
409
369
|
await addCellIndexColumns(table, "area_id")
|
|
410
370
|
.addPrimaryKeyConstraint("zoning_cell_pk", ["h3_cell", "area_id"])
|
|
411
|
-
// `
|
|
371
|
+
// `without rowid` has no first-class builder, so the raw modifier is the fallback.
|
|
412
372
|
.modifyEnd(sql`without rowid`)
|
|
413
373
|
.execute()
|
|
414
374
|
}
|
|
415
375
|
|
|
416
376
|
/**
|
|
417
|
-
* Create `zoning_mapped_extent
|
|
418
|
-
* way — see the interface's docstring.
|
|
377
|
+
* Create `zoning_mapped_extent`, empty while the reader refuses a stronger coverage basis.
|
|
419
378
|
*/
|
|
420
379
|
export async function createZoningMappedExtentTable(db: ZoningSchemaHandle): Promise<void> {
|
|
421
380
|
const table = db.schema
|