@mailwoman/tiger 11.5.0 → 12.0.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/out/sdk/gazetteer.d.ts +45 -0
- package/out/sdk/gazetteer.d.ts.map +1 -1
- package/out/sdk/gazetteer.js +50 -0
- package/out/sdk/gazetteer.js.map +1 -1
- package/out/sdk/tsconfig.tsbuildinfo +1 -1
- package/out/tools/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -7
- package/sdk/gazetteer.ts +88 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mailwoman/tiger",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "12.0.0",
|
|
4
4
|
"description": "US Census TIGER/Line data processing and analysis.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"census",
|
|
@@ -132,14 +132,14 @@
|
|
|
132
132
|
"test": "node ./out/sdk/TIGERService.test.js"
|
|
133
133
|
},
|
|
134
134
|
"dependencies": {
|
|
135
|
-
"@mailwoman/core": "
|
|
136
|
-
"@mailwoman/spatial": "
|
|
137
|
-
"@mailwoman/sqlite": "
|
|
135
|
+
"@mailwoman/core": "12.0.0",
|
|
136
|
+
"@mailwoman/spatial": "12.0.0",
|
|
137
|
+
"@mailwoman/sqlite": "12.0.0",
|
|
138
138
|
"@turf/boolean-contains": "^7.4.0",
|
|
139
|
-
"kysely": "^0.29.
|
|
139
|
+
"kysely": "^0.29.9",
|
|
140
140
|
"path-ts": "^2.5.0",
|
|
141
|
-
"spliterator": "^
|
|
142
|
-
"type-fest": "^
|
|
141
|
+
"spliterator": "^11.0.0",
|
|
142
|
+
"type-fest": "^6.0.3"
|
|
143
143
|
},
|
|
144
144
|
"devDependencies": {
|
|
145
145
|
"@protomaps/basemaps": "^5.7.2"
|
package/sdk/gazetteer.ts
CHANGED
|
@@ -27,6 +27,11 @@ import { downloadIfNeeded } from "#sdk/download"
|
|
|
27
27
|
export const CensusGazetteerKind = {
|
|
28
28
|
Place: "place",
|
|
29
29
|
CountySubdivision: "cousubs",
|
|
30
|
+
/**
|
|
31
|
+
* Core based statistical areas: the metropolitan and micropolitan statistical areas the
|
|
32
|
+
* Office of Management and Budget delineates. {@link readCBSAGazetteer} reads this file.
|
|
33
|
+
*/
|
|
34
|
+
CoreBasedStatisticalArea: "cbsa",
|
|
30
35
|
} as const
|
|
31
36
|
|
|
32
37
|
export type CensusGazetteerKind = (typeof CensusGazetteerKind)[keyof typeof CensusGazetteerKind]
|
|
@@ -136,3 +141,86 @@ export async function* readCensusGazetteer(
|
|
|
136
141
|
}
|
|
137
142
|
}
|
|
138
143
|
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* The two kinds of core based statistical area.
|
|
147
|
+
*/
|
|
148
|
+
export const CBSAKind = {
|
|
149
|
+
Metropolitan: "metropolitan",
|
|
150
|
+
Micropolitan: "micropolitan",
|
|
151
|
+
} as const
|
|
152
|
+
|
|
153
|
+
export type CBSAKind = (typeof CBSAKind)[keyof typeof CBSAKind]
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* One row of the core based statistical area gazetteer file.
|
|
157
|
+
*/
|
|
158
|
+
export interface CBSAGazetteerEntry {
|
|
159
|
+
/**
|
|
160
|
+
* The area's five-digit CBSA code, `10180`.
|
|
161
|
+
*/
|
|
162
|
+
geoid: string
|
|
163
|
+
/**
|
|
164
|
+
* The area's title with its designator, `Abilene, TX Metro Area`.
|
|
165
|
+
*/
|
|
166
|
+
title: string
|
|
167
|
+
/**
|
|
168
|
+
* The area's title without its designator, `Abilene, TX`.
|
|
169
|
+
*/
|
|
170
|
+
name: string
|
|
171
|
+
kind: CBSAKind
|
|
172
|
+
/**
|
|
173
|
+
* The code of the combined statistical area the area belongs to, or `null`.
|
|
174
|
+
*/
|
|
175
|
+
combinedArea: string | null
|
|
176
|
+
latitude: number
|
|
177
|
+
longitude: number
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const CBSA_DESIGNATOR = / (?:Metro|Micro) Area$/u
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Reads the national core based statistical area gazetteer file.
|
|
184
|
+
*
|
|
185
|
+
* `CBSA_TYPE` is `1` for a metropolitan area and `2` for a micropolitan one.
|
|
186
|
+
*
|
|
187
|
+
* @throws When the header lacks a column the reader needs, or a row states another type.
|
|
188
|
+
*/
|
|
189
|
+
export async function* readCBSAGazetteer(path: PathBuilderLike): AsyncGenerator<CBSAGazetteerEntry> {
|
|
190
|
+
let header: string[] | null = null
|
|
191
|
+
|
|
192
|
+
const at = (column: string): number => {
|
|
193
|
+
const index = header!.indexOf(column)
|
|
194
|
+
|
|
195
|
+
if (index === -1) throw new Error(`${path}: the gazetteer header has no ${column} column`)
|
|
196
|
+
|
|
197
|
+
return index
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
for await (const fields of readUnquotedTSV(path)) {
|
|
201
|
+
const row = fields.map((field) => String(field ?? "").trim())
|
|
202
|
+
|
|
203
|
+
if (!header) {
|
|
204
|
+
header = row
|
|
205
|
+
|
|
206
|
+
continue
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const type = row[at("CBSA_TYPE")]
|
|
210
|
+
const title = row[at("NAME")]!
|
|
211
|
+
|
|
212
|
+
if (type !== "1" && type !== "2") {
|
|
213
|
+
throw new Error(`${path}: CBSA ${row[at("GEOID")]} states CBSA_TYPE ${type}`)
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
yield {
|
|
217
|
+
geoid: row[at("GEOID")]!,
|
|
218
|
+
title,
|
|
219
|
+
name: title.replace(CBSA_DESIGNATOR, ""),
|
|
220
|
+
kind: type === "1" ? CBSAKind.Metropolitan : CBSAKind.Micropolitan,
|
|
221
|
+
combinedArea: row[at("CSAFP")] || null,
|
|
222
|
+
latitude: Number(row[at("INTPTLAT")]),
|
|
223
|
+
longitude: Number(row[at("INTPTLONG")]),
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|