@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/sdk → sdk}/cells.ts
RENAMED
|
@@ -3,28 +3,7 @@
|
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* THE CLASSIFIER ITSELF LIVES IN `@mailwoman/spatial`, re-exported below so this package's call sites and
|
|
9
|
-
* its `@mailwoman/zoning/sdk/cells` subpath keep reading the same. `classifyFeatureCells`, the per-PART
|
|
10
|
-
* zero-cell guard and the allocator-avoiding shortcuts around it are properties of h3-js rather than of
|
|
11
|
-
* this product — the layer contract's polygon-builder section states them as requirements on EVERY polygon
|
|
12
|
-
* builder — and a second copy of the zero-cell guard is a second place for it to stop guarding.
|
|
13
|
-
*
|
|
14
|
-
* WHAT THIS LAYER ADDS IS THE NUMBER THE RESOLUTION IS ACTUALLY CHOSEN FROM, AND IT IS NOT THE `partial`
|
|
15
|
-
* SHARE. The inherited size contract picks a resolution from the measured `partial` share, and for this
|
|
16
|
-
* subject that statistic carries no signal: computed over all 85,330 Irish features, the median zoning
|
|
17
|
-
* polygon is 4,497 m² against an average res-9 cell of 105,333 m², so 95.7% of them are smaller than a cell
|
|
18
|
-
* and the `partial` share is near 100% at every candidate. Two numbers do carry signal —
|
|
19
|
-
* CANDIDATES PER CELL, which is how much geometry a probe reads, and the POLYFILL-ONLY ZERO-CELL COUNT,
|
|
20
|
-
* which is how many features a centre-in-polygon index would have dropped — so both are measured here and
|
|
21
|
-
* the `partial` share is reported beside them rather than in place of them.
|
|
22
|
-
*
|
|
23
|
-
* THE ZERO-CELL COUNT IS A MEASUREMENT OF THE ALTERNATIVE, NOT OF THIS INDEX. `classifyFeatureCells` takes
|
|
24
|
-
* overlapping containment and REFUSES a feature that reaches no cell, so this index's own zero-cell count is
|
|
25
|
-
* zero by construction. What the column reports is what `polygonToCells` — the centre-in-polygon polyfill a
|
|
26
|
-
* builder reaches for first — would have returned nothing for, and every one of those would have read
|
|
27
|
-
* downstream as an absence of zoning.
|
|
6
|
+
* The cell classifier lives in `@mailwoman/spatial`, and this layer adds the candidates-per-cell and polyfill-only zero-cell measurements the resolution is chosen from.
|
|
28
7
|
*/
|
|
29
8
|
|
|
30
9
|
import {
|
|
@@ -37,15 +16,12 @@ import {
|
|
|
37
16
|
import { polygonToCells } from "h3-js"
|
|
38
17
|
|
|
39
18
|
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* The measurement that forced this layer's index to take cell-touches-polygon: at resolution 9 `polygonToCells` returns
|
|
43
|
-
* an empty set for the great majority of Irish zoning polygons, because no cell centre falls inside them. A builder
|
|
44
|
-
* indexing only the polyfill output would drop every one of them silently.
|
|
19
|
+
* Whether a center-in-polygon polyfill would return no cell for this feature,
|
|
20
|
+
* the measurement that forced the index to take cell-touches-polygon.
|
|
45
21
|
*/
|
|
46
22
|
export function polyfillFindsNothing(polygons: MultiPolygonRings, resolution: number): boolean {
|
|
47
23
|
for (const rings of polygons) {
|
|
48
|
-
// `isGeoJSON = true`: the rings are already `[lon, lat]
|
|
24
|
+
// `isGeoJSON = true`: the rings are already `[lon, lat]`.
|
|
49
25
|
if (polygonToCells(rings as number[][][], resolution, true).length) return false
|
|
50
26
|
}
|
|
51
27
|
|
|
@@ -53,17 +29,15 @@ export function polyfillFindsNothing(polygons: MultiPolygonRings, resolution: nu
|
|
|
53
29
|
}
|
|
54
30
|
|
|
55
31
|
/**
|
|
56
|
-
* What one resolution came out as over the whole set
|
|
32
|
+
* What one resolution came out as over the whole set, the numbers the resolution choice is made from.
|
|
57
33
|
*/
|
|
58
34
|
export interface CellIndexMeasurement {
|
|
59
35
|
resolution: number
|
|
60
36
|
features: number
|
|
61
|
-
|
|
62
|
-
* Cells the layer reaches at all.
|
|
63
|
-
*/
|
|
37
|
+
|
|
64
38
|
touchedCells: number
|
|
65
39
|
/**
|
|
66
|
-
* Cells answered by the index
|
|
40
|
+
* Cells answered by the index by itself, before compaction.
|
|
67
41
|
*/
|
|
68
42
|
wholeCells: number
|
|
69
43
|
/**
|
|
@@ -71,7 +45,7 @@ export interface CellIndexMeasurement {
|
|
|
71
45
|
*/
|
|
72
46
|
partialCells: number
|
|
73
47
|
/**
|
|
74
|
-
* `partialCells / touchedCells
|
|
48
|
+
* `partialCells / touchedCells`, reported rather than chosen on.
|
|
75
49
|
*/
|
|
76
50
|
partialShare: number
|
|
77
51
|
/**
|
|
@@ -83,38 +57,35 @@ export interface CellIndexMeasurement {
|
|
|
83
57
|
*/
|
|
84
58
|
storedCellRows: number
|
|
85
59
|
/**
|
|
86
|
-
*
|
|
87
|
-
*
|
|
60
|
+
* Polygon count per cell across all cells the layer reaches.
|
|
61
|
+
* A probe pays this cost.
|
|
88
62
|
*/
|
|
89
63
|
candidatesPerCell: { mean: number; p90: number; max: number }
|
|
90
64
|
/**
|
|
91
|
-
*
|
|
65
|
+
* Count of cells naming more than one polygon and their share among touched cells.
|
|
92
66
|
*/
|
|
93
67
|
multiCandidateCells: number
|
|
94
68
|
multiCandidateShare: number
|
|
95
69
|
/**
|
|
96
|
-
* Features a
|
|
97
|
-
* `
|
|
70
|
+
* Features a center-in-polygon polyfill would have returned no cell for —
|
|
71
|
+
* see {@link polyfillFindsNothing} — and `null` where the measurement did not run it.
|
|
98
72
|
*/
|
|
99
|
-
polyfillZeroCellFeatures
|
|
73
|
+
polyfillZeroCellFeatures: number | null
|
|
100
74
|
/**
|
|
101
75
|
* Features whose bounding box forced a coarser resolution than the target — see `CELL_ESTIMATE_BUDGET`.
|
|
102
76
|
*/
|
|
103
77
|
coarsenedFeatures: number
|
|
104
78
|
/**
|
|
105
|
-
* Features this index returned no cell for
|
|
106
|
-
*
|
|
79
|
+
* Features this index returned no cell for, always zero while `classifyFeatureCells`
|
|
80
|
+
* throws rather than returning an empty set.
|
|
107
81
|
*/
|
|
108
82
|
zeroCellFeatures: number
|
|
109
83
|
}
|
|
110
84
|
|
|
111
85
|
/**
|
|
112
|
-
* Accumulate one resolution's cell index over a stream of features
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
* h3-js function over full indexes and round-tripping at every step would cost more than the strings do. The candidate
|
|
116
|
-
* counter is keyed by the 48-bit INTEGER instead: it is the larger of the two at every candidate resolution, and it is
|
|
117
|
-
* never handed back to h3.
|
|
86
|
+
* Accumulate one resolution's cell index over a stream of features, holding
|
|
87
|
+
* whole cells as short-cell strings and the candidate counter by 48-bit integer
|
|
88
|
+
* because `compactCells` is an h3-js function over full indexes.
|
|
118
89
|
*/
|
|
119
90
|
export class ZoningCellIndex {
|
|
120
91
|
readonly resolution: number
|
|
@@ -133,9 +104,6 @@ export class ZoningCellIndex {
|
|
|
133
104
|
this.resolution = resolution
|
|
134
105
|
}
|
|
135
106
|
|
|
136
|
-
/**
|
|
137
|
-
* Fold one feature's classification in.
|
|
138
|
-
*/
|
|
139
107
|
add(cells: FeatureCells): void {
|
|
140
108
|
this.#features++
|
|
141
109
|
|
|
@@ -158,9 +126,6 @@ export class ZoningCellIndex {
|
|
|
158
126
|
}
|
|
159
127
|
}
|
|
160
128
|
|
|
161
|
-
/**
|
|
162
|
-
* Record that a centre-in-polygon polyfill found nothing for one feature.
|
|
163
|
-
*/
|
|
164
129
|
addPolyfillProbe(foundNothing: boolean): void {
|
|
165
130
|
this.#measuredPolyfill = true
|
|
166
131
|
|
|
@@ -172,10 +137,8 @@ export class ZoningCellIndex {
|
|
|
172
137
|
/**
|
|
173
138
|
* The measurement.
|
|
174
139
|
*
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
* a lower bound on the stored row count — the direction a size estimate should err in — and the build's own receipt
|
|
178
|
-
* reports the real number.
|
|
140
|
+
* Its compacted count is a lower bound on stored rows.
|
|
141
|
+
* The compaction uses the feature union rather than each feature.
|
|
179
142
|
*/
|
|
180
143
|
finish(): CellIndexMeasurement {
|
|
181
144
|
const compacted = compactAcrossResolutions(this.#whole).length
|
|
@@ -218,13 +181,14 @@ export class ZoningCellIndex {
|
|
|
218
181
|
storedCellRows: compacted + partial,
|
|
219
182
|
candidatesPerCell: {
|
|
220
183
|
mean: touched ? total / touched : 0,
|
|
221
|
-
// Nearest-rank p90 over
|
|
184
|
+
// Nearest-rank p90 over candidate counts.
|
|
185
|
+
// This matches `@mailwoman/core/stats`.
|
|
222
186
|
p90: counts.length ? counts[Math.min(counts.length - 1, Math.ceil(0.9 * counts.length) - 1)]! : 0,
|
|
223
187
|
max,
|
|
224
188
|
},
|
|
225
189
|
multiCandidateCells: multi,
|
|
226
190
|
multiCandidateShare: touched ? multi / touched : 0,
|
|
227
|
-
|
|
191
|
+
polyfillZeroCellFeatures: this.#measuredPolyfill ? this.#polyfillZeroCell : null,
|
|
228
192
|
coarsenedFeatures: this.#coarsened,
|
|
229
193
|
zeroCellFeatures: this.#zeroCell,
|
|
230
194
|
}
|
|
@@ -238,11 +202,8 @@ export class ZoningCellIndex {
|
|
|
238
202
|
}
|
|
239
203
|
|
|
240
204
|
/**
|
|
241
|
-
* The measurement as markdown table
|
|
242
|
-
*
|
|
243
|
-
*
|
|
244
|
-
* THE ZERO-CELL COLUMN IS FIRST AFTER THE COUNTS, because it is the column the resolution is chosen on and the one a
|
|
245
|
-
* reader most needs to see is not zero for the alternative index.
|
|
205
|
+
* The measurement as markdown table rows, one line per element, with the zero-cell column first
|
|
206
|
+
* after the counts because it is the column the resolution is chosen on.
|
|
246
207
|
*/
|
|
247
208
|
export function formatResolutionRows(measurements: readonly CellIndexMeasurement[]): string[] {
|
|
248
209
|
return [
|
|
@@ -252,7 +213,7 @@ export function formatResolutionRows(measurements: readonly CellIndexMeasurement
|
|
|
252
213
|
(measurement) =>
|
|
253
214
|
`| ${measurement.resolution} | ${measurement.features.toLocaleString()} | ` +
|
|
254
215
|
`${
|
|
255
|
-
measurement.polyfillZeroCellFeatures ===
|
|
216
|
+
measurement.polyfillZeroCellFeatures === null
|
|
256
217
|
? "not measured"
|
|
257
218
|
: `${measurement.polyfillZeroCellFeatures.toLocaleString()} (${(
|
|
258
219
|
(measurement.polyfillZeroCellFeatures / Math.max(1, measurement.features)) *
|
|
@@ -3,83 +3,52 @@
|
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
* {@linkcode APIClient}.
|
|
8
|
-
*
|
|
9
|
-
* THESE ARE API REQUESTS AND THEY GO THROUGH `APIClient`. Small bodies, repeated calls, a third-party
|
|
10
|
-
* host — the pacing, bounded retry, response caching and `ResourceError` mapping are exactly what they
|
|
11
|
-
* need. The 247 MB bulk export is NOT one of them: it is a file transfer, it streams to disk on raw
|
|
12
|
-
* `fetch`, and `download.ts` says so in place.
|
|
13
|
-
*
|
|
14
|
-
* FOUR MEASURED CLIENT BEHAVIORS ARE ENCODED HERE RATHER THAN WRITTEN DOWN SOMEWHERE ELSE.
|
|
15
|
-
*
|
|
16
|
-
* 1. THE HUB DOWNLOAD JOB ANSWERS WITH A `resultUrl` THAT 302s. `…/api/download/v1/items/<id>/geojson?
|
|
17
|
-
* redirect=false&layers=0` returns `{"status":"Completed","resultUrl":…}` in 249 bytes; the result URL
|
|
18
|
-
* itself redirects, so the transfer needs `redirect: "follow"`. A client that took the first response as
|
|
19
|
-
* the file writes a redirect page to disk and reports a successful download.
|
|
20
|
-
* 2. THE BULK EXPORT IS EPSG:2157 UNDER A `crs` MEMBER RFC 7946 REMOVED. The file's own header carries
|
|
21
|
-
* `"crs":{"type":"name","properties":{"name":"EPSG:2157"}}` and its coordinates are Irish Transverse
|
|
22
|
-
* Mercator metres. A strict RFC 7946 reader ignores the member and places Ireland at latitude 735,435;
|
|
23
|
-
* GDAL honours it, which is why `sdk/ingest.ts` reads the archive through ogr2ogr and asserts the
|
|
24
|
-
* reprojected result lands inside the Department's own declared extent.
|
|
25
|
-
* 3. THE PUBLISHER'S OWN AREA STATISTIC IS NOT IN THE ARCHIVE. `Shape__Area` is a service field and the
|
|
26
|
-
* GeoJSON export drops it, so the area cross-check has to come from {@linkcode readShapeAreaSum} — which
|
|
27
|
-
* makes it a genuine two-path check rather than the archive agreeing with itself. Measured:
|
|
28
|
-
* 5,444,492,956.40 m² over 85,330 features.
|
|
29
|
-
* 4. `GZT_LINK` POINTS AT A HOST WITH NO DNS RECORD. All 85,330 rows link their generic type's definition to
|
|
30
|
-
* `viewer.myplan.ie`, which has no A or AAAA record, and three candidate replacements on the live host
|
|
31
|
-
* answer HTTP 404. So `zoning_vocabulary.definition_url` cannot be populated from it and is left NULL
|
|
32
|
-
* rather than filled with a plausible one.
|
|
6
|
+
* The Department's ArcGIS item, its feature service and the Hub download job, read through {@linkcode APIClient}; the bulk export streams to disk on raw `fetch` instead.
|
|
33
7
|
*/
|
|
34
8
|
|
|
35
9
|
import { APIClient, type APIClientConfig, assertNoArcGISError } from "@mailwoman/core/api"
|
|
36
10
|
import { createPacedCachedClient, type CreatePacedCachedClientOptions } from "@mailwoman/core/api/paced-client"
|
|
37
11
|
import { htmlToText } from "@mailwoman/core/html/text"
|
|
12
|
+
import { stringifyJSON } from "@mailwoman/core/json"
|
|
38
13
|
import { isoDate } from "@mailwoman/core/utils"
|
|
39
14
|
|
|
40
15
|
import { GZT_ATTRIBUTION, GZT_ITEM_ID, GZT_SERVICE_URL, GZT_SOURCE_EPSG } from "#vocabulary"
|
|
41
16
|
|
|
42
|
-
// Re-exported so a caller branching on this client's failures needs exactly one import.
|
|
43
|
-
|
|
44
17
|
/**
|
|
45
|
-
* The ArcGIS Online sharing API
|
|
18
|
+
* The ArcGIS Online sharing API.
|
|
19
|
+
*
|
|
20
|
+
* The item's license and attribution fields are available there.
|
|
46
21
|
*/
|
|
47
22
|
export const ARCGIS_ITEM_API_BASE_URL = "https://www.arcgis.com/sharing/rest/content/items"
|
|
48
23
|
|
|
49
24
|
/**
|
|
50
|
-
* The Hub download API
|
|
25
|
+
* The Hub download API exports the whole layer as one file.
|
|
51
26
|
*/
|
|
52
27
|
export const HUB_DOWNLOAD_API_BASE_URL = "https://hub.arcgis.com/api/download/v1/items"
|
|
53
28
|
|
|
54
29
|
/**
|
|
55
|
-
* Minimum spacing between requests to the Department's hosts,
|
|
56
|
-
*
|
|
57
|
-
* The Department publishes no rate limit for this service, so this is courtesy pacing rather than a published ceiling —
|
|
58
|
-
* stated as such rather than dressed up as a measured limit. Two requests a second is far below anything a hosted
|
|
59
|
-
* ArcGIS feature service is provisioned for and costs a build nothing: the acquisition path makes single-digit numbers
|
|
60
|
-
* of calls and the verification a few dozen.
|
|
30
|
+
* Minimum spacing between requests to the Department's hosts, courtesy pacing
|
|
31
|
+
* because the Department publishes no rate limit for this service.
|
|
61
32
|
*/
|
|
62
33
|
export const GZT_MIN_REQUEST_INTERVAL_MS = 500
|
|
63
34
|
|
|
64
35
|
/**
|
|
65
|
-
* How long a cached metadata response stays fresh
|
|
66
|
-
*
|
|
67
|
-
* Six hours, chosen against the product's own cadence rather than a wall-clock intuition. The Department publishes no
|
|
68
|
-
* maintenance-frequency statement at all; what is observable is that the item's `modified` date and the data's latest
|
|
69
|
-
* `UPLOAD_DATE` move a handful of times a year, so a shorter TTL buys nothing.
|
|
36
|
+
* How long a cached metadata response stays fresh, six hours because the item's `modified` date
|
|
37
|
+
* and the data's latest `UPLOAD_DATE` move only a handful of times a year.
|
|
70
38
|
*/
|
|
71
39
|
const GZT_CACHE_TTL_MS = 6 * 60 * 60 * 1000
|
|
72
40
|
|
|
73
41
|
export type CreateZoningClientOptions = CreatePacedCachedClientOptions
|
|
74
42
|
|
|
75
43
|
/**
|
|
76
|
-
* What the item
|
|
44
|
+
* What the item reports about the product.
|
|
77
45
|
*/
|
|
78
46
|
export interface ZoningItemRecord {
|
|
79
47
|
itemID: string
|
|
80
48
|
title: string
|
|
81
49
|
/**
|
|
82
|
-
* The item's `modified` timestamp as an ISO date
|
|
50
|
+
* The item's `modified` timestamp as an ISO date.
|
|
51
|
+
* It records product vintage and signals freshness.
|
|
83
52
|
*/
|
|
84
53
|
modifiedDate: string
|
|
85
54
|
/**
|
|
@@ -87,8 +56,8 @@ export interface ZoningItemRecord {
|
|
|
87
56
|
*/
|
|
88
57
|
accessInformation: string
|
|
89
58
|
/**
|
|
90
|
-
* `licenseInfo`, verbatim
|
|
91
|
-
* terms is visible at build time.
|
|
59
|
+
* `licenseInfo`, verbatim with its markup stripped, read rather than trusted from
|
|
60
|
+
* the constant so a change in the terms is visible at build time.
|
|
92
61
|
*/
|
|
93
62
|
licenseInfo: string
|
|
94
63
|
/**
|
|
@@ -107,7 +76,7 @@ const BBOX_ORDINATES = 4
|
|
|
107
76
|
*/
|
|
108
77
|
export class GZTClient extends APIClient<APIClientConfig> {
|
|
109
78
|
/**
|
|
110
|
-
* The item record: its vintage, its credit line, its
|
|
79
|
+
* The item record: its vintage, its credit line, its license text and its declared extent.
|
|
111
80
|
*
|
|
112
81
|
* @throws {Error} When the item is missing, or declares no extent.
|
|
113
82
|
*/
|
|
@@ -129,7 +98,7 @@ export class GZTClient extends APIClient<APIClientConfig> {
|
|
|
129
98
|
|
|
130
99
|
if (data.id !== GZT_ITEM_ID) {
|
|
131
100
|
throw new Error(
|
|
132
|
-
`zoning client: the item endpoint answered for ${
|
|
101
|
+
`zoning client: the item endpoint answered for ${stringifyJSON(data.id)}, expected ${GZT_ITEM_ID}`
|
|
133
102
|
)
|
|
134
103
|
}
|
|
135
104
|
|
|
@@ -148,7 +117,7 @@ export class GZTClient extends APIClient<APIClientConfig> {
|
|
|
148
117
|
const bbox: [number, number, number, number] = [extent[0][0]!, extent[0][1]!, extent[1][0]!, extent[1][1]!]
|
|
149
118
|
|
|
150
119
|
if (bbox.some((ordinate) => !Number.isFinite(ordinate)) || bbox.length !== BBOX_ORDINATES) {
|
|
151
|
-
throw new TypeError(`zoning client: the item's extent is not a 2D bounding box (${
|
|
120
|
+
throw new TypeError(`zoning client: the item's extent is not a 2D bounding box (${stringifyJSON(extent)})`)
|
|
152
121
|
}
|
|
153
122
|
|
|
154
123
|
return {
|
|
@@ -162,11 +131,7 @@ export class GZTClient extends APIClient<APIClientConfig> {
|
|
|
162
131
|
}
|
|
163
132
|
|
|
164
133
|
/**
|
|
165
|
-
* The feature count the service reports,
|
|
166
|
-
*
|
|
167
|
-
* The SECOND path in the build's agreement check: the same authority, a different distribution channel. An archive
|
|
168
|
-
* whose feature count disagrees with the live service is not a file this build should be writing into a sealed
|
|
169
|
-
* artifact.
|
|
134
|
+
* The feature count and EPSG code the service reports, the second path in the build's agreement check.
|
|
170
135
|
*/
|
|
171
136
|
public async readServiceIdentity(): Promise<{ featureCount: number; epsg: number; maxRecordCount: number }> {
|
|
172
137
|
const { data } = await this.fetch<{
|
|
@@ -200,11 +165,9 @@ export class GZTClient extends APIClient<APIClientConfig> {
|
|
|
200
165
|
}
|
|
201
166
|
|
|
202
167
|
/**
|
|
203
|
-
* The sum of the Department's
|
|
168
|
+
* The sum of the Department's `Shape__Area` column in square meters.
|
|
204
169
|
*
|
|
205
|
-
*
|
|
206
|
-
* the column. Read with the holes the rings total 5,444.5 km²; read without them, 5,666.6 km². The difference is 4.1%
|
|
207
|
-
* of area and, far more importantly, a ray cast that answers "inside" for every location a plan carved out.
|
|
170
|
+
* The service must provide this value because the bulk export omits the column.
|
|
208
171
|
*/
|
|
209
172
|
public async readShapeAreaSum(): Promise<number> {
|
|
210
173
|
const { data } = await this.fetch<{ features?: Array<{ attributes?: Record<string, number> }> }>({
|
|
@@ -212,7 +175,7 @@ export class GZTClient extends APIClient<APIClientConfig> {
|
|
|
212
175
|
url: `${GZT_SERVICE_URL}/query`,
|
|
213
176
|
params: {
|
|
214
177
|
where: "1=1",
|
|
215
|
-
outStatistics:
|
|
178
|
+
outStatistics: stringifyJSON([
|
|
216
179
|
{ statisticType: "sum", onStatisticField: "Shape__Area", outStatisticFieldName: "area_sum" },
|
|
217
180
|
]),
|
|
218
181
|
f: "json",
|
|
@@ -233,13 +196,10 @@ export class GZTClient extends APIClient<APIClientConfig> {
|
|
|
233
196
|
}
|
|
234
197
|
|
|
235
198
|
/**
|
|
236
|
-
* Ask the Hub for a bulk GeoJSON export and return the URL
|
|
237
|
-
*
|
|
238
|
-
* `redirect=false` asks for the job record rather than a redirect, so this call reads a small JSON body. The URL it
|
|
239
|
-
* returns is the one that 302s — see {@link downloadZoningExport}.
|
|
199
|
+
* Ask the Hub for a bulk GeoJSON export and return the result URL, a 302 that the caller has to follow.
|
|
240
200
|
*
|
|
241
|
-
* @throws {Error} When the job is not `Completed`, or names no result URL.
|
|
242
|
-
*
|
|
201
|
+
* @throws {Error} When the job is not `Completed`, or names no result URL.
|
|
202
|
+
* A partial job that answered with a status and no URL would otherwise present as an empty download.
|
|
243
203
|
*/
|
|
244
204
|
public async readExportURL(): Promise<string> {
|
|
245
205
|
const { data } = await this.fetch<{ status?: string; resultUrl?: string; message?: string }>({
|
|
@@ -252,7 +212,7 @@ export class GZTClient extends APIClient<APIClientConfig> {
|
|
|
252
212
|
|
|
253
213
|
if (data.status !== "Completed" || !data.resultUrl) {
|
|
254
214
|
throw new Error(
|
|
255
|
-
`zoning client: the Hub download job answered status ${
|
|
215
|
+
`zoning client: the Hub download job answered status ${stringifyJSON(data.status)} with ${
|
|
256
216
|
data.resultUrl ? "a" : "no"
|
|
257
217
|
} result URL${data.message ? ` (${data.message})` : ""}`
|
|
258
218
|
)
|
|
@@ -262,11 +222,8 @@ export class GZTClient extends APIClient<APIClientConfig> {
|
|
|
262
222
|
}
|
|
263
223
|
|
|
264
224
|
/**
|
|
265
|
-
* The features the service publishes near a point
|
|
266
|
-
*
|
|
267
|
-
* `outSR=4326` on the query path, because the service answers in Irish Transverse Mercator otherwise and the
|
|
268
|
-
* comparison is against coordinates this package reprojected itself. The service answers a bounding box rather than a
|
|
269
|
-
* point, so the containment decision is made against the returned rings by the caller.
|
|
225
|
+
* The features the service publishes near a point, queried with `outSR=4326`
|
|
226
|
+
* because it answers in Irish Transverse Mercator otherwise.
|
|
270
227
|
*/
|
|
271
228
|
public async readFeaturesNear(
|
|
272
229
|
latitude: number,
|
|
@@ -279,7 +236,7 @@ export class GZTClient extends APIClient<APIClientConfig> {
|
|
|
279
236
|
method: "GET",
|
|
280
237
|
url: `${GZT_SERVICE_URL}/query`,
|
|
281
238
|
params: {
|
|
282
|
-
geometry:
|
|
239
|
+
geometry: stringifyJSON({
|
|
283
240
|
xmin: longitude - halfWidthDegrees,
|
|
284
241
|
ymin: latitude - halfWidthDegrees,
|
|
285
242
|
xmax: longitude + halfWidthDegrees,
|
|
@@ -303,28 +260,23 @@ export class GZTClient extends APIClient<APIClientConfig> {
|
|
|
303
260
|
}
|
|
304
261
|
|
|
305
262
|
/**
|
|
306
|
-
* Refuse an attribution the published item no longer matches
|
|
307
|
-
*
|
|
308
|
-
* READ AT BUILD TIME RATHER THAN TRUSTED FROM THE CONSTANT. The constant is what the artifact is stamped with offline;
|
|
309
|
-
* this is the live value it is reconciled with when the network is available. The check is on the DEPARTMENT'S CREDIT
|
|
310
|
-
* LINE and on the Tailte Éireann clause separately, because they are two different statements and the second is the one
|
|
311
|
-
* that holds this layer at `build-local`: an item that dropped it would be a licence change worth hearing about, and an
|
|
312
|
-
* item that dropped only the credit line would be a different one.
|
|
263
|
+
* Refuse an attribution the published item no longer matches, checking the Department's
|
|
264
|
+
* credit line and the Tailte Éireann clause separately.
|
|
313
265
|
*
|
|
314
266
|
* @throws {Error} When either half of {@link GZT_ATTRIBUTION} is no longer in the item's own fields.
|
|
315
267
|
*/
|
|
316
268
|
export function assertAttributionUnchanged(record: Pick<ZoningItemRecord, "accessInformation" | "licenseInfo">): void {
|
|
317
269
|
if (!GZT_ATTRIBUTION.includes(record.accessInformation.trim()) || !record.accessInformation.trim()) {
|
|
318
270
|
throw new Error(
|
|
319
|
-
`zoning client: the item's accessInformation reads ${
|
|
320
|
-
`${
|
|
271
|
+
`zoning client: the item's accessInformation reads ${stringifyJSON(record.accessInformation)}, and this build ships ` +
|
|
272
|
+
`${stringifyJSON(GZT_ATTRIBUTION)} — the credit line is what a re-user has to publish, so a change in it is a change in the terms`
|
|
321
273
|
)
|
|
322
274
|
}
|
|
323
275
|
|
|
324
276
|
if (!record.licenseInfo.includes("Tailte Éireann")) {
|
|
325
277
|
throw new Error(
|
|
326
278
|
"zoning client: the item's licenseInfo no longer names Tailte Éireann as a licensor. That clause is the reason " +
|
|
327
|
-
"this layer is built locally rather than shipped, so its disappearance is a
|
|
279
|
+
"this layer is built locally rather than shipped, so its disappearance is a license change to read rather than absorb"
|
|
328
280
|
)
|
|
329
281
|
}
|
|
330
282
|
}
|
package/sdk/download.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Acquire the Department's bulk GeoJSON export with raw `fetch` rather than `APIClient`, following the result URL's redirect and keying the cache on the item's own modified date.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { tryStat } from "@mailwoman/core/fs/readers/stat"
|
|
10
|
+
import { makeDirectories } from "@mailwoman/core/fs/writers"
|
|
11
|
+
import { streamToDisk } from "@mailwoman/core/utils"
|
|
12
|
+
import { PathBuilder, type PathBuilderLike } from "path-ts"
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The file name one vintage's export is kept under.
|
|
16
|
+
*/
|
|
17
|
+
export const GZT_EXPORT_FILE = "gzt-current-plan.geojson"
|
|
18
|
+
|
|
19
|
+
export interface DownloadZoningExportOptions {
|
|
20
|
+
/**
|
|
21
|
+
* The Hub job's `resultUrl`, read rather than assembled because it includes a
|
|
22
|
+
* generated file id that a hard-coded URL would outlive.
|
|
23
|
+
*/
|
|
24
|
+
url: string
|
|
25
|
+
/**
|
|
26
|
+
* The product vintage the cache is keyed on.
|
|
27
|
+
*/
|
|
28
|
+
vintage: string
|
|
29
|
+
cacheRoot: PathBuilderLike
|
|
30
|
+
onProgress?: (message: string) => void
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Download the bulk export for one product vintage and return the path of the GeoJSON file, renaming a
|
|
35
|
+
* `.part` file only on a clean finish so an interrupted transfer never presents as a complete export.
|
|
36
|
+
*/
|
|
37
|
+
export async function downloadZoningExport(options: DownloadZoningExportOptions): Promise<string> {
|
|
38
|
+
const vintageDir = PathBuilder.from(options.cacheRoot)(options.vintage)
|
|
39
|
+
// A string, because the build records the export path it read.
|
|
40
|
+
const exportPath = vintageDir(GZT_EXPORT_FILE).toString()
|
|
41
|
+
|
|
42
|
+
if (await tryStat(exportPath)) {
|
|
43
|
+
options.onProgress?.(`export for ${options.vintage} already downloaded`)
|
|
44
|
+
|
|
45
|
+
return exportPath
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
await makeDirectories(vintageDir)
|
|
49
|
+
|
|
50
|
+
await streamToDisk({
|
|
51
|
+
url: options.url,
|
|
52
|
+
destination: exportPath,
|
|
53
|
+
context: "zoning download",
|
|
54
|
+
...(options.onProgress ? { onProgress: options.onProgress } : {}),
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
return exportPath
|
|
58
|
+
}
|