@mailwoman/spatial 10.3.0 → 10.5.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 +3 -3
- package/lib/coordinate/formats.ts +1 -1
- package/lib/distance.ts +32 -2
- package/lib/gb/codepoint.ts +210 -0
- package/lib/gb/os-downloads.ts +46 -0
- package/lib/geometries/point.ts +1 -1
- package/lib/h3/coverage.ts +1 -1
- package/lib/h3/polygon-cells.ts +2 -2
- package/lib/projection/transform.ts +1 -1
- package/out/coordinate/formats.d.ts +1 -1
- package/out/coordinate/formats.js +1 -1
- package/out/distance.d.ts +13 -1
- package/out/distance.d.ts.map +1 -1
- package/out/distance.js +23 -2
- package/out/distance.js.map +1 -1
- package/out/gb/codepoint.d.ts +126 -0
- package/out/gb/codepoint.d.ts.map +1 -0
- package/out/gb/codepoint.js +117 -0
- package/out/gb/codepoint.js.map +1 -0
- package/out/gb/os-downloads.d.ts +45 -0
- package/out/gb/os-downloads.d.ts.map +1 -0
- package/out/gb/os-downloads.js +15 -0
- package/out/gb/os-downloads.js.map +1 -0
- package/out/geometries/point.d.ts +1 -1
- package/out/geometries/point.js +1 -1
- package/out/h3/coverage.d.ts +1 -1
- package/out/h3/coverage.js +1 -1
- package/out/h3/polygon-cells.d.ts +2 -2
- package/out/h3/polygon-cells.js +2 -2
- package/out/projection/transform.d.ts +1 -1
- package/out/tools/tsconfig.tsbuildinfo +1 -1
- package/out/tsconfig.test.tsbuildinfo +1 -1
- package/package.json +5 -4
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software.
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Streams unit-postcode rows from extracted Code-Point Open CSVs and converts their OSGB36
|
|
7
|
+
* coordinates to WGS84.
|
|
8
|
+
*/
|
|
9
|
+
import { normalizePostcodeDisplay } from "@mailwoman/codex/postcode/display-form";
|
|
10
|
+
import { CSVSpliterator } from "spliterator";
|
|
11
|
+
import { osgb36ToWGS84 } from "#osgb36";
|
|
12
|
+
/**
|
|
13
|
+
* The positional quality indicator for a row with no coordinate.
|
|
14
|
+
*
|
|
15
|
+
* These rows have zero eastings and northings.
|
|
16
|
+
* Conversion would place them at a real but wrong location.
|
|
17
|
+
*/
|
|
18
|
+
export const PQI_NO_COORDINATE = 90;
|
|
19
|
+
/**
|
|
20
|
+
* The number of columns in a Code-Point Open CSV row.
|
|
21
|
+
*/
|
|
22
|
+
const CODEPOINT_COLUMNS = 10;
|
|
23
|
+
/**
|
|
24
|
+
* The ONS country codes in Code-Point Open, mapped to ISO 3166-2 subdivisions.
|
|
25
|
+
*
|
|
26
|
+
* Northern Ireland has no code because the product does not cover it.
|
|
27
|
+
*/
|
|
28
|
+
export const CODEPOINT_COUNTRY_CODES = {
|
|
29
|
+
E92000001: "ENG",
|
|
30
|
+
S92000003: "SCT",
|
|
31
|
+
W92000004: "WLS",
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Matches a GB unit postcode with a single space.
|
|
35
|
+
*
|
|
36
|
+
* The pattern accepts any valid outward-code shape, such as `W1A`, `EC1A`, `B1`, or `DN55`.
|
|
37
|
+
* The inward code is always a digit followed by two letters.
|
|
38
|
+
*/
|
|
39
|
+
const UNIT_POSTCODE = /^[A-Z]{1,2}[0-9][A-Z0-9]?\s[0-9][A-Z]{2}$/;
|
|
40
|
+
/**
|
|
41
|
+
* Returns the postcode area.
|
|
42
|
+
* It consists of the leading one or two letters.
|
|
43
|
+
*
|
|
44
|
+
* For example, `SW1A 1AA` gives `SW` and `B33 8TH` gives `B`.
|
|
45
|
+
* `Doc/metadata.txt` counts rows by area.
|
|
46
|
+
*/
|
|
47
|
+
export function postcodeArea(postcode) {
|
|
48
|
+
return /^[A-Z]{1,2}/.exec(postcode)?.[0] ?? "";
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Splits one CSV record into fields with RFC 4180 quoting.
|
|
52
|
+
*
|
|
53
|
+
* @deprecated Use `CSVSpliterator` directly.
|
|
54
|
+
* Callers that stream records should use {@linkcode readCodePointCSV}.
|
|
55
|
+
*/
|
|
56
|
+
export function splitCSVLine(line) {
|
|
57
|
+
return CSVSpliterator.from(line, { header: false }).next().value ?? [];
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Streams every usable record from one extracted area CSV and updates `stats` as it reads.
|
|
61
|
+
*/
|
|
62
|
+
export async function* readCodePointCSV(csvPath, stats) {
|
|
63
|
+
// The CSVs have no header row.
|
|
64
|
+
// OS ships the column names in `Doc/Code-Point_Open_Column_Headers.csv`.
|
|
65
|
+
for await (const row of CSVSpliterator.fromAsync(csvPath, {
|
|
66
|
+
header: false,
|
|
67
|
+
})) {
|
|
68
|
+
stats.read++;
|
|
69
|
+
if (row.length !== CODEPOINT_COLUMNS) {
|
|
70
|
+
stats.skippedMalformed++;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
const postcode = normalizeCodePointSpacing(row[0] ?? "");
|
|
74
|
+
const quality = Number(row[1]);
|
|
75
|
+
const easting = Number(row[2]);
|
|
76
|
+
const northing = Number(row[3]);
|
|
77
|
+
const countryCode = row[4] ?? "";
|
|
78
|
+
if (quality === PQI_NO_COORDINATE) {
|
|
79
|
+
stats.skippedNoCoordinate++;
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
if (!UNIT_POSTCODE.test(postcode) || !Number.isFinite(easting) || !Number.isFinite(northing)) {
|
|
83
|
+
stats.skippedMalformed++;
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
const { latitude, longitude } = osgb36ToWGS84({ easting, northing });
|
|
87
|
+
const area = postcodeArea(postcode);
|
|
88
|
+
stats.yielded++;
|
|
89
|
+
stats.yieldedByArea[area] = (stats.yieldedByArea[area] ?? 0) + 1;
|
|
90
|
+
yield {
|
|
91
|
+
postcode,
|
|
92
|
+
quality,
|
|
93
|
+
easting,
|
|
94
|
+
northing,
|
|
95
|
+
latitude,
|
|
96
|
+
longitude,
|
|
97
|
+
countryCode,
|
|
98
|
+
country: CODEPOINT_COUNTRY_CODES[countryCode] ?? null,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Normalizes Code-Point postcode spacing to the single-space display form.
|
|
104
|
+
*
|
|
105
|
+
* The product specification uses a fixed seven-character field that pads short postcodes with extra spaces.
|
|
106
|
+
* Normalization keeps a padded postcode from becoming a separate entry.
|
|
107
|
+
*/
|
|
108
|
+
export function normalizeCodePointSpacing(raw) {
|
|
109
|
+
return normalizePostcodeDisplay(raw);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Returns a stats object with every count at zero.
|
|
113
|
+
*/
|
|
114
|
+
export function createCodePointParseStats() {
|
|
115
|
+
return { read: 0, yielded: 0, skippedNoCoordinate: 0, skippedMalformed: 0, yieldedByArea: {} };
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=codepoint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codepoint.js","sourceRoot":"","sources":["../../lib/gb/codepoint.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAA;AACjF,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAE5C,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAEvC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,CAAA;AAEnC;;GAEG;AACH,MAAM,iBAAiB,GAAG,EAAE,CAAA;AAE5B;;;;GAIG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACtC,SAAS,EAAE,KAAK;IAChB,SAAS,EAAE,KAAK;IAChB,SAAS,EAAE,KAAK;CACP,CAAA;AA2EV;;;;;GAKG;AACH,MAAM,aAAa,GAAG,2C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ads API's record of one downloadable archive.
|
|
7
|
+
*
|
|
8
|
+
* The API serves OS OpenData products without authentication. `GET /products/<id>/downloads`
|
|
9
|
+
* lists one record per archive, and every OS product fetcher in this repository reads that list.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* The root of the OS Downloads API.
|
|
13
|
+
*/
|
|
14
|
+
export declare const OS_DOWNLOADS_API_BASE = "https://api.os.uk/downloads/v1";
|
|
15
|
+
/**
|
|
16
|
+
* One archive as `GET /products/<id>/downloads` lists it.
|
|
17
|
+
*/
|
|
18
|
+
export interface OSDownload {
|
|
19
|
+
/**
|
|
20
|
+
* The OS-published MD5 of the archive.
|
|
21
|
+
*/
|
|
22
|
+
md5: string;
|
|
23
|
+
/**
|
|
24
|
+
* The archive size in bytes.
|
|
25
|
+
*/
|
|
26
|
+
size: number;
|
|
27
|
+
/**
|
|
28
|
+
* The download URL.
|
|
29
|
+
* It redirects to a CDN object.
|
|
30
|
+
*/
|
|
31
|
+
url: string;
|
|
32
|
+
/**
|
|
33
|
+
* The archive format, such as `CSV`, `GML` or `GeoPackage`.
|
|
34
|
+
*/
|
|
35
|
+
format: string;
|
|
36
|
+
/**
|
|
37
|
+
* The coverage area, such as `GB` or a 100 km grid square.
|
|
38
|
+
*/
|
|
39
|
+
area: string;
|
|
40
|
+
/**
|
|
41
|
+
* The archive file name, such as `codepo_gb.zip`.
|
|
42
|
+
*/
|
|
43
|
+
fileName: string;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=os-downloads.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"os-downloads.d.ts","sourceRoot":"","sources":["../../lib/gb/os-downloads.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH;;GAEG;AACH,eAAO,MAAM,qBAAqB,mCAAmC,CAAA;AAErE;;GAEG;AACH,MAAM,WAAW,UAAU;IAC1B;;OAEG;IACH,GAAG,EAAE,MAAM,CAAA;IACX;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ;;;OAGG;IACH,GAAG,EAAE,MAAM,CAAA;IACX;;OAEG;IACH,MAAM,EAAE,MAAM,CAAA;IACd;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAA;CAChB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* The Ordnance Survey Downloads API's record of one downloadable archive.
|
|
7
|
+
*
|
|
8
|
+
* The API serves OS OpenData products without authentication. `GET /products/<id>/downloads`
|
|
9
|
+
* lists one record per archive, and every OS product fetcher in this repository reads that list.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* The root of the OS Downloads API.
|
|
13
|
+
*/
|
|
14
|
+
export const OS_DOWNLOADS_API_BASE = "https://api.os.uk/downloads/v1";
|
|
15
|
+
//# sourceMappingURL=os-downloads.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"os-downloads.js","sourceRoot":"","sources":["../../lib/gb/os-downloads.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,gCAAgC,CAAA"}
|
|
@@ -188,7 +188,7 @@ export declare class GeoPoint implements PointLiteral {
|
|
|
188
188
|
*/
|
|
189
189
|
is3D(): boolean;
|
|
190
190
|
/**
|
|
191
|
-
* Whether the GeoPoint
|
|
191
|
+
* Whether the GeoPoint sits at 0, 0 (Null Island).
|
|
192
192
|
*/
|
|
193
193
|
isNullIsland(): boolean;
|
|
194
194
|
toJSON(): PointLiteral;
|
package/out/geometries/point.js
CHANGED
|
@@ -223,7 +223,7 @@ export class GeoPoint {
|
|
|
223
223
|
return this.#altitude !== 0;
|
|
224
224
|
}
|
|
225
225
|
/**
|
|
226
|
-
* Whether the GeoPoint
|
|
226
|
+
* Whether the GeoPoint sits at 0, 0 (Null Island).
|
|
227
227
|
*/
|
|
228
228
|
isNullIsland() {
|
|
229
229
|
return this.#latitude === 0 && this.#longitude === 0;
|
package/out/h3/coverage.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ export interface CoverageRowProbe {
|
|
|
24
24
|
*
|
|
25
25
|
* A caller must treat it as an unknown value, separate from `{completeness: 0}`.
|
|
26
26
|
*
|
|
27
|
-
* The shared mapping owns the
|
|
27
|
+
* The shared mapping owns the rule for a `basis` column that holds NULL.
|
|
28
28
|
* A NULL column means the artifact predates `basis`.
|
|
29
29
|
*
|
|
30
30
|
* It recorded source presence and no stronger basis than the builder had.
|
package/out/h3/coverage.js
CHANGED
|
@@ -19,7 +19,7 @@ import { shortCellToInt } from "#h3/cell";
|
|
|
19
19
|
*
|
|
20
20
|
* A caller must treat it as an unknown value, separate from `{completeness: 0}`.
|
|
21
21
|
*
|
|
22
|
-
* The shared mapping owns the
|
|
22
|
+
* The shared mapping owns the rule for a `basis` column that holds NULL.
|
|
23
23
|
* A NULL column means the artifact predates `basis`.
|
|
24
24
|
*
|
|
25
25
|
* It recorded source presence and no stronger basis than the builder had.
|
|
@@ -38,8 +38,8 @@ export interface FeatureCells {
|
|
|
38
38
|
partial: H3Cell[];
|
|
39
39
|
}
|
|
40
40
|
/**
|
|
41
|
-
*
|
|
42
|
-
* h3 reserves its buffer from, approximate on purpose.
|
|
41
|
+
* The count of cells at `resolution` that the feature's bounding box spans —
|
|
42
|
+
* the same quantity h3 reserves its buffer from, approximate on purpose.
|
|
43
43
|
*/
|
|
44
44
|
export declare function estimateCellCount(polygons: MultiPolygonRings, resolution: number): number;
|
|
45
45
|
/**
|
package/out/h3/polygon-cells.js
CHANGED
|
@@ -61,8 +61,8 @@ function canContainCell(box, resolution) {
|
|
|
61
61
|
return heightM >= minimumWidthM && widthM >= minimumWidthM;
|
|
62
62
|
}
|
|
63
63
|
/**
|
|
64
|
-
*
|
|
65
|
-
* h3 reserves its buffer from, approximate on purpose.
|
|
64
|
+
* The count of cells at `resolution` that the feature's bounding box spans —
|
|
65
|
+
* the same quantity h3 reserves its buffer from, approximate on purpose.
|
|
66
66
|
*/
|
|
67
67
|
export function estimateCellCount(polygons, resolution) {
|
|
68
68
|
const box = ringsBoundingBox(polygons);
|