@mailwoman/tiger 11.1.0 → 11.3.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/lib/geoid.ts +1 -1
- package/lib/source.ts +26 -0
- package/lib/state.ts +2 -2
- package/lib/tabulation-block.ts +2 -2
- package/lib/tract.ts +7 -6
- package/out/geoid.d.ts +1 -1
- package/out/geoid.js +1 -1
- package/out/sdk/fetch.d.ts +54 -0
- package/out/sdk/fetch.d.ts.map +1 -1
- package/out/sdk/fetch.js +55 -9
- package/out/sdk/fetch.js.map +1 -1
- package/out/sdk/gazetteer.d.ts +57 -0
- package/out/sdk/gazetteer.d.ts.map +1 -0
- package/out/sdk/gazetteer.js +82 -0
- package/out/sdk/gazetteer.js.map +1 -0
- package/out/sdk/tsconfig.tsbuildinfo +1 -1
- package/out/source.d.ts +16 -0
- package/out/source.d.ts.map +1 -0
- package/out/source.js +18 -0
- package/out/source.js.map +1 -0
- package/out/state.d.ts +2 -2
- package/out/tabulation-block.d.ts +2 -2
- package/out/tools/race/dots/map.js +1 -1
- package/out/tools/race/dots/map.js.map +1 -1
- package/out/tools/race/dots.js +1 -1
- package/out/tools/race/dots.js.map +1 -1
- package/out/tools/serve-range.d.ts +6 -3
- package/out/tools/serve-range.d.ts.map +1 -1
- package/out/tools/serve-range.js +6 -3
- package/out/tools/serve-range.js.map +1 -1
- package/out/tools/tsconfig.tsbuildinfo +1 -1
- package/out/tract.d.ts +7 -6
- package/out/tract.d.ts.map +1 -1
- package/out/tsconfig.test.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/sdk/fetch.ts +112 -10
- package/sdk/gazetteer.ts +138 -0
- package/tools/race/dots/map.ts +1 -1
- package/tools/race/dots.ts +1 -1
- package/tools/serve-range.ts +6 -3
package/lib/geoid.ts
CHANGED
|
@@ -203,7 +203,7 @@ export type FIPSCongressionalDistrictCode = Tagged<string, "FIPSConressionalDist
|
|
|
203
203
|
// #region GeoID Parsing Setup
|
|
204
204
|
|
|
205
205
|
/**
|
|
206
|
-
* A part of a GeoID
|
|
206
|
+
* A part of a GeoID and its corresponding name.
|
|
207
207
|
*
|
|
208
208
|
* @internal
|
|
209
209
|
*/
|
package/lib/source.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Where the U.S. Census Bureau publishes the TIGER/Line Shapefiles, for the interpolation
|
|
6
|
+
* build that records them and for a server that links a user to them.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { SourceLocation } from "@mailwoman/core/resolver"
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The name the US interpolation build records in a manifest's `source` for TIGER/Line.
|
|
13
|
+
*/
|
|
14
|
+
export const TIGER_SOURCE_NAME = "tiger"
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Where a user obtains each source a TIGER/Line layer records.
|
|
18
|
+
*
|
|
19
|
+
* The page lists every TIGER/Line release by year and links each release's files.
|
|
20
|
+
*/
|
|
21
|
+
export const TIGER_SOURCE_LOCATIONS: Readonly<Record<string, SourceLocation>> = {
|
|
22
|
+
[TIGER_SOURCE_NAME]: {
|
|
23
|
+
title: "U.S. Census Bureau, TIGER/Line Shapefiles",
|
|
24
|
+
url: "https://www.census.gov/geographies/mapping-files/time-series/geo/tiger-line-file.html",
|
|
25
|
+
},
|
|
26
|
+
}
|
package/lib/state.ts
CHANGED
|
@@ -667,8 +667,8 @@ export interface TIGERState {
|
|
|
667
667
|
[GeoIDPart.State]: AdminLevel1Code
|
|
668
668
|
|
|
669
669
|
/**
|
|
670
|
-
* The geometry of the
|
|
671
|
-
*
|
|
670
|
+
* The geometry of the state, typically a polygon, but it may be a multipolygon
|
|
671
|
+
* for states with holes or islands.
|
|
672
672
|
*
|
|
673
673
|
* @title Geometry
|
|
674
674
|
*/
|
package/lib/tabulation-block.ts
CHANGED
|
@@ -7,7 +7,7 @@ import type { TIGERProperty, TIGERPropertyRecord } from "#constants"
|
|
|
7
7
|
import type { GeoIDPart, FIPSBlockGeoID, ParsedGeoIDBlockLevel } from "#geoid"
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* The properties of a tabulated block from the
|
|
10
|
+
* The properties of a tabulated block from the TIGER/Line dataset.
|
|
11
11
|
*/
|
|
12
12
|
export type TIGERTabulatedBlockProperties = Pick<
|
|
13
13
|
TIGERPropertyRecord<FIPSBlockGeoID>,
|
|
@@ -44,7 +44,7 @@ export interface TIGERBlockFeatureCollection {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
|
-
* A tabulated block from the
|
|
47
|
+
* A tabulated block from the TIGER/Line dataset.
|
|
48
48
|
*
|
|
49
49
|
* @public
|
|
50
50
|
*/
|
package/lib/tract.ts
CHANGED
|
@@ -7,20 +7,21 @@ import type { TIGERProperty, TIGERPropertyRecord } from "#constants"
|
|
|
7
7
|
import type { FIPSTractGeoID, GeoIDPart, ParsedGeoIDTractLevel } from "#geoid"
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* @title
|
|
10
|
+
* @title TIGER Tract
|
|
11
11
|
* @public
|
|
12
12
|
*/
|
|
13
13
|
export interface TIGERTract extends ParsedGeoIDTractLevel {
|
|
14
14
|
/**
|
|
15
|
-
* The GeoID
|
|
15
|
+
* The GeoID that identifies the tract.
|
|
16
16
|
*
|
|
17
17
|
* @title Geo ID
|
|
18
18
|
*/
|
|
19
19
|
GEOID: FIPSTractGeoID
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
|
-
* The geometry
|
|
23
|
-
*
|
|
22
|
+
* The tract's geometry is typically a polygon.
|
|
23
|
+
*
|
|
24
|
+
* It may be a multipolygon when the tract contains holes or islands.
|
|
24
25
|
*
|
|
25
26
|
* @title Geometry
|
|
26
27
|
*/
|
|
@@ -28,7 +29,7 @@ export interface TIGERTract extends ParsedGeoIDTractLevel {
|
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
/**
|
|
31
|
-
* Properties
|
|
32
|
+
* Properties recorded for a Census tract.
|
|
32
33
|
*/
|
|
33
34
|
export type TIGERTractProperties = Pick<
|
|
34
35
|
TIGERPropertyRecord<FIPSTractGeoID>,
|
|
@@ -45,6 +46,6 @@ export type TIGERTractProperties = Pick<
|
|
|
45
46
|
>
|
|
46
47
|
|
|
47
48
|
/**
|
|
48
|
-
* A
|
|
49
|
+
* A GeoJSON feature that represents a Census tract.
|
|
49
50
|
*/
|
|
50
51
|
export type TIGERTractFeature = GeoFeature<MultiPolygonLiteral, TIGERTractProperties>
|
package/out/geoid.d.ts
CHANGED
|
@@ -183,7 +183,7 @@ export type FIPSPlaceCode = Tagged<string, "FIPSPlaceCode">;
|
|
|
183
183
|
*/
|
|
184
184
|
export type FIPSCongressionalDistrictCode = Tagged<string, "FIPSConressionalDistrictCode">;
|
|
185
185
|
/**
|
|
186
|
-
* A part of a GeoID
|
|
186
|
+
* A part of a GeoID and its corresponding name.
|
|
187
187
|
*
|
|
188
188
|
* @internal
|
|
189
189
|
*/
|
package/out/geoid.js
CHANGED
package/out/sdk/fetch.d.ts
CHANGED
|
@@ -73,6 +73,60 @@ export interface FetchTIGERResult {
|
|
|
73
73
|
table: string;
|
|
74
74
|
inserted: number;
|
|
75
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* A TIGER/Line boundary product that {@link readTIGERBoundaries} reads with its geometry.
|
|
78
|
+
*/
|
|
79
|
+
export declare const TIGERBoundaryLevel: {
|
|
80
|
+
readonly County: "county";
|
|
81
|
+
readonly CountySubdivision: "cousub";
|
|
82
|
+
readonly Place: "place";
|
|
83
|
+
};
|
|
84
|
+
export type TIGERBoundaryLevel = (typeof TIGERBoundaryLevel)[keyof typeof TIGERBoundaryLevel];
|
|
85
|
+
/**
|
|
86
|
+
* One boundary {@link readTIGERBoundaries} yields, in EPSG:4326.
|
|
87
|
+
*/
|
|
88
|
+
export interface TIGERBoundary {
|
|
89
|
+
level: TIGERBoundaryLevel;
|
|
90
|
+
geoid: string;
|
|
91
|
+
/**
|
|
92
|
+
* The name with its legal/statistical area description (`NAMELSAD`), such as `Adjuntas Municipio`.
|
|
93
|
+
*/
|
|
94
|
+
name: string;
|
|
95
|
+
statefp: string;
|
|
96
|
+
geometry: {
|
|
97
|
+
type: string;
|
|
98
|
+
coordinates: unknown;
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Options for {@link readTIGERBoundaries}.
|
|
103
|
+
*/
|
|
104
|
+
export interface ReadTIGERBoundariesOptions {
|
|
105
|
+
level: TIGERBoundaryLevel;
|
|
106
|
+
/**
|
|
107
|
+
* The two-digit state or territory FIPS code, such as `"72"`.
|
|
108
|
+
*/
|
|
109
|
+
stateFIPS: string;
|
|
110
|
+
/**
|
|
111
|
+
* @defaultValue `2024`
|
|
112
|
+
*/
|
|
113
|
+
vintage?: number;
|
|
114
|
+
/**
|
|
115
|
+
* The root of the download cache.
|
|
116
|
+
*
|
|
117
|
+
* @defaultValue the Mailwoman data root.
|
|
118
|
+
*/
|
|
119
|
+
dataRoot?: string;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Downloads one state's or territory's TIGER/Line boundaries at `level` and yields each with its geometry.
|
|
123
|
+
*
|
|
124
|
+
* Counties come from the national file, filtered to the state.
|
|
125
|
+
* County subdivisions and places come from the state's own file.
|
|
126
|
+
*
|
|
127
|
+
* @throws When the Census Bureau serves no file for the state at `level`.
|
|
128
|
+
*/
|
|
129
|
+
export declare function readTIGERBoundaries(options: ReadTIGERBoundariesOptions): AsyncGenerator<TIGERBoundary>;
|
|
76
130
|
/**
|
|
77
131
|
* Downloads one state's TIGER/Line files at `level`, loads them into a SQLite database
|
|
78
132
|
* and yields progress events.
|
package/out/sdk/fetch.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../sdk/fetch.ts"],"names":[],"mappings":"AAoBA;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,YAAY,GAAG,OAAO,GAAG,UAAU,CAAA;AAcjE;;GAEG;AACH,MAAM,WAAW,iBAAiB;IACjC;;OAEG;IACH,SAAS,EAAE,MAAM,CAAA;IAEjB;;;;OAIG;IACH,KAAK,CAAC,EAAE,eAAe,CAAA;IAEvB;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IAEjB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IAEf;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CAClB;AAED;;;;GAIG;AACH,MAAM,MAAM,eAAe,GACxB;IAAE,KAAK,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,GACpD;IAAE,KAAK,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAClC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAA;AAErD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAChC,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;CAChB;
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../sdk/fetch.ts"],"names":[],"mappings":"AAoBA;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,YAAY,GAAG,OAAO,GAAG,UAAU,CAAA;AAcjE;;GAEG;AACH,MAAM,WAAW,iBAAiB;IACjC;;OAEG;IACH,SAA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,CAAC;QAAC,WAAW,EAAE,OAAO,CAAA;KAAE,CAAA;CAChD;AAED;;GAEG;AACH,MAAM,WAAW,0BAA0B;IAC1C,KAAK,EAAE,kBAAkB,CAAA;IACzB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAA;IACjB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;CACjB;AAED;;;;;;;GAOG;AACH,wBAAuB,mBAAmB,CAAC,OAAO,EAAE,0BAA0B,GAAG,cAAc,CAAC,aAAa,CAAC,CA8B7G;AAiBD;;;;;GAKG;AACH,wBAAuB,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,cAAc,CAAC,eAAe,EAAE,gBAAgB,CAAC,CA0G/G"}
|
package/out/sdk/fetch.js
CHANGED
|
@@ -4,7 +4,7 @@ import { APIClient, pluckResponseData } from "@mailwoman/core/api";
|
|
|
4
4
|
import { dataRootPath } from "@mailwoman/core/data-root";
|
|
5
5
|
import { makeDirectories } from "@mailwoman/core/fs/writers";
|
|
6
6
|
import { extractZipEntries } from "@mailwoman/core/fs/zip";
|
|
7
|
-
import { stringifyJSON } from "@mailwoman/core/json";
|
|
7
|
+
import { stringifyJSON } from "@mailwoman/core/values/json";
|
|
8
8
|
import { ogr2ogrGeoJSONSeq } from "@mailwoman/spatial/tools/ogr/stream";
|
|
9
9
|
import { DatabaseClient } from "@mailwoman/sqlite/client";
|
|
10
10
|
import { PathBuilder } from "path-ts";
|
|
@@ -79,6 +79,58 @@ function buildRow(level, p, geometry, state) {
|
|
|
79
79
|
};
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* Downloads one TIGER/Line shapefile archive into `cacheDir` unless a valid copy is there, and extracts it.
|
|
84
|
+
*
|
|
85
|
+
* @param directory The product directory under `TIGER<vintage>/`, such as `PLACE`.
|
|
86
|
+
* @param product The product name in the file name, such as `place`.
|
|
87
|
+
* @param unit The state FIPS code, a state and county code, or `us` for a national file.
|
|
88
|
+
*/
|
|
89
|
+
async function downloadTIGERLayer(directory, product, unit, vintage, cacheDir) {
|
|
90
|
+
const layer = `tl_${vintage}_${unit}_${product}`;
|
|
91
|
+
const zipPath = cacheDir(`${layer}.zip`);
|
|
92
|
+
const cached = await downloadIfNeeded(`${CENSUS_HOST}/geo/tiger/TIGER${vintage}/${directory}/${layer}.zip`, zipPath);
|
|
93
|
+
await extractZipEntries(zipPath, cacheDir);
|
|
94
|
+
return { layer, shpPath: cacheDir(`${layer}.shp`), cached };
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* A TIGER/Line boundary product that {@link readTIGERBoundaries} reads with its geometry.
|
|
98
|
+
*/
|
|
99
|
+
export const TIGERBoundaryLevel = {
|
|
100
|
+
County: "county",
|
|
101
|
+
CountySubdivision: "cousub",
|
|
102
|
+
Place: "place",
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Downloads one state's or territory's TIGER/Line boundaries at `level` and yields each with its geometry.
|
|
106
|
+
*
|
|
107
|
+
* Counties come from the national file, filtered to the state.
|
|
108
|
+
* County subdivisions and places come from the state's own file.
|
|
109
|
+
*
|
|
110
|
+
* @throws When the Census Bureau serves no file for the state at `level`.
|
|
111
|
+
*/
|
|
112
|
+
export async function* readTIGERBoundaries(options) {
|
|
113
|
+
const { level, stateFIPS } = options;
|
|
114
|
+
const vintage = options.vintage ?? 2024;
|
|
115
|
+
const unit = level === TIGERBoundaryLevel.County ? "us" : stateFIPS;
|
|
116
|
+
const cacheDir = PathBuilder.from(options.dataRoot ?? DEFAULT_DATA_ROOT)("tiger", String(vintage), unit);
|
|
117
|
+
await makeDirectories(cacheDir);
|
|
118
|
+
const { layer, shpPath } = await downloadTIGERLayer(level.toUpperCase(), level, unit, vintage, cacheDir);
|
|
119
|
+
const sql = `SELECT GEOID AS geoid, NAMELSAD AS name, STATEFP AS statefp FROM "${layer}" WHERE STATEFP = '${stateFIPS}'`;
|
|
120
|
+
for await (const feature of ogr2ogrGeoJSONSeq(["-f", "GeoJSONSeq", "-t_srs", "EPSG:4326", "-sql", sql, "/vsistdout/", shpPath], layer)) {
|
|
121
|
+
const { properties, geometry } = feature;
|
|
122
|
+
if (!properties?.geoid || !geometry) {
|
|
123
|
+
throw new Error(`${layer}: a feature has no GEOID or no geometry`);
|
|
124
|
+
}
|
|
125
|
+
yield {
|
|
126
|
+
level,
|
|
127
|
+
geoid: properties.geoid,
|
|
128
|
+
name: properties.name ?? "",
|
|
129
|
+
statefp: properties.statefp ?? stateFIPS,
|
|
130
|
+
geometry,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
}
|
|
82
134
|
async function discoverCounties(state, vintage) {
|
|
83
135
|
const html = await new APIClient({ displayName: "tiger-listing", retry: true })
|
|
84
136
|
.fetch({ url: `${CENSUS_HOST}/geo/tiger/TIGER${vintage}/ADDRFEAT/`, responseType: "text" })
|
|
@@ -156,14 +208,8 @@ export async function* fetchTIGER(options) {
|
|
|
156
208
|
};
|
|
157
209
|
for (const geo of geoCodes) {
|
|
158
210
|
const unit = level === "addrfeat" ? state + geo : state;
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
const url = `${CENSUS_HOST}/geo/tiger/TIGER${vintage}/${LEVEL_DIR[level]}/${zipName}`;
|
|
162
|
-
const cached = await downloadIfNeeded(url, zipPath);
|
|
163
|
-
yield { phase: "download", file: zipName, cached };
|
|
164
|
-
await extractZipEntries(zipPath, cacheDir);
|
|
165
|
-
const layer = `tl_${vintage}_${unit}_${level}`;
|
|
166
|
-
const shpPath = cacheDir(layer + ".shp");
|
|
211
|
+
const { layer, shpPath, cached } = await downloadTIGERLayer(LEVEL_DIR[level], level, unit, vintage, cacheDir);
|
|
212
|
+
yield { phase: "download", file: `${layer}.zip`, cached };
|
|
167
213
|
yield { phase: "extract", file: layer + ".shp" };
|
|
168
214
|
const args = [
|
|
169
215
|
"-f",
|
package/out/sdk/fetch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../sdk/fetch.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,kEAAkE;AAElE,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../sdk/fetch.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,kEAAkE;AAElE,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAA;AACvE,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAErC,OAAO,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAA;AAE1C,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAEhD,MAAM,WAAW,GAAG,yBAAyB,CAAA;AAC7C,MAAM,iBAAiB,GAAG,YAAY,EAAE,CAAA;AAQxC,MAAM,SAAS,GAAoC;IAClD,UAAU,EAAE,YAAY;IACxB,KAAK,EAAE,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AAK,CACL,EAAE,CAAC;gBACH,IAAI,CAAC,IAAI,CAAC,UAAU;oBAAE,SAAQ;gBAE9B,IAAI,KAAK,KAAK,YAAY,IAAI,CAAC,IAAI,CAAC,QAAQ;oBAAE,SAAQ;gBACtD,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAA;gBAElE,IAAI,KAAK,CAAC,MAAM,IAAI,SAAS,EAAE,CAAC;oBAC/B,MAAM,KAAK,EAAE,CAAA;oBACb,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,EAAE,CAAA;gBAC5C,CAAC;YACF,CAAC;YAED,MAAM,KAAK,EAAE,CAAA;YACb,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,EAAE,CAAA;QAC5C,CAAC;QAED,GAAG,CAAC,IAAI,CAAC,kCAAkC,CAAC,CAAA;QAE5C,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAA;IACxD,CAAC;YAAS,CAAC;QACV,MAAM,GAAG,CAAC,OAAO,EAAE,CAAA;IACpB,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { PathBuilder, type PathBuilderLike } from "path-ts";
|
|
2
|
+
/**
|
|
3
|
+
* The gazetteer files {@link fetchCensusGazetteer} reads, by the name the Census Bureau files them under.
|
|
4
|
+
*/
|
|
5
|
+
export declare const CensusGazetteerKind: {
|
|
6
|
+
readonly Place: "place";
|
|
7
|
+
readonly CountySubdivision: "cousubs";
|
|
8
|
+
};
|
|
9
|
+
export type CensusGazetteerKind = (typeof CensusGazetteerKind)[keyof typeof CensusGazetteerKind];
|
|
10
|
+
/**
|
|
11
|
+
* One row of a Census gazetteer file.
|
|
12
|
+
*/
|
|
13
|
+
export interface CensusGazetteerEntry {
|
|
14
|
+
kind: CensusGazetteerKind;
|
|
15
|
+
/**
|
|
16
|
+
* The USPS state code.
|
|
17
|
+
*/
|
|
18
|
+
state: string;
|
|
19
|
+
geoid: string;
|
|
20
|
+
/**
|
|
21
|
+
* The GNIS feature id, from the zero-padded `ANSICODE`.
|
|
22
|
+
*/
|
|
23
|
+
gnisID: number;
|
|
24
|
+
name: string;
|
|
25
|
+
/**
|
|
26
|
+
* The legal/statistical area description code (`LSAD`), or `null` in the county subdivision file.
|
|
27
|
+
* That file has no `LSAD` column.
|
|
28
|
+
*/
|
|
29
|
+
lsad: string | null;
|
|
30
|
+
/**
|
|
31
|
+
* The functional status code (`FUNCSTAT`), as `TIGERFunctionalStatus` defines it.
|
|
32
|
+
*/
|
|
33
|
+
functionalStatus: string;
|
|
34
|
+
latitude: number;
|
|
35
|
+
longitude: number;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The gazetteer vintage {@link fetchCensusGazetteer} reads unless told otherwise.
|
|
39
|
+
*/
|
|
40
|
+
export declare const DEFAULT_CENSUS_GAZETTEER_VINTAGE = 2024;
|
|
41
|
+
/**
|
|
42
|
+
* Downloads one national gazetteer file into `<dataRoot>/tiger/<vintage>/`
|
|
43
|
+
* unless a valid copy is there, and returns the path of its extracted text file.
|
|
44
|
+
*/
|
|
45
|
+
export declare function fetchCensusGazetteer(kind: CensusGazetteerKind, options?: {
|
|
46
|
+
vintage?: number;
|
|
47
|
+
dataRoot?: PathBuilderLike;
|
|
48
|
+
}): Promise<PathBuilder>;
|
|
49
|
+
/**
|
|
50
|
+
* Reads a national gazetteer text file.
|
|
51
|
+
*
|
|
52
|
+
* The files are tab-separated with a header row, and they pad the last column with trailing spaces.
|
|
53
|
+
*
|
|
54
|
+
* @throws When the header lacks a column the reader needs.
|
|
55
|
+
*/
|
|
56
|
+
export declare function readCensusGazetteer(path: PathBuilderLike, kind: CensusGazetteerKind): AsyncGenerator<Cens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
// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
3
|
+
/**
|
|
4
|
+
* @file The Census Bureau's national gazetteer files: one row per place or county subdivision, with its
|
|
5
|
+
* GEOID, its GNIS feature id (`ANSICODE`), its legal/statistical area description, its functional
|
|
6
|
+
* status and an interior point.
|
|
7
|
+
*
|
|
8
|
+
* The GNIS id ties a Census entity to the GNIS populated place of the same feature, and the GEOID ties
|
|
9
|
+
* it to a Who's On First record holding it as its `uscensus:geoid` concordance. A GNIS place whose
|
|
10
|
+
* Census entity a WOF record already holds is the same place, whatever either source calls it.
|
|
11
|
+
*
|
|
12
|
+
* A work of the United States Government, public domain under 17 U.S.C. § 105.
|
|
13
|
+
*/
|
|
14
|
+
import { dataRootPath } from "@mailwoman/core/data-root";
|
|
15
|
+
import { readUnquotedTSV } from "@mailwoman/core/fs/delimited";
|
|
16
|
+
import { makeDirectories } from "@mailwoman/core/fs/writers";
|
|
17
|
+
import { extractZipEntries } from "@mailwoman/core/fs/zip";
|
|
18
|
+
import { PathBuilder } from "path-ts";
|
|
19
|
+
import { downloadIfNeeded } from "#sdk/download";
|
|
20
|
+
/**
|
|
21
|
+
* The gazetteer files {@link fetchCensusGazetteer} reads, by the name the Census Bureau files them under.
|
|
22
|
+
*/
|
|
23
|
+
export const CensusGazetteerKind = {
|
|
24
|
+
Place: "place",
|
|
25
|
+
CountySubdivision: "cousubs",
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* The gazetteer vintage {@link fetchCensusGazetteer} reads unless told otherwise.
|
|
29
|
+
*/
|
|
30
|
+
export const DEFAULT_CENSUS_GAZETTEER_VINTAGE = 2024;
|
|
31
|
+
function gazetteerFileName(kind, vintage) {
|
|
32
|
+
return `${vintage}_Gaz_${kind}_national`;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Downloads one national gazetteer file into `<dataRoot>/tiger/<vintage>/`
|
|
36
|
+
* unless a valid copy is there, and returns the path of its extracted text file.
|
|
37
|
+
*/
|
|
38
|
+
export async function fetchCensusGazetteer(kind, options = {}) {
|
|
39
|
+
const vintage = options.vintage ?? DEFAULT_CENSUS_GAZETTEER_VINTAGE;
|
|
40
|
+
const directory = PathBuilder.from(options.dataRoot ?? dataRootPath())("tiger", String(vintage));
|
|
41
|
+
const name = gazetteerFileName(kind, vintage);
|
|
42
|
+
const zipPath = directory(`${name}.zip`);
|
|
43
|
+
await makeDirectories(directory);
|
|
44
|
+
await downloadIfNeeded(`https://www2.census.gov/geo/docs/maps-data/data/gazetteer/${vintage}_Gazetteer/${name}.zip`, zipPath);
|
|
45
|
+
await extractZipEntries(zipPath, directory, { skipExisting: true });
|
|
46
|
+
return directory(`${name}.txt`);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Reads a national gazetteer text file.
|
|
50
|
+
*
|
|
51
|
+
* The files are tab-separated with a header row, and they pad the last column with trailing spaces.
|
|
52
|
+
*
|
|
53
|
+
* @throws When the header lacks a column the reader needs.
|
|
54
|
+
*/
|
|
55
|
+
export async function* readCensusGazetteer(path, kind) {
|
|
56
|
+
let header = null;
|
|
57
|
+
const at = (column) => {
|
|
58
|
+
const index = header.indexOf(column);
|
|
59
|
+
if (index === -1)
|
|
60
|
+
throw new Error(`${path}: the gazetteer header has no ${column} column`);
|
|
61
|
+
return index;
|
|
62
|
+
};
|
|
63
|
+
for await (const fields of readUnquotedTSV(path)) {
|
|
64
|
+
const row = fields.map((field) => String(field ?? "").trim());
|
|
65
|
+
if (!header) {
|
|
66
|
+
header = row;
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
yield {
|
|
70
|
+
kind,
|
|
71
|
+
state: row[at("USPS")],
|
|
72
|
+
geoid: row[at("GEOID")],
|
|
73
|
+
gnisID: Number(row[at("ANSICODE")]),
|
|
74
|
+
name: row[at("NAME")],
|
|
75
|
+
lsad: header.includes("LSAD") ? row[at("LSAD")] : null,
|
|
76
|
+
functionalStatus: row[at("FUNCSTAT")],
|
|
77
|
+
latitude: Number(row[at("INTPTLAT")]),
|
|
78
|
+
longitude: Number(row[at("INTPTLONG")]),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=gazetteer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gazetteer.js","sourceRoot":"","sources":["../../sdk/gazetteer.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,kEAAkE;AAElE;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAA;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,WAAW,EAAwB,MAAM,SAAS,CAAA;AAE3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAEhD;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG;IAClC,KAAK,EAAE,OAAO;IACd,iBAAiB,EAAE,SAAS;CACnB,CAAA;AAgCV;;GAEG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,IAAI,CAAA;AAEpD,SAAS,iBAAiB,CAAC,IAAyB,EAAE,OAAe;IACpE,OAAO,GAAG,OAAO,QAAQ,IAAI,WAAW,CAAA;AACzC,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACzC,IAAyB,EACzB,OAAO,GAAqD,EAAE;IAE9D,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,gCAAgC,CAAA;IACnE,MAAM,SAAS,GAAG,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,IAAI,YAAY,EAAE,CAAC,CAAC,OAAO,EAAE,MAAM,CAAC,OA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