@mailwoman/zoning 9.4.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 +48 -137
- 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 +106 -0
- package/out/sdk/ingest/chunk.d.ts.map +1 -0
- package/out/sdk/{ingest-chunk.js → ingest/chunk.js} +17 -50
- package/out/sdk/ingest/chunk.js.map +1 -0
- 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 +54 -77
- package/out/sdk/ingest.d.ts.map +1 -1
- package/out/sdk/ingest.js +50 -87
- package/out/sdk/ingest.js.map +1 -1
- package/out/sdk/measure-resolutions.d.ts +6 -23
- package/out/sdk/measure-resolutions.d.ts.map +1 -1
- package/out/sdk/measure-resolutions.js +4 -21
- 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 +100 -186
- 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/ingest-chunk.ts → sdk/ingest/chunk.ts} +32 -61
- 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 +8 -25
- package/{lib → sdk}/test-kit.ts +20 -43
- 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.ts +0 -398
- 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-chunk.d.ts +0 -130
- package/out/sdk/ingest-chunk.d.ts.map +0 -1
- package/out/sdk/ingest-chunk.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/index.ts
CHANGED
|
@@ -3,50 +3,7 @@
|
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
* authority's own vocabulary, and on what basis.
|
|
8
|
-
*
|
|
9
|
-
* TWO READINGS, AND THE ONE THAT IS MISSING IS THE POINT.
|
|
10
|
-
*
|
|
11
|
-
* 1. `designated` — an adopted plan places the location inside a zoning polygon, and the polygon is the
|
|
12
|
-
* answer: the authority's own code, its own description, the plan it belongs to and that plan's stated
|
|
13
|
-
* window, with the Department's national generic type BESIDE the local code rather than instead of it.
|
|
14
|
-
* 2. `unknown` — no polygon contains the point. THAT IS NOT AN ABSENCE READING, and this layer has none.
|
|
15
|
-
*
|
|
16
|
-
* THERE IS NO `designated_absence` HERE, AND ZONING IS THE HARDEST CASE OF THE RULE. For flood zones the
|
|
17
|
-
* Environment Agency states England-wide coverage and the Planning Practice Guidance defines Zone 1 as the
|
|
18
|
-
* land outside Zones 2 and 3, so an empty answer inside England IS a designation. No such definition exists
|
|
19
|
-
* anywhere for zoning: a location with no zoning polygon is outside any adopted plan area, or inside one on
|
|
20
|
-
* land the plan does not zone, or in a jurisdiction that has never adopted zoning, or in a jurisdiction
|
|
21
|
-
* whose records nobody has published — and no product distinguishes them. The source itself proves the
|
|
22
|
-
* asymmetry: it states `UNZ - Unzoned` as a POSITIVE value on 4 of 85,330 rows, so where the authority
|
|
23
|
-
* means unzoned it says so, and every other absence is a row that is not there.
|
|
24
|
-
*
|
|
25
|
-
* SO THE CONSTRUCTOR REFUSES A COVERAGE ROW THAT WOULD SUPPORT AN EXCLUSION. Every row must read
|
|
26
|
-
* `source_present`; `supportsExclusion` must be false for all of them. That is not a convention this reader
|
|
27
|
-
* follows — it is a condition it checks at open time, so the day someone writes a stronger basis without
|
|
28
|
-
* settling the footprint question, the layer refuses to open rather than answering confidently.
|
|
29
|
-
*
|
|
30
|
-
* NEITHER READING IS A STATEMENT ABOUT WHAT MAY BE BUILT. The layer reports what a plan assigns at a
|
|
31
|
-
* location, which is a fact about the plan. The Department states that its data are "not published here as
|
|
32
|
-
* legal definitions of the current actuality with regard to Local Authority zoning or their geographic
|
|
33
|
-
* extents" and that "Original data should be sourced directly from the relevant Local Authority" — and
|
|
34
|
-
* `limits` carries the authority's own exclusions on every answer.
|
|
35
|
-
*
|
|
36
|
-
* THE PLAN IS PART OF THE CLAIM, NEVER A PARAMETER OF IT. A zone exists inside a named Development Plan or
|
|
37
|
-
* Local Area Plan with a stated validity window; a reading that dropped the plan would answer a question no
|
|
38
|
-
* authority asked. And `currentPlan = 1` means "not superseded", not "in force today": 2,363 of 85,330 rows
|
|
39
|
-
* carry a `validTo` already in the past, so the window travels on every reading and the comparison against a
|
|
40
|
-
* date is the caller's, made against a clock this reader does not own.
|
|
41
|
-
*
|
|
42
|
-
* THE PROBE IS STRUCTURE FIRST, GEOMETRY LAST. `cellToParent` up the compacted whole-cell chain answers an
|
|
43
|
-
* interior point with primary-key probes alone; only a cell a boundary crosses reaches the ray cast, and
|
|
44
|
-
* then only against the polygons `zoning_cell` already named for that cell.
|
|
45
|
-
*
|
|
46
|
-
* THE READER IS SYNCHRONOUS AND USES RAW PREPARED STATEMENTS, for the same reason the sibling layer readers
|
|
47
|
-
* are: it answers one point per geocode with a bounded number of primary-key probes plus a bounded geometry
|
|
48
|
-
* read, and the ray cast it wraps is synchronous anyway. The DDL that created these tables IS Kysely — see
|
|
49
|
-
* `schema.ts`.
|
|
6
|
+
* Synchronous reader for `zoning-ireland.db` that returns the zoning an adopted local plan assigns at a coordinate.
|
|
50
7
|
*/
|
|
51
8
|
|
|
52
9
|
import {
|
|
@@ -68,6 +25,7 @@ import {
|
|
|
68
25
|
import { readCoverageAt } from "@mailwoman/spatial/h3/coverage"
|
|
69
26
|
import { DatabaseClient } from "@mailwoman/sqlite/client"
|
|
70
27
|
import { latLngToCell } from "h3-js"
|
|
28
|
+
import type { PathBuilderLike } from "path-ts"
|
|
71
29
|
|
|
72
30
|
import type { ZoningDatabase } from "#schema"
|
|
73
31
|
import { ZoningCellContainment } from "#schema"
|
|
@@ -82,7 +40,7 @@ import {
|
|
|
82
40
|
export { GZT_LAYER_NAME, ProvenanceGrade } from "#vocabulary"
|
|
83
41
|
|
|
84
42
|
/**
|
|
85
|
-
*
|
|
43
|
+
* The kinds of answer the layer gives for a coordinate.
|
|
86
44
|
*/
|
|
87
45
|
export const ZoningReadingKind = {
|
|
88
46
|
/**
|
|
@@ -90,31 +48,37 @@ export const ZoningReadingKind = {
|
|
|
90
48
|
*/
|
|
91
49
|
Designated: "designated",
|
|
92
50
|
/**
|
|
93
|
-
* No zoning polygon contains the point
|
|
51
|
+
* No zoning polygon contains the point — this kind never means the location is unzoned.
|
|
94
52
|
*/
|
|
95
53
|
Unknown: "unknown",
|
|
96
54
|
} as const
|
|
97
55
|
|
|
56
|
+
/**
|
|
57
|
+
* One of the {@link ZoningReadingKind} values.
|
|
58
|
+
*/
|
|
98
59
|
export type ZoningReadingKind = (typeof ZoningReadingKind)[keyof typeof ZoningReadingKind]
|
|
99
60
|
|
|
100
61
|
/**
|
|
101
|
-
* How
|
|
62
|
+
* How the lookup established containment.
|
|
102
63
|
*/
|
|
103
64
|
export const ZoningContainmentPath = {
|
|
104
65
|
/**
|
|
105
|
-
* The cell lies wholly inside the zone
|
|
66
|
+
* The cell lies wholly inside the zone, so no geometry was read.
|
|
106
67
|
*/
|
|
107
68
|
WholeCell: "whole_cell",
|
|
108
69
|
/**
|
|
109
|
-
*
|
|
70
|
+
* A boundary crosses the cell, so the point was ray-cast against the cell's polygons.
|
|
110
71
|
*/
|
|
111
72
|
RayCast: "ray_cast",
|
|
112
73
|
/**
|
|
113
|
-
* No zone reaches this cell
|
|
74
|
+
* No zone reaches this cell.
|
|
114
75
|
*/
|
|
115
76
|
NoZoneCell: "no_zone_cell",
|
|
116
77
|
} as const
|
|
117
78
|
|
|
79
|
+
/**
|
|
80
|
+
* One of the {@link ZoningContainmentPath} values.
|
|
81
|
+
*/
|
|
118
82
|
export type ZoningContainmentPath = (typeof ZoningContainmentPath)[keyof typeof ZoningContainmentPath]
|
|
119
83
|
|
|
120
84
|
/**
|
|
@@ -124,148 +88,167 @@ export interface ZoningJurisdiction {
|
|
|
124
88
|
jurisdictionID: string
|
|
125
89
|
name: string
|
|
126
90
|
/**
|
|
127
|
-
* The publisher's
|
|
91
|
+
* The publisher's code, verbatim.
|
|
128
92
|
*/
|
|
129
93
|
sourceCode: string
|
|
130
94
|
country: string
|
|
131
95
|
}
|
|
132
96
|
|
|
133
97
|
/**
|
|
134
|
-
* The plan a zone belongs to, with its
|
|
98
|
+
* The plan that a zone belongs to, with its stated validity window.
|
|
99
|
+
*
|
|
100
|
+
* The caller must compare the window with the current date, because a plan that is
|
|
101
|
+
* not superseded can still have a `validTo` in the past.
|
|
135
102
|
*/
|
|
136
103
|
export interface ZoningPlan {
|
|
137
104
|
planID: string
|
|
138
105
|
name: string
|
|
139
106
|
/**
|
|
140
|
-
* `DP` Development Plan, `LAP` Local Area Plan
|
|
107
|
+
* The plan level: `DP` for Development Plan, `LAP` for Local Area Plan
|
|
108
|
+
* or `SDZ` for Strategic Development Zone.
|
|
141
109
|
*/
|
|
142
110
|
level: string
|
|
143
111
|
validFrom: string | null
|
|
144
112
|
validTo: string | null
|
|
145
113
|
/**
|
|
146
|
-
* The publisher's `CURRENT_PLAN` flag
|
|
114
|
+
* The publisher's `CURRENT_PLAN` flag as published.
|
|
115
|
+
*
|
|
116
|
+
* The value `1` means the plan is active.
|
|
117
|
+
* `validTo` determines whether it has force today.
|
|
147
118
|
*/
|
|
148
119
|
currentPlan: number
|
|
149
120
|
}
|
|
150
121
|
|
|
151
122
|
/**
|
|
152
|
-
* One zoning polygon the point
|
|
123
|
+
* One zoning polygon that contains the point, as the authority publishes it.
|
|
153
124
|
*/
|
|
154
125
|
export interface ZoningDesignation {
|
|
155
126
|
areaID: string
|
|
156
127
|
/**
|
|
157
|
-
* The authority's
|
|
128
|
+
* The authority's zone code, verbatim.
|
|
158
129
|
*/
|
|
159
130
|
localCode: string
|
|
160
131
|
localDescription: string | null
|
|
161
132
|
localCodeURL: string | null
|
|
162
133
|
/**
|
|
163
|
-
* The
|
|
164
|
-
*
|
|
165
|
-
*
|
|
134
|
+
* The publisher's crosswalk from the local code into a shared scheme, when it publishes one.
|
|
135
|
+
*
|
|
136
|
+
* The crosswalk is stored per polygon because one local code can map to several
|
|
137
|
+
* generic types, so it cannot be derived from `localCode`.
|
|
166
138
|
*/
|
|
167
139
|
crosswalk?: {
|
|
168
140
|
scheme: string
|
|
169
141
|
code: string
|
|
170
142
|
description: string | null
|
|
171
143
|
/**
|
|
172
|
-
* A coarser code from the same authority,
|
|
144
|
+
* A coarser code from the same authority, as published.
|
|
173
145
|
*/
|
|
174
146
|
rollup: string | null
|
|
175
147
|
/**
|
|
176
|
-
* The publisher's
|
|
177
|
-
*
|
|
148
|
+
* The publisher's label for `code` from its declared domain.
|
|
149
|
+
*
|
|
150
|
+
* It is absent for a code that the publisher uses without declaring.
|
|
178
151
|
*/
|
|
179
152
|
label?: string
|
|
180
153
|
/**
|
|
181
|
-
*
|
|
154
|
+
* Whether the publisher declares this code in its own domain.
|
|
182
155
|
*/
|
|
183
156
|
declared: boolean
|
|
184
157
|
}
|
|
185
158
|
/**
|
|
186
|
-
* One of {@link ProvenanceGrade}.
|
|
187
|
-
*
|
|
159
|
+
* One of {@link ProvenanceGrade}.
|
|
160
|
+
*
|
|
161
|
+
* Every row of this artifact is `authoritative`.
|
|
162
|
+
* A caller must never present an `inferred` row as the authority's designation.
|
|
188
163
|
*/
|
|
189
164
|
provenanceGrade: string
|
|
190
165
|
jurisdiction: ZoningJurisdiction
|
|
191
166
|
plan: ZoningPlan
|
|
192
167
|
/**
|
|
193
|
-
*
|
|
194
|
-
*
|
|
168
|
+
* Whether the authority explicitly zones this polygon as unzoned.
|
|
169
|
+
*
|
|
170
|
+
* Only this flag means unzoned.
|
|
171
|
+
* A point with no designation makes no statement about zoning.
|
|
195
172
|
*/
|
|
196
173
|
unzoned: boolean
|
|
197
174
|
containment: ZoningContainmentPath
|
|
198
175
|
}
|
|
199
176
|
|
|
200
177
|
/**
|
|
201
|
-
* One reading,
|
|
178
|
+
* One reading at a coordinate, with the provenance a caller needs to check it.
|
|
202
179
|
*/
|
|
203
180
|
export interface ZoningReading {
|
|
204
181
|
kind: ZoningReadingKind
|
|
205
182
|
/**
|
|
206
|
-
* Every polygon
|
|
207
|
-
*
|
|
183
|
+
* Every polygon that contains the point, ordered by `area_id`.
|
|
184
|
+
*
|
|
185
|
+
* A Local Area Plan that overlays a Development Plan produces two designations for the same ground.
|
|
208
186
|
*/
|
|
209
187
|
designations: ZoningDesignation[]
|
|
210
188
|
containment: ZoningContainmentPath
|
|
211
189
|
/**
|
|
212
|
-
* The coverage row for the location, when the product has data in that cell.
|
|
213
|
-
*
|
|
214
|
-
*
|
|
190
|
+
* The coverage row for the location, when the product has data in that cell.
|
|
191
|
+
*
|
|
192
|
+
* Its basis is always `source_present`, which only shows that the source has data nearby.
|
|
193
|
+
* Neither a present nor an absent coverage row means the location is unrestricted.
|
|
215
194
|
*/
|
|
216
195
|
coverage?: CoverageCell & { h3CellIndex: string; resolution: number }
|
|
217
196
|
/**
|
|
218
|
-
* The index cell
|
|
197
|
+
* The H3 index cell that the lookup probed.
|
|
219
198
|
*/
|
|
220
199
|
indexCellIndex: string
|
|
221
200
|
/**
|
|
222
|
-
*
|
|
201
|
+
* The authority's own statements of what the product does not state.
|
|
223
202
|
*/
|
|
224
203
|
limits: ReadonlyArray<string>
|
|
225
204
|
/**
|
|
226
|
-
*
|
|
205
|
+
* One sentence on why this layer's coverage supports no negative claim.
|
|
227
206
|
*/
|
|
228
207
|
coverageLimit: string
|
|
229
208
|
}
|
|
230
209
|
|
|
231
210
|
/**
|
|
232
|
-
* The layer's identity, read once
|
|
211
|
+
* The layer's identity, read once when the database opens.
|
|
233
212
|
*/
|
|
234
213
|
export interface ZoningLayerIdentity {
|
|
235
214
|
manifest: LayerManifest
|
|
236
215
|
indexResolution: number
|
|
237
216
|
coverageResolution: number
|
|
238
217
|
/**
|
|
239
|
-
* Every resolution `zoning_cell` stores
|
|
218
|
+
* Every resolution at which `zoning_cell` stores rows, coarsest first.
|
|
240
219
|
*
|
|
241
|
-
*
|
|
242
|
-
*
|
|
243
|
-
*
|
|
220
|
+
* A probe walks all of them because whole cells are compacted into parents.
|
|
221
|
+
* The builder indexes a polygon at a coarser resolution when the h3 allocator
|
|
222
|
+
* cannot fit it at the index resolution.
|
|
244
223
|
*/
|
|
245
224
|
cellResolutions: number[]
|
|
246
225
|
/**
|
|
247
|
-
* The jurisdictions the layer
|
|
226
|
+
* The jurisdictions in the layer, keyed by id.
|
|
248
227
|
*/
|
|
249
228
|
jurisdictions: ReadonlyMap<string, ZoningJurisdiction>
|
|
250
229
|
/**
|
|
251
|
-
* The crosswalk scheme this layer's rows
|
|
230
|
+
* The crosswalk scheme of this layer's rows, or `undefined` when the publisher ships none.
|
|
252
231
|
*/
|
|
253
232
|
crosswalkScheme?: string
|
|
254
233
|
/**
|
|
255
|
-
* The authority's footprint statements.
|
|
256
|
-
*
|
|
234
|
+
* The authority's footprint statements.
|
|
235
|
+
*
|
|
236
|
+
* This edition has none, so `source_present` is the only coverage basis allowed.
|
|
257
237
|
*/
|
|
258
238
|
mappedExtents: Array<{ extentID: string; source: string; statement: string; statementURL: string }>
|
|
259
239
|
/**
|
|
260
|
-
* The coverage basis every row
|
|
261
|
-
*
|
|
240
|
+
* The coverage basis of every row.
|
|
241
|
+
* It is `source_present` while `mappedExtents` is empty.
|
|
262
242
|
*/
|
|
263
243
|
coverageBasis: CoverageBasis
|
|
264
244
|
databasePath: string
|
|
265
245
|
}
|
|
266
246
|
|
|
247
|
+
/**
|
|
248
|
+
* Options for {@link ZoningLookup}.
|
|
249
|
+
*/
|
|
267
250
|
export interface ZoningLookupOptions {
|
|
268
|
-
databasePath:
|
|
251
|
+
databasePath: PathBuilderLike
|
|
269
252
|
}
|
|
270
253
|
|
|
271
254
|
interface AreaRow {
|
|
@@ -296,13 +279,10 @@ interface PlanRow {
|
|
|
296
279
|
}
|
|
297
280
|
|
|
298
281
|
/**
|
|
299
|
-
*
|
|
282
|
+
* Reads a sealed `zoning-ireland.db`.
|
|
300
283
|
*
|
|
301
|
-
*
|
|
302
|
-
*
|
|
303
|
-
* support an exclusion, an empty jurisdiction table. Each of those would otherwise present as a reader that quietly
|
|
304
|
-
* always answers `unknown` — or, in the exclusion case, as a reader that confidently reports unzoned-and-unmapped land
|
|
305
|
-
* as free of restriction.
|
|
284
|
+
* The constructor throws on a manifest for a different layer, an empty coverage table,
|
|
285
|
+
* a coverage basis that supports exclusion or an empty jurisdiction table.
|
|
306
286
|
*/
|
|
307
287
|
export class ZoningLookup implements Disposable {
|
|
308
288
|
readonly identity: ZoningLayerIdentity
|
|
@@ -319,7 +299,7 @@ export class ZoningLookup implements Disposable {
|
|
|
319
299
|
this.#database = new DatabaseClient<ZoningDatabase>(options.databasePath, { readOnly: true })
|
|
320
300
|
|
|
321
301
|
try {
|
|
322
|
-
this.identity = readIdentity(this.#database, options.databasePath)
|
|
302
|
+
this.identity = readIdentity(this.#database, options.databasePath.toString())
|
|
323
303
|
this.#crosswalkTerms = readCrosswalkTerms(this.#database)
|
|
324
304
|
} catch (error) {
|
|
325
305
|
this.#database.destroy()
|
|
@@ -329,10 +309,9 @@ export class ZoningLookup implements Disposable {
|
|
|
329
309
|
|
|
330
310
|
this.#selectCell = this.#database.prepare("SELECT area_id, containment FROM zoning_cell WHERE h3_cell = ?")
|
|
331
311
|
|
|
332
|
-
//
|
|
333
|
-
//
|
|
334
|
-
//
|
|
335
|
-
// all.
|
|
312
|
+
// Read without the ring blob.
|
|
313
|
+
// The bounding box rejects most polygons before the ray cast needs rings.
|
|
314
|
+
// A whole cell never reads the blob.
|
|
336
315
|
this.#selectArea = this.#database.prepare(
|
|
337
316
|
"SELECT area_id, jurisdiction_id, plan_id, local_code, local_description, local_code_url, crosswalk_code, " +
|
|
338
317
|
"crosswalk_scheme, crosswalk_description, crosswalk_rollup, provenance_grade, min_lat, min_lon, max_lat, max_lon " +
|
|
@@ -351,7 +330,7 @@ export class ZoningLookup implements Disposable {
|
|
|
351
330
|
}
|
|
352
331
|
|
|
353
332
|
/**
|
|
354
|
-
*
|
|
333
|
+
* Returns what an adopted plan assigns at this coordinate.
|
|
355
334
|
*/
|
|
356
335
|
public lookup(latitude: number, longitude: number): ZoningReading {
|
|
357
336
|
const indexCell = latLngToCell(latitude, longitude, this.identity.indexResolution) as H3Cell
|
|
@@ -374,14 +353,14 @@ export class ZoningLookup implements Disposable {
|
|
|
374
353
|
}
|
|
375
354
|
|
|
376
355
|
/**
|
|
377
|
-
*
|
|
356
|
+
* Returns the coverage row for the index cell's parent at the coverage resolution.
|
|
378
357
|
*/
|
|
379
358
|
#readCoverage(indexCell: H3Cell): (CoverageCell & { h3CellIndex: string; resolution: number }) | undefined {
|
|
380
359
|
return readCoverageAt(this.#selectCoverage, indexCell, this.identity.coverageResolution)
|
|
381
360
|
}
|
|
382
361
|
|
|
383
362
|
/**
|
|
384
|
-
*
|
|
363
|
+
* Walks the cell index up the ancestor chain and reads geometry only for cells that a boundary crosses.
|
|
385
364
|
*/
|
|
386
365
|
#resolveDesignations(
|
|
387
366
|
indexCell: H3Cell,
|
|
@@ -416,7 +395,6 @@ export class ZoningLookup implements Disposable {
|
|
|
416
395
|
let rayCastRan = false
|
|
417
396
|
|
|
418
397
|
for (const areaID of [...partial].toSorted()) {
|
|
419
|
-
// A polygon that already answered `whole` higher in the chain needs no geometry read.
|
|
420
398
|
if (whole.has(areaID)) continue
|
|
421
399
|
|
|
422
400
|
const area = this.#selectArea.get(areaID) as AreaRow | undefined
|
|
@@ -425,8 +403,6 @@ export class ZoningLookup implements Disposable {
|
|
|
425
403
|
|
|
426
404
|
rayCastRan = true
|
|
427
405
|
|
|
428
|
-
// The bbox is the prefilter the geometry table stores precisely so the ray cast runs on the few polygons that
|
|
429
|
-
// could contain the point rather than on every polygon reaching the cell.
|
|
430
406
|
if (!bboxContains(area, longitude, latitude)) {
|
|
431
407
|
continue
|
|
432
408
|
}
|
|
@@ -456,7 +432,7 @@ export class ZoningLookup implements Disposable {
|
|
|
456
432
|
}
|
|
457
433
|
|
|
458
434
|
/**
|
|
459
|
-
*
|
|
435
|
+
* Converts a stored row to a designation with its plan and jurisdiction.
|
|
460
436
|
*/
|
|
461
437
|
#toDesignation(area: AreaRow, containment: ZoningContainmentPath): ZoningDesignation {
|
|
462
438
|
const plan = this.#selectPlan.get(area.plan_id) as PlanRow | undefined
|
|
@@ -475,8 +451,6 @@ export class ZoningLookup implements Disposable {
|
|
|
475
451
|
localCode: area.local_code,
|
|
476
452
|
localDescription: area.local_description,
|
|
477
453
|
localCodeURL: area.local_code_url,
|
|
478
|
-
// The crosswalk travels as one object or not at all: a code without its scheme reads as a code in whichever
|
|
479
|
-
// vocabulary the consumer happened to assume.
|
|
480
454
|
...(area.crosswalk_code === null || area.crosswalk_scheme === null
|
|
481
455
|
? {}
|
|
482
456
|
: {
|
|
@@ -505,9 +479,6 @@ export class ZoningLookup implements Disposable {
|
|
|
505
479
|
}
|
|
506
480
|
}
|
|
507
481
|
|
|
508
|
-
/**
|
|
509
|
-
* The publisher's crosswalk domain, by code — its label and whether the publisher DECLARED it.
|
|
510
|
-
*/
|
|
511
482
|
function readCrosswalkTerms(
|
|
512
483
|
database: DatabaseClient<ZoningDatabase>
|
|
513
484
|
): ReadonlyMap<string, { label: string; declared: boolean }> {
|
|
@@ -519,7 +490,7 @@ function readCrosswalkTerms(
|
|
|
519
490
|
}
|
|
520
491
|
|
|
521
492
|
/**
|
|
522
|
-
*
|
|
493
|
+
* Reads the layer's identity and throws if it is unusable.
|
|
523
494
|
*/
|
|
524
495
|
function readIdentity(database: DatabaseClient<ZoningDatabase>, databasePath: string): ZoningLayerIdentity {
|
|
525
496
|
const manifest = parseManifestRows(
|
|
@@ -534,10 +505,8 @@ function readIdentity(database: DatabaseClient<ZoningDatabase>, databasePath: st
|
|
|
534
505
|
throw new Error(`zoning reader: ${databasePath} declares no h3 spine key`)
|
|
535
506
|
}
|
|
536
507
|
|
|
537
|
-
//
|
|
538
|
-
//
|
|
539
|
-
// basis reaching a caller would let an absent polygon be read as a designation of freedom to build over most of the
|
|
540
|
-
// map. The check itself is the contract's rather than this product's; the SENTENCE saying why is this product's.
|
|
508
|
+
// The Department publishes its coverage footprint only in a map viewer,
|
|
509
|
+
// so no coverage row may support a claim that a location is unrestricted.
|
|
541
510
|
assertCoverageLicensesNoExclusion(
|
|
542
511
|
(database.prepare("SELECT DISTINCT basis FROM layer_coverage").all() as Array<{ basis: string | null }>).map(
|
|
543
512
|
(coverageRow) => coverageRow.basis
|
|
@@ -576,10 +545,10 @@ function readIdentity(database: DatabaseClient<ZoningDatabase>, databasePath: st
|
|
|
576
545
|
.all() as Array<{ crosswalk_scheme: string }>
|
|
577
546
|
).map((entry) => entry.crosswalk_scheme)
|
|
578
547
|
|
|
579
|
-
//
|
|
580
|
-
//
|
|
581
|
-
//
|
|
582
|
-
//
|
|
548
|
+
// The layer stores no coverage resolution.
|
|
549
|
+
// The code recovers it from the coverage cells.
|
|
550
|
+
// A short cell expands to a valid index at exactly one resolution.
|
|
551
|
+
// The helper throws on mixed resolutions.
|
|
583
552
|
const coverageResolution = recoverShortCellResolution(
|
|
584
553
|
(database.prepare("SELECT h3_cell FROM layer_coverage").all() as Array<{ h3_cell: number }>).map(
|
|
585
554
|
(coverageRow) => coverageRow.h3_cell
|
package/lib/paths.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Where the zoning layer database and its download cache live under the data root's `db/` group.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { databaseRootPath, dataRootPath } from "@mailwoman/core/data-root"
|
|
10
|
+
import type { PathBuilder, PathBuilderLike } from "path-ts"
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* `<dataRoot>/db/zoning`.
|
|
14
|
+
*/
|
|
15
|
+
export function zoningDatabaseRoot(dataRoot: PathBuilderLike): PathBuilder {
|
|
16
|
+
return databaseRootPath(dataRoot)("zoning")
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* `$MAILWOMAN_DATA_ROOT/db/zoning`, read when a path is requested.
|
|
21
|
+
*
|
|
22
|
+
* @see {@link zoningDatabaseRoot} for another data root.
|
|
23
|
+
*/
|
|
24
|
+
export const zoningDatabasePath: PathBuilder = zoningDatabaseRoot(dataRootPath())
|