@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 → sdk}/test-kit.ts
RENAMED
|
@@ -3,27 +3,11 @@
|
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
|
-
* `@mailwoman/zoning/test-kit`
|
|
7
|
-
*
|
|
8
|
-
* authority states as
|
|
6
|
+
* `@mailwoman/zoning/test-kit` provides hand-built geometry for fixture tests.
|
|
7
|
+
* It includes zones in two plans over the same ground. It includes a zone with a service-encoded hole.
|
|
8
|
+
* It includes a zone smaller than a cell and a zone the authority states as unzoned.
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
* the observation route's suite lives in another workspace, and a relative import across two TypeScript
|
|
12
|
-
* projects is refused outright (`TS2878`) because the compiled layout would not match the source layout.
|
|
13
|
-
*
|
|
14
|
-
* NO NETWORK AND NO GDAL. The builder takes a {@linkcode ZoningFeatureSource}, so a fixture is a list of
|
|
15
|
-
* features — which is what lets this rung exercise the ring-role resolution, the vocabulary census, the cell
|
|
16
|
-
* classification, the coverage rows, the manifest and the seal on every machine rather than only the ones
|
|
17
|
-
* with ogr2ogr.
|
|
18
|
-
*
|
|
19
|
-
* THE EXTERIOR RING IS THE CLOCKWISE ONE, WHICH IS THE INVERSE OF THE GEOJSON CONVENTION AND OF EVERY
|
|
20
|
-
* SIBLING FIXTURE. `@mailwoman/spatial`'s `rectangleRing` winds counter-clockwise and its `reversedRing`
|
|
21
|
-
* clockwise, so this file aliases them the other way round from the flood and coastal test kits: under this
|
|
22
|
-
* service a clockwise ring is the EXTERIOR and a counter-clockwise one is a HOLE. A fixture that used the
|
|
23
|
-
* sibling naming would build geometry the ingest reads inside-out, and every assertion on it would pass.
|
|
24
|
-
*
|
|
25
|
-
* THE COORDINATES ARE IN THE IRISH SEA east of Dublin — inside the Department's declared extent, so a
|
|
26
|
-
* fixture stays in the coordinate space the product occupies, and clear of every real zoning polygon.
|
|
10
|
+
* Under this service a clockwise ring is the exterior and a counter-clockwise one is a hole, the inverse of the GeoJSON convention and of every sibling fixture.
|
|
27
11
|
*/
|
|
28
12
|
|
|
29
13
|
import {
|
|
@@ -37,12 +21,12 @@ import type { ZoningFeatureSource, ZoningSourceFeature } from "#sdk/ingest"
|
|
|
37
21
|
import { GZT_SOURCE_EPSG, GZT_UNZONED_LOCAL_CODE } from "#vocabulary"
|
|
38
22
|
|
|
39
23
|
/**
|
|
40
|
-
* The exterior ring builder
|
|
24
|
+
* The exterior ring builder under this service's convention.
|
|
41
25
|
*/
|
|
42
26
|
export const exteriorRing = clockwiseRing
|
|
43
27
|
|
|
44
28
|
/**
|
|
45
|
-
* The hole ring builder
|
|
29
|
+
* The hole ring builder under this service's convention.
|
|
46
30
|
*/
|
|
47
31
|
export const holeRing = counterClockwiseRing
|
|
48
32
|
|
|
@@ -52,22 +36,18 @@ export const holeRing = counterClockwiseRing
|
|
|
52
36
|
export const FIXTURE_ORIGIN = { lon: -5.99, lat: 53.3 } as const
|
|
53
37
|
|
|
54
38
|
/**
|
|
55
|
-
* Side of a fixture zone
|
|
56
|
-
* interior AND a real fringe.
|
|
39
|
+
* Side of a fixture zone in degrees.
|
|
57
40
|
*/
|
|
58
41
|
export const FIXTURE_SIDE = 0.01
|
|
59
42
|
|
|
60
43
|
/**
|
|
61
|
-
* The fixture authority and
|
|
44
|
+
* The fixture authority's code and name.
|
|
62
45
|
*/
|
|
63
46
|
export const FIXTURE_AUTHORITY = { code: "Fx", name: "Fixture County Council" } as const
|
|
64
47
|
|
|
65
48
|
/**
|
|
66
|
-
* The two plans the fixture set uses, shaped like the real product's
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
* The dates are in the source's own RFC 1123 form, because that is what the export publishes and this layer carries
|
|
70
|
-
* them as published rather than re-formatting them.
|
|
49
|
+
* The two plans the fixture set uses, shaped like the real product's, with dates
|
|
50
|
+
* preserved as published in the source's own RFC 1123 form.
|
|
71
51
|
*/
|
|
72
52
|
export const FIXTURE_PLANS = {
|
|
73
53
|
development: {
|
|
@@ -113,18 +93,16 @@ export function fixtureFeature(
|
|
|
113
93
|
crosswalkDescription: "Existing residential",
|
|
114
94
|
crosswalkRollup: "RE",
|
|
115
95
|
...overrides,
|
|
116
|
-
//
|
|
117
|
-
// assertion rather than the resolution, and the resolution is the part of this layer no sibling already has.
|
|
96
|
+
// Resolved through the real resolver rather than hand-assembled.
|
|
118
97
|
rings: resolveRingRoles(polygons, String(objectID)),
|
|
119
98
|
}
|
|
120
99
|
}
|
|
121
100
|
|
|
122
101
|
/**
|
|
123
|
-
* The fixture set
|
|
124
|
-
* SAME ground as the first; a zone smaller than a cell; and a zone the authority states as unzoned.
|
|
102
|
+
* The fixture set has two adjacent zones and one with a service-encoded hole.
|
|
125
103
|
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
104
|
+
* It has a second plan over the same ground.
|
|
105
|
+
* It has a zone smaller than a cell and a zone the authority states as unzoned.
|
|
128
106
|
*/
|
|
129
107
|
export function fixtureFeatures(): ZoningSourceFeature[] {
|
|
130
108
|
const { lon, lat } = FIXTURE_ORIGIN
|
|
@@ -132,8 +110,8 @@ export function fixtureFeatures(): ZoningSourceFeature[] {
|
|
|
132
110
|
const zoneA = exteriorRing(lon, lat, lon + FIXTURE_SIDE, lat + FIXTURE_SIDE)
|
|
133
111
|
const zoneB = exteriorRing(lon + FIXTURE_SIDE, lat, lon + 2 * FIXTURE_SIDE, lat + FIXTURE_SIDE)
|
|
134
112
|
|
|
135
|
-
//
|
|
136
|
-
//
|
|
113
|
+
// The real service encodes the hole as a separate part.
|
|
114
|
+
// It does not nest the hole ring.
|
|
137
115
|
const holed: MultiPolygonRings = [
|
|
138
116
|
[exteriorRing(lon, lat + 2 * FIXTURE_SIDE, lon + FIXTURE_SIDE, lat + 3 * FIXTURE_SIDE)],
|
|
139
117
|
[
|
|
@@ -146,8 +124,8 @@ export function fixtureFeatures(): ZoningSourceFeature[] {
|
|
|
146
124
|
],
|
|
147
125
|
]
|
|
148
126
|
|
|
149
|
-
//
|
|
150
|
-
//
|
|
127
|
+
// Smaller than a res-11 cell, so `polygonToCells` returns no cell and the index must
|
|
128
|
+
// cover it by cell-touches-polygon rather than center-in-polygon.
|
|
151
129
|
const sliver = exteriorRing(lon + 3 * FIXTURE_SIDE, lat, lon + 3 * FIXTURE_SIDE + 0.00005, lat + 0.00005)
|
|
152
130
|
|
|
153
131
|
const unzoned = exteriorRing(lon + 4 * FIXTURE_SIDE, lat, lon + 5 * FIXTURE_SIDE, lat + FIXTURE_SIDE)
|
|
@@ -174,7 +152,7 @@ export function fixtureFeatures(): ZoningSourceFeature[] {
|
|
|
174
152
|
crosswalkCode: "N1.1",
|
|
175
153
|
crosswalkDescription: "Road",
|
|
176
154
|
}),
|
|
177
|
-
// The authority
|
|
155
|
+
// The authority marks land as unzoned with a code its own domain does not declare.
|
|
178
156
|
fixtureFeature(5, [[unzoned]], {
|
|
179
157
|
localCode: GZT_UNZONED_LOCAL_CODE,
|
|
180
158
|
localDescription: "Unzoned",
|
|
@@ -182,8 +160,7 @@ export function fixtureFeatures(): ZoningSourceFeature[] {
|
|
|
182
160
|
crosswalkDescription: null,
|
|
183
161
|
crosswalkRollup: "N/A",
|
|
184
162
|
}),
|
|
185
|
-
// The
|
|
186
|
-
// is the shape that makes the crosswalk non-functional over an (authority, code) pair.
|
|
163
|
+
// The same ground as zone A under a second plan, with the same local code mapped to a different generic type.
|
|
187
164
|
fixtureFeature(6, [[zoneA]], {
|
|
188
165
|
planID: localAreaPlan.id,
|
|
189
166
|
planName: localAreaPlan.name,
|
|
@@ -3,37 +3,34 @@
|
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
|
-
* The
|
|
6
|
+
* The check compares the artifact with a second path. A separate half tests locations outside its coverage.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* on OUR CONVERSION rather than on the authority.
|
|
8
|
+
* The positive half samples points from the sealed artifact and asks the Department's feature service about them.
|
|
9
|
+
* The service supplies geometry through a separate distribution channel. This package has not touched that geometry.
|
|
10
|
+
* The check runs the point test on the service's rings. It compares two verdicts from the same authority.
|
|
11
|
+
* This measures our conversion against the authority's published geometry.
|
|
13
12
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* comes back OUTSIDE on both paths or on neither.
|
|
13
|
+
* The service returns geometry in the publisher's ring convention. `outSR=4326` returns the same clockwise-exterior
|
|
14
|
+
* rings as the bulk export. This path re-derives ring roles as ingest does. A point inside a hole then falls outside
|
|
15
|
+
* on both paths or inside on both paths.
|
|
18
16
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* polygon is not a statement.
|
|
17
|
+
* The negative half checks locations outside the publication area. The Department omits Donegal, one of 31 local
|
|
18
|
+
* authorities. The product also excludes Northern Ireland. Points in both areas must return `unknown` with no
|
|
19
|
+
* designation. A positive-only check could pass an artifact that reports the whole island as zoned. The layer treats
|
|
20
|
+
* a missing polygon as no zoning statement.
|
|
24
21
|
*
|
|
25
|
-
*
|
|
26
|
-
* archive publishes nine decimals through this package's ingest
|
|
27
|
-
* within roughly a
|
|
28
|
-
*
|
|
29
|
-
* of the receipt.
|
|
22
|
+
* The channels use different coordinate precision. A boundary-point disagreement therefore does not establish a
|
|
23
|
+
* conversion defect. The archive publishes nine decimals through this package's ingest. The service rounds its JSON.
|
|
24
|
+
* A point within roughly a meter of a zone boundary can fall on opposite sides of the two rendered edges. The check
|
|
25
|
+
* reports these cases as `boundary_tolerance` with the distance to the nearest edge. The receipt includes their count.
|
|
30
26
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
27
|
+
* The distance measures to the edge rather than to the nearest vertex. A point a centimeter from a long edge can be
|
|
28
|
+
* meters from every vertex. In one sibling-layer near-miss, vertex distance measured 1.58 m and edge distance
|
|
29
|
+
* measured 0.009 m. The vertex measurement overstated distance by 175 times. It would make the stated boundary
|
|
30
|
+
* tolerance stricter and report a rendering difference as a conversion defect.
|
|
35
31
|
*/
|
|
36
32
|
|
|
33
|
+
import { stringifyJSON } from "@mailwoman/core/json"
|
|
37
34
|
import {
|
|
38
35
|
nearestRingEdgeMetres,
|
|
39
36
|
pointInEncodedRings,
|
|
@@ -43,6 +40,7 @@ import {
|
|
|
43
40
|
type PolygonRings,
|
|
44
41
|
} from "@mailwoman/spatial"
|
|
45
42
|
import { DatabaseClient } from "@mailwoman/sqlite/client"
|
|
43
|
+
import type { PathBuilderLike } from "path-ts"
|
|
46
44
|
|
|
47
45
|
import { ZoningLookup, ZoningReadingKind, type ZoningReading } from "#index"
|
|
48
46
|
import { resolveRingRoles } from "#rings"
|
|
@@ -50,7 +48,8 @@ import type { ZoningDatabase } from "#schema"
|
|
|
50
48
|
import type { GZTClient } from "#sdk/client"
|
|
51
49
|
|
|
52
50
|
/**
|
|
53
|
-
*
|
|
51
|
+
* Records one point and both verdicts.
|
|
52
|
+
* It also records whether they agree.
|
|
54
53
|
*/
|
|
55
54
|
export interface AgreementRow {
|
|
56
55
|
label: string
|
|
@@ -65,18 +64,23 @@ export interface AgreementRow {
|
|
|
65
64
|
*/
|
|
66
65
|
serviceInside: boolean
|
|
67
66
|
/**
|
|
68
|
-
* The local code the
|
|
69
|
-
*
|
|
70
|
-
* the
|
|
67
|
+
* The local code the service reports at the point, where it reports one.
|
|
68
|
+
*
|
|
69
|
+
* Compared verbatim against the artifact's, because carrying the code verbatim
|
|
70
|
+
* is what this layer is for: two paths that agree on containment and disagree
|
|
71
|
+
* on the code would be a silent vocabulary defect.
|
|
71
72
|
*/
|
|
72
73
|
serviceLocalCode?: string
|
|
73
74
|
outcome: "agree" | "disagree" | "boundary_tolerance"
|
|
74
75
|
/**
|
|
75
|
-
*
|
|
76
|
+
* Meters from the point to the nearest edge of any polygon the service returned nearby.
|
|
77
|
+
*
|
|
78
|
+
* Every row includes this distance.
|
|
79
|
+
* It separates a real defect from a difference caused by the two channels
|
|
80
|
+
* rendering the same edge differently.
|
|
76
81
|
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
* service returned no polygon at all near the point.
|
|
82
|
+
* A receipt without it forces a re-run.
|
|
83
|
+
* `undefined` means the service returned no polygon at all near the point.
|
|
80
84
|
*/
|
|
81
85
|
nearestEdgeMetres?: number
|
|
82
86
|
}
|
|
@@ -91,7 +95,8 @@ export interface OutsideRow {
|
|
|
91
95
|
kind: string
|
|
92
96
|
designations: number
|
|
93
97
|
/**
|
|
94
|
-
* True when the artifact answered `unknown` with no designation
|
|
98
|
+
* True when the artifact answered `unknown` with no designation.
|
|
99
|
+
* The only acceptable reading here.
|
|
95
100
|
*/
|
|
96
101
|
passed: boolean
|
|
97
102
|
}
|
|
@@ -110,12 +115,18 @@ export interface VerifyZoningResult {
|
|
|
110
115
|
}
|
|
111
116
|
|
|
112
117
|
/**
|
|
113
|
-
*
|
|
114
|
-
*
|
|
118
|
+
* Point identifiers for locations outside this product's publication area.
|
|
119
|
+
*
|
|
120
|
+
* Each is a place rather than a bare pair of numbers: a coordinate a reader a
|
|
121
|
+
* coordinate without a reference source cannot be checked.
|
|
122
|
+
*
|
|
123
|
+
* The check requires points from two populations.
|
|
124
|
+
* The Donegal points are the case this layer's coverage posture exists for.
|
|
125
|
+
*
|
|
126
|
+
* The Department has not published that authority's zoning.
|
|
127
|
+
* A builder that reads the absence as "unrestricted" would answer these points confidently.
|
|
115
128
|
*
|
|
116
|
-
*
|
|
117
|
-
* — the Department has not published that authority's zoning, and a builder that read absence as "unrestricted" would
|
|
118
|
-
* answer them confidently. The Northern Irish points confirm the artifact is clipped to the Republic rather than to the
|
|
129
|
+
* The Northern Irish points confirm the artifact is clipped to the Republic rather than to the
|
|
119
130
|
* island: zoning there is a different jurisdiction's instrument under a different planning act.
|
|
120
131
|
*/
|
|
121
132
|
export const OUTSIDE_PUBLICATION_POINTS: ReadonlyArray<{ label: string; latitude: number; longitude: number }> = [
|
|
@@ -128,23 +139,28 @@ export const OUTSIDE_PUBLICATION_POINTS: ReadonlyArray<{ label: string; latitude
|
|
|
128
139
|
]
|
|
129
140
|
|
|
130
141
|
/**
|
|
131
|
-
* Half-width of the bounding box the service is asked for, in degrees.
|
|
132
|
-
*
|
|
142
|
+
* Half-width of the bounding box the service is asked for, in degrees.
|
|
143
|
+
*
|
|
144
|
+
* About 11 m at this latitude — wide enough that a polygon containing the point is
|
|
145
|
+
* certainly returned, narrow enough that the response stays small.
|
|
133
146
|
*/
|
|
134
147
|
const PROBE_HALF_WIDTH_DEGREES = 0.0001
|
|
135
148
|
|
|
136
149
|
/**
|
|
137
|
-
* How close to a service-polygon edge a disagreement is attributed to the channels'
|
|
138
|
-
* rather than to the conversion.
|
|
150
|
+
* How close to a service-polygon edge a disagreement is attributed to the channels'
|
|
151
|
+
* differing coordinate precision rather than to the conversion.
|
|
152
|
+
*
|
|
153
|
+
* Half a meter.
|
|
154
|
+
* The two channels render the same edge from the same source coordinates through different
|
|
155
|
+
* rounding, so a point between the two renderings lands on opposite sides.
|
|
139
156
|
*
|
|
140
|
-
* Half a
|
|
141
|
-
* point between the two renderings lands on opposite sides; half a metre is far below any real zoning boundary and far
|
|
142
|
-
* above the rounding difference.
|
|
157
|
+
* Half a meter is far below any real zoning boundary and far above the rounding difference.
|
|
143
158
|
*/
|
|
144
159
|
const BOUNDARY_TOLERANCE_METRES = 0.5
|
|
145
160
|
|
|
146
161
|
/**
|
|
147
|
-
* One feature as the service publishes it
|
|
162
|
+
* One feature as the service publishes it.
|
|
163
|
+
* The only shape the comparison reads.
|
|
148
164
|
*/
|
|
149
165
|
export interface ServiceFeature {
|
|
150
166
|
properties?: Record<string, unknown>
|
|
@@ -152,31 +168,37 @@ export interface ServiceFeature {
|
|
|
152
168
|
}
|
|
153
169
|
|
|
154
170
|
/**
|
|
155
|
-
* The
|
|
171
|
+
* The one call the verification makes against the service: the features it publishes near a point.
|
|
172
|
+
*
|
|
173
|
+
* The function exposes only the service read.
|
|
174
|
+
* This keeps the check's own logic testable.
|
|
156
175
|
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
176
|
+
* The comparison's value is that it decides which of three outcomes a point gets.
|
|
177
|
+
*
|
|
178
|
+
* An HTTP client would let tests observe these decisions only during a live run.
|
|
179
|
+
* A scripted reader pins the decisions. {@link createServiceReader} builds the real reader.
|
|
161
180
|
*/
|
|
162
181
|
export type ServiceFeatureReader = (latitude: number, longitude: number) => Promise<ServiceFeature[]>
|
|
163
182
|
|
|
164
183
|
/**
|
|
165
184
|
* The reader the live check uses: a bounding-box query against the Department's own service.
|
|
166
185
|
*
|
|
167
|
-
* The service answers a BOX
|
|
168
|
-
* in {@link readServiceContainment} against
|
|
169
|
-
*
|
|
186
|
+
* The service answers a BOX rather than a point, so this returns what it published nearby
|
|
187
|
+
* and the containment decision is made in {@link readServiceContainment} against
|
|
188
|
+
* those rings — comparing the artifact's verdict against a bare "the service returned
|
|
189
|
+
* something here" would pass on any polygon within eleven meters.
|
|
170
190
|
*/
|
|
171
191
|
export function createServiceReader(client: Pick<GZTClient, "readFeaturesNear">): ServiceFeatureReader {
|
|
172
192
|
return async (latitude, longitude) => client.readFeaturesNear(latitude, longitude, PROBE_HALF_WIDTH_DEGREES)
|
|
173
193
|
}
|
|
174
194
|
|
|
175
195
|
export interface VerifyZoningOptions {
|
|
176
|
-
databasePath:
|
|
196
|
+
databasePath: PathBuilderLike
|
|
177
197
|
readServiceFeatures: ServiceFeatureReader
|
|
178
198
|
/**
|
|
179
|
-
* Points to re-ask the service about.
|
|
199
|
+
* Points to re-ask the service about.
|
|
200
|
+
*
|
|
201
|
+
* A caller samples them from the artifact — see {@link sampleAgreementPoints}.
|
|
180
202
|
*/
|
|
181
203
|
points: ReadonlyArray<{ label: string; latitude: number; longitude: number; localCode?: string }>
|
|
182
204
|
outsidePoints?: ReadonlyArray<{ label: string; latitude: number; longitude: number }>
|
|
@@ -248,8 +270,9 @@ export async function verifyZoningDatabase(options: VerifyZoningOptions): Promis
|
|
|
248
270
|
}
|
|
249
271
|
|
|
250
272
|
/**
|
|
251
|
-
* Whether the
|
|
252
|
-
* even-odd rule the artifact's reader uses
|
|
273
|
+
* Whether the service's own geometry contains the point, decided here with the same
|
|
274
|
+
* ring-role resolution and the same even-odd rule the artifact's reader uses.
|
|
275
|
+
* So what is compared is a verdict against a verdict.
|
|
253
276
|
*/
|
|
254
277
|
async function readServiceContainment(
|
|
255
278
|
readServiceFeatures: ServiceFeatureReader,
|
|
@@ -278,14 +301,15 @@ async function readServiceContainment(
|
|
|
278
301
|
nearest = distance
|
|
279
302
|
}
|
|
280
303
|
|
|
281
|
-
//
|
|
282
|
-
// both channels, so reading this side as nested
|
|
283
|
-
//
|
|
304
|
+
// the service'S rings GET the same role resolution the ingest gave the archive'S.
|
|
305
|
+
// The publisher uses one convention on both channels, so reading this side as nested
|
|
306
|
+
// GeoJSON would answer "inside" for a point in a hole and report the artifact as
|
|
307
|
+
// wrong at exactly the locations the hole handling exists for.
|
|
284
308
|
const resolved = resolveRingRoles(raw, `service feature near ${latitude},${longitude}`)
|
|
285
309
|
|
|
286
|
-
//
|
|
287
|
-
// `pointInEncodedRings`, and running the service's geometry through a different
|
|
288
|
-
// that were never asked the same question.
|
|
310
|
+
// encoded and RE-read rather than RAY-cast directly, deliberately: the artifact answers
|
|
311
|
+
// through `pointInEncodedRings`, and running the service's geometry through a different
|
|
312
|
+
// predicate would compare two answers that were never asked the same question.
|
|
289
313
|
if (pointInEncodedRings(encodeRings(resolved.polygons), longitude, latitude)) {
|
|
290
314
|
inside = true
|
|
291
315
|
|
|
@@ -305,24 +329,27 @@ async function readServiceContainment(
|
|
|
305
329
|
}
|
|
306
330
|
|
|
307
331
|
/**
|
|
308
|
-
* Draw a reproducible sample of points from the artifact — interior points of
|
|
309
|
-
* authorities.
|
|
332
|
+
* Draw a reproducible sample of points from the artifact — interior points of
|
|
333
|
+
* stored polygons, spread across authorities.
|
|
310
334
|
*
|
|
311
|
-
*
|
|
312
|
-
* between them and a sample from one would verify
|
|
313
|
-
*
|
|
314
|
-
*
|
|
335
|
+
* Spread across authorities rather than drawn from one, because 30 local authorities
|
|
336
|
+
* publish 581 distinct local codes between them and a sample from one would verify
|
|
337
|
+
* one authority's conversion while reporting on all of them.
|
|
338
|
+
* The stride discipline — keys chosen before any geometry is read, deterministic
|
|
339
|
+
* rather than random — is `strideSampleInteriorPoints`'s.
|
|
315
340
|
*/
|
|
316
341
|
export function sampleAgreementPoints(
|
|
317
|
-
databasePath:
|
|
342
|
+
databasePath: PathBuilderLike,
|
|
318
343
|
options: { count?: number } = {}
|
|
319
344
|
): Array<{ label: string; latitude: number; longitude: number; localCode: string }> {
|
|
320
345
|
const count = options.count ?? 48
|
|
321
346
|
using database = new DatabaseClient<ZoningDatabase>(databasePath, { readOnly: true })
|
|
322
347
|
|
|
323
|
-
//
|
|
324
|
-
//
|
|
325
|
-
//
|
|
348
|
+
// Sort by authority so the stride samples across the 30 authorities
|
|
349
|
+
// instead of sampling one authority repeatedly.
|
|
350
|
+
// A stride over `area_id` by itself would follow the publisher's feature numbering.
|
|
351
|
+
// That numbering is grouped by authority, so the stride would select only the
|
|
352
|
+
// authorities that fall on its positions.
|
|
326
353
|
const areaIDs = (
|
|
327
354
|
database.prepare("SELECT area_id FROM zoning_area ORDER BY jurisdiction_id, area_id").all() as Array<{
|
|
328
355
|
area_id: string
|
|
@@ -349,7 +376,7 @@ export function sampleAgreementPoints(
|
|
|
349
376
|
| undefined,
|
|
350
377
|
gridSteps: 17,
|
|
351
378
|
toPoint: (area, interior) => ({
|
|
352
|
-
label: `${area.jurisdiction_id} ${
|
|
379
|
+
label: `${area.jurisdiction_id} ${stringifyJSON(area.local_code)} polygon ${area.area_id}`,
|
|
353
380
|
localCode: area.local_code,
|
|
354
381
|
...interior,
|
|
355
382
|
}),
|
package/lib/sdk/download.ts
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @copyright Sister Software
|
|
3
|
-
* @license AGPL-3.0
|
|
4
|
-
* @author Teffen Ellis, et al.
|
|
5
|
-
*
|
|
6
|
-
* Acquire the Department's bulk GeoJSON export — a 247,452,342-byte file streamed to disk.
|
|
7
|
-
*
|
|
8
|
-
* THIS IS A FILE TRANSFER, NOT AN API REQUEST, AND IT KEEPS RAW `fetch` ON PURPOSE. The repo's rule sends
|
|
9
|
-
* HTTP clients through `@mailwoman/core/api`'s `APIClient`, and the rule draws its line at what that class
|
|
10
|
-
* is for: pacing, bounded retry, response caching and error mapping over small bodies and repeated calls.
|
|
11
|
-
* None of it applies here. Caching a 247 MB body through a JSON-validating disk cache would write a second,
|
|
12
|
-
* unreadable copy of a file already on disk; there is nothing to pace, because this runs once per product
|
|
13
|
-
* vintage; and axios buffers any non-stream response type in memory. `packages/osm/lib/sdk/fetch.ts`,
|
|
14
|
-
* `packages/tiger/lib/sdk/download.ts`, `packages/flood/lib/sdk/download.ts` and `packages/coastal/lib/sdk/download.ts`
|
|
15
|
-
* are the existing transfers that say the same thing in the same place. The JOB that produces this URL, and
|
|
16
|
-
* every other metadata read around it, DO go through `APIClient` — see `client.ts`.
|
|
17
|
-
*
|
|
18
|
-
* THE RESULT URL REDIRECTS AND THE FETCH MUST FOLLOW IT. The Hub download job answers
|
|
19
|
-
* `{"status":"Completed","resultUrl":…}`; the result URL itself 302s to the generated file. Node's `fetch`
|
|
20
|
-
* follows redirects by default, and the option is passed explicitly anyway — a transfer that stopped at the
|
|
21
|
-
* redirect would write a short body to disk and report a successful download.
|
|
22
|
-
*
|
|
23
|
-
* FRESHNESS IS THE ITEM'S OWN MODIFIED DATE, NEVER A LENGTH PROBE. The cache is keyed on the vintage the
|
|
24
|
-
* item declares, so a re-run against the same vintage never re-transfers and a new vintage never overwrites
|
|
25
|
-
* the old one in place.
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
import { tryStat } from "@mailwoman/core/fs/readers"
|
|
29
|
-
import { makeDirectories } from "@mailwoman/core/fs/writers"
|
|
30
|
-
import { streamToDisk } from "@mailwoman/core/utils"
|
|
31
|
-
import { join } from "path-ts"
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* The file name one vintage's export is kept under.
|
|
35
|
-
*/
|
|
36
|
-
export const GZT_EXPORT_FILE = "gzt-current-plan.geojson"
|
|
37
|
-
|
|
38
|
-
export interface DownloadZoningExportOptions {
|
|
39
|
-
/**
|
|
40
|
-
* The Hub job's `resultUrl`, read rather than assembled — it carries a generated file id with no relationship to the
|
|
41
|
-
* item id, so a hard-coded URL survives a republish by pointing at a file that is no longer the product.
|
|
42
|
-
*/
|
|
43
|
-
url: string
|
|
44
|
-
/**
|
|
45
|
-
* The product vintage the cache is keyed on.
|
|
46
|
-
*/
|
|
47
|
-
vintage: string
|
|
48
|
-
cacheRoot: string
|
|
49
|
-
onProgress?: (message: string) => void
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Download the bulk export for one product vintage, returning the path of the GeoJSON file.
|
|
54
|
-
*
|
|
55
|
-
* Downloads to a `.part` file and renames only on a clean finish, so an interrupted transfer never presents as a
|
|
56
|
-
* complete export — the same discipline the database build uses, for the same reason.
|
|
57
|
-
*/
|
|
58
|
-
export async function downloadZoningExport(options: DownloadZoningExportOptions): Promise<string> {
|
|
59
|
-
const vintageDir = join(options.cacheRoot, options.vintage)
|
|
60
|
-
const exportPath = join(vintageDir, GZT_EXPORT_FILE)
|
|
61
|
-
|
|
62
|
-
if (await tryStat(exportPath)) {
|
|
63
|
-
options.onProgress?.(`export for ${options.vintage} already downloaded`)
|
|
64
|
-
|
|
65
|
-
return exportPath
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
await makeDirectories(vintageDir)
|
|
69
|
-
|
|
70
|
-
await streamToDisk({
|
|
71
|
-
url: options.url,
|
|
72
|
-
destination: exportPath,
|
|
73
|
-
context: "zoning download",
|
|
74
|
-
...(options.onProgress ? { onProgress: options.onProgress } : {}),
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
return exportPath
|
|
78
|
-
}
|
package/lib/sdk/index.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @copyright Sister Software
|
|
3
|
-
* @license AGPL-3.0
|
|
4
|
-
* @author Teffen Ellis, et al.
|
|
5
|
-
* @file The acquisition + build surface for the Irish zoning layer. The READER is the package root.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
export * from "#sdk/build-zoning"
|
|
9
|
-
export * from "#sdk/cells"
|
|
10
|
-
export * from "#sdk/client"
|
|
11
|
-
export * from "#sdk/download"
|
|
12
|
-
export * from "#sdk/ingest"
|
|
13
|
-
export * from "#sdk/ingest-chunk"
|
|
14
|
-
export * from "#sdk/measure-resolutions"
|
|
15
|
-
export * from "#sdk/verify"
|