@mailwoman/tiger 1.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.
Files changed (103) hide show
  1. package/README.md +3 -0
  2. package/block-group.ts +151 -0
  3. package/class-code.ts +1026 -0
  4. package/constants.ts +252 -0
  5. package/county-subdivision.ts +154 -0
  6. package/county.ts +135 -0
  7. package/files.ts +251 -0
  8. package/functional-status.ts +64 -0
  9. package/geoid.ts +678 -0
  10. package/index.ts +18 -0
  11. package/legal-statistical-area.ts +222 -0
  12. package/out/block-group.d.ts +135 -0
  13. package/out/block-group.d.ts.map +1 -0
  14. package/out/block-group.js +7 -0
  15. package/out/block-group.js.map +1 -0
  16. package/out/class-code.d.ts +863 -0
  17. package/out/class-code.d.ts.map +1 -0
  18. package/out/class-code.js +864 -0
  19. package/out/class-code.js.map +1 -0
  20. package/out/constants.d.ts +220 -0
  21. package/out/constants.d.ts.map +1 -0
  22. package/out/constants.js +98 -0
  23. package/out/constants.js.map +1 -0
  24. package/out/county-subdivision.d.ts +139 -0
  25. package/out/county-subdivision.d.ts.map +1 -0
  26. package/out/county-subdivision.js +7 -0
  27. package/out/county-subdivision.js.map +1 -0
  28. package/out/county.d.ts +120 -0
  29. package/out/county.d.ts.map +1 -0
  30. package/out/county.js +9 -0
  31. package/out/county.js.map +1 -0
  32. package/out/files.d.ts +118 -0
  33. package/out/files.d.ts.map +1 -0
  34. package/out/files.js +142 -0
  35. package/out/files.js.map +1 -0
  36. package/out/functional-status.d.ts +64 -0
  37. package/out/functional-status.d.ts.map +1 -0
  38. package/out/functional-status.js +65 -0
  39. package/out/functional-status.js.map +1 -0
  40. package/out/geoid.d.ts +438 -0
  41. package/out/geoid.d.ts.map +1 -0
  42. package/out/geoid.js +255 -0
  43. package/out/geoid.js.map +1 -0
  44. package/out/index.d.ts +18 -0
  45. package/out/index.d.ts.map +1 -0
  46. package/out/index.js +18 -0
  47. package/out/index.js.map +1 -0
  48. package/out/legal-statistical-area.d.ts +222 -0
  49. package/out/legal-statistical-area.d.ts.map +1 -0
  50. package/out/legal-statistical-area.js +223 -0
  51. package/out/legal-statistical-area.js.map +1 -0
  52. package/out/sdk/fetch.d.ts.map +1 -0
  53. package/out/sdk/fetch.js.map +1 -0
  54. package/out/sdk/index.d.ts +7 -0
  55. package/out/sdk/index.d.ts.map +1 -0
  56. package/out/sdk/index.js +7 -0
  57. package/out/sdk/index.js.map +1 -0
  58. package/out/sdk/redistricting.d.ts.map +1 -0
  59. package/out/sdk/redistricting.js.map +1 -0
  60. package/out/sdk/schema.d.ts.map +1 -0
  61. package/out/sdk/schema.js.map +1 -0
  62. package/out/sdk/state/TIGERTabulatedBlockEntity.d.ts +13 -0
  63. package/out/sdk/state/TIGERTabulatedBlockEntity.d.ts.map +1 -0
  64. package/out/sdk/state/TIGERTabulatedBlockEntity.js +22 -0
  65. package/out/sdk/state/TIGERTabulatedBlockEntity.js.map +1 -0
  66. package/out/sdk/state/TIGERTractEntity.d.ts +31 -0
  67. package/out/sdk/state/TIGERTractEntity.d.ts.map +1 -0
  68. package/out/sdk/state/TIGERTractEntity.js +7 -0
  69. package/out/sdk/state/TIGERTractEntity.js.map +1 -0
  70. package/out/sdk/state/block-operations.d.ts +36 -0
  71. package/out/sdk/state/block-operations.d.ts.map +1 -0
  72. package/out/sdk/state/block-operations.js +37 -0
  73. package/out/sdk/state/block-operations.js.map +1 -0
  74. package/out/sdk/state/index.d.ts +9 -0
  75. package/out/sdk/state/index.d.ts.map +1 -0
  76. package/out/sdk/state/index.js +9 -0
  77. package/out/sdk/state/index.js.map +1 -0
  78. package/out/state.d.ts +595 -0
  79. package/out/state.d.ts.map +1 -0
  80. package/out/state.js +384 -0
  81. package/out/state.js.map +1 -0
  82. package/out/tabulation-block.d.ts +43 -0
  83. package/out/tabulation-block.d.ts.map +1 -0
  84. package/out/tabulation-block.js +9 -0
  85. package/out/tabulation-block.js.map +1 -0
  86. package/out/tract.d.ts +36 -0
  87. package/out/tract.d.ts.map +1 -0
  88. package/out/tract.js +8 -0
  89. package/out/tract.js.map +1 -0
  90. package/out/tsconfig.tsbuildinfo +1 -0
  91. package/package.json +41 -0
  92. package/sdk/data/nation/index.json +14642 -0
  93. package/sdk/index.ts +7 -0
  94. package/sdk/initialize.sql +161 -0
  95. package/sdk/state/TIGERTabulatedBlockEntity.ts +25 -0
  96. package/sdk/state/TIGERTractEntity.ts +34 -0
  97. package/sdk/state/block-operations.ts +69 -0
  98. package/sdk/state/index.ts +9 -0
  99. package/state.ts +553 -0
  100. package/tabulation-block.ts +68 -0
  101. package/tract.ts +52 -0
  102. package/tsconfig.json +16 -0
  103. package/typedoc.json +5 -0
package/sdk/index.ts ADDED
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @copyright Sister Software.
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ */
6
+
7
+ export * from "./state/index.js"
@@ -0,0 +1,161 @@
1
+ -- @copyright Sister Software.
2
+ -- @license AGPL-3.0
3
+ -- @author Teffen Ellis, et al.
4
+ -- @file TIGER SQLite3 Database Initialization Script
5
+
6
+ PRAGMA auto_vacuum = FULL;
7
+ PRAGMA synchronous = FULL;
8
+ PRAGMA locking_mode = EXCLUSIVE;
9
+ PRAGMA page_size = 4096;
10
+ PRAGMA cache_size = 10000;
11
+
12
+ SELECT load_extension('/opt/homebrew/opt/libspatialite/lib/mod_spatialite.dylib');
13
+ SELECT InitSpatialMetadata();
14
+
15
+ --#region US States
16
+
17
+ CREATE TABLE "us_state" (
18
+ "state_code" text(2) PRIMARY KEY NOT NULL,
19
+ "abbreviation" text NOT NULL,
20
+ "display_name" text NOT NULL
21
+ );
22
+
23
+ SELECT AddGeometryColumn('us_state', 'GEOM', 4326, 'MultiPolygon', 2, 1);
24
+ SELECT CreateSpatialIndex('us_state', 'GEOM');
25
+
26
+
27
+ CREATE UNIQUE INDEX "idx_us_state_code" ON "us_state" (
28
+ "state_code"
29
+ );
30
+
31
+ CREATE UNIQUE INDEX "idx_us_state_abbreviation" ON "us_state" (
32
+ "abbreviation"
33
+ );
34
+
35
+ CREATE UNIQUE INDEX "idx_us_state_display_name" ON "us_state" (
36
+ "display_name"
37
+ );
38
+
39
+ --#endregion
40
+
41
+ --#region Tracts
42
+
43
+ CREATE TABLE "tract" (
44
+ "GEOID" text(11) PRIMARY KEY NOT NULL,
45
+ "state_code" text(2) NOT NULL,
46
+ "county_code" text(3) NOT NULL,
47
+ "county_sub_division_code" text(5) NOT NULL,
48
+ "tract_code" text(6) NOT NULL
49
+ );
50
+
51
+ SELECT AddGeometryColumn('tract', 'GEOM', 4326, 'MultiPolygon', 2, 1);
52
+ SELECT CreateSpatialIndex('tract', 'GEOM');
53
+
54
+ --#endregion
55
+
56
+
57
+ --#region Tabulated Blocks
58
+
59
+ CREATE TABLE "tabblock20" (
60
+ "GEOID" text(15) PRIMARY KEY NOT NULL,
61
+ "state_code" text(2) NOT NULL,
62
+ "county_code" text(3) NOT NULL,
63
+ "county_sub_division_code" text(5) NOT NULL,
64
+ "tract_code" text(6) NOT NULL,
65
+ "block_group_code" text(1) NOT NULL,
66
+ "block_code" text(4) NOT NULL,
67
+ "urbanized_area_code" text(5),
68
+ "urban_rural_code" text(1),
69
+ "housing_unit_count" integer NOT NULL,
70
+ "land_area_sqm" integer NOT NULL,
71
+ "water_area_sqm" integer NOT NULL,
72
+ "population" integer NOT NULL
73
+ );
74
+
75
+ SELECT AddGeometryColumn('tabblock20', 'GEOM', 4326, 'MultiPolygon', 2, 1);
76
+ SELECT CreateSpatialIndex('tabblock20', 'GEOM');
77
+
78
+
79
+ CREATE UNIQUE INDEX "idx_tabblock20_geoid" ON "tabblock20" (
80
+ "GEOID"
81
+ );
82
+
83
+ CREATE INDEX "idx_tabblock20_state_code" ON "tabblock20" (
84
+ "state_code"
85
+ );
86
+
87
+ CREATE INDEX "idx_tabblock20_county_code" ON "tabblock20" (
88
+ "county_code"
89
+ );
90
+
91
+ CREATE INDEX "idx_tabblock20_county_sub_division_code" ON "tabblock20" (
92
+ "county_sub_division_code"
93
+ );
94
+
95
+ CREATE INDEX "idx_tabblock20_tract_code" ON "tabblock20" (
96
+ "tract_code"
97
+ );
98
+
99
+ CREATE INDEX "idx_tabblock20_block_group_code" ON "tabblock20" (
100
+ "block_group_code"
101
+ );
102
+
103
+ CREATE INDEX "idx_tabblock20_block_code" ON "tabblock20" (
104
+ "block_code"
105
+ );
106
+
107
+ CREATE INDEX "idx_tabblock20_urbanized_area_code" ON "tabblock20" (
108
+ "urbanized_area_code"
109
+ );
110
+
111
+ CREATE INDEX "idx_tabblock20_urban_rural_code" ON "tabblock20" (
112
+ "urban_rural_code"
113
+ );
114
+
115
+ CREATE INDEX "idx_tabblock20_housing_unit_count" ON "tabblock20" (
116
+ "housing_unit_count"
117
+ );
118
+
119
+ CREATE INDEX "idx_tabblock20_land_area_sqm" ON "tabblock20" (
120
+ "land_area_sqm"
121
+ );
122
+
123
+ CREATE INDEX "idx_tabblock20_water_area_sqm" ON "tabblock20" (
124
+ "water_area_sqm"
125
+ );
126
+
127
+ CREATE INDEX "idx_tabblock20_population" ON "tabblock20" (
128
+ "population"
129
+ );
130
+
131
+ CREATE INDEX "idx_tabblock20_state_code_county_code" ON "tabblock20" (
132
+ "state_code",
133
+ "county_code"
134
+ );
135
+
136
+ CREATE INDEX "idx_tabblock20_state_code_county_code_tract_code" ON "tabblock20" (
137
+ "state_code",
138
+ "county_code",
139
+ "tract_code"
140
+ );
141
+
142
+ CREATE INDEX "idx_tabblock20_state_code_county_code_tract_code_block_group_code" ON "tabblock20" (
143
+ "state_code",
144
+ "county_code",
145
+ "tract_code",
146
+ "block_group_code"
147
+ );
148
+
149
+ CREATE INDEX "idx_tabblock20_state_code_county_code_tract_code_block_group_code_block_code" ON "tabblock20" (
150
+ "state_code",
151
+ "county_code",
152
+ "tract_code",
153
+ "block_group_code",
154
+ "block_code"
155
+ );
156
+
157
+ --#endregion
158
+
159
+
160
+
161
+
@@ -0,0 +1,25 @@
1
+ /**
2
+ * @copyright Sister Software.
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ */
6
+
7
+ import { smartSnakeCase } from "@mailwoman/core"
8
+ import { TIGERProperty } from "@mailwoman/tiger"
9
+
10
+ /**
11
+ * Default column selections for TIGER tabulated block entities.
12
+ *
13
+ * @internal
14
+ */
15
+ export const TIGERTabulatedBlockEntitySelections = (
16
+ [
17
+ TIGERProperty.GeoID,
18
+ TIGERProperty.UrbanizedAreaCode,
19
+ TIGERProperty.UrbanRuralCode,
20
+ TIGERProperty.HousingUnitCount,
21
+ TIGERProperty.LandAreaSqm,
22
+ TIGERProperty.WaterAreaSqm,
23
+ TIGERProperty.Population,
24
+ ] as const
25
+ ).map((columnName) => smartSnakeCase(columnName))
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @copyright Sister Software.
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ */
6
+
7
+ import { AdminLevel1Code, type FIPSCountyCode, type FIPSTractCode } from "@mailwoman/tiger"
8
+
9
+ /**
10
+ * @internal
11
+ */
12
+ export interface TIGERTractShapeAttributes {
13
+ /**
14
+ * @title State FIPS Code
15
+ */
16
+ STATEFP: AdminLevel1Code
17
+
18
+ /**
19
+ * @title County FIPS Code
20
+ * @minLength 3
21
+ * @maxLength 3
22
+ * @pattern ^\d{3}$
23
+ */
24
+ COUNTYFP: FIPSCountyCode
25
+
26
+ /**
27
+ * @title Tract FIPS Code
28
+ *
29
+ * @minLength 6
30
+ * @maxLength 6
31
+ * @pattern ^\d{6}$
32
+ */
33
+ TRACTCE: FIPSTractCode
34
+ }
@@ -0,0 +1,69 @@
1
+ /**
2
+ * @copyright Sister Software.
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ */
6
+
7
+ import type { GeometryLiteral, MultiPolygonLiteral } from "@mailwoman/spatial"
8
+ import { wellKnownGeometryToGeoJSON } from "@mailwoman/spatial/sdk"
9
+ import {
10
+ FIPSStateCode,
11
+ type FIPSBlockGeoID,
12
+ type FIPSTractCode,
13
+ type TIGERBlockFeature,
14
+ type TIGERBlockFeatureCollection,
15
+ type TIGERTabulatedBlockProperties,
16
+ } from "@mailwoman/tiger"
17
+
18
+ export interface StateBlockIntersectionCriteria {
19
+ stateCode: FIPSStateCode
20
+ geometry: GeometryLiteral
21
+ tractCodes?: FIPSTractCode[]
22
+ }
23
+
24
+ //#region Row parsing
25
+
26
+ /**
27
+ * @internal
28
+ */
29
+ export interface TIGERBlockRow extends TIGERTabulatedBlockProperties {
30
+ GEOID: FIPSBlockGeoID
31
+ /**
32
+ * @format hex
33
+ */
34
+ serializedGeometry: string
35
+ }
36
+
37
+ /**
38
+ * Given a row from the TIGER tabulated block table, parses it into a GeoJSON feature.
39
+ *
40
+ * @internal
41
+ */
42
+ export function parseTIGERBlockFromRow({ serializedGeometry, ...properties }: TIGERBlockRow): TIGERBlockFeature {
43
+ const feature: TIGERBlockFeature = {
44
+ type: "Feature",
45
+ id: properties.GEOID,
46
+ geometry: wellKnownGeometryToGeoJSON<MultiPolygonLiteral>(Buffer.from(serializedGeometry, "hex")),
47
+ properties,
48
+ }
49
+
50
+ return feature
51
+ }
52
+
53
+ /**
54
+ * Given a collection of rows from the TIGER tabulated block table, parses them into a GeoJSON
55
+ * feature collection.
56
+ *
57
+ * @internal
58
+ */
59
+ export function parseTIGERBlockFeatureCollectionFromRows(rows: TIGERBlockRow[]): TIGERBlockFeatureCollection {
60
+ const features = rows.map(parseTIGERBlockFromRow)
61
+ const featureCollection: TIGERBlockFeatureCollection = {
62
+ type: "FeatureCollection",
63
+ features,
64
+ }
65
+
66
+ return featureCollection
67
+ }
68
+
69
+ //#endregion
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @copyright Sister Software.
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ */
6
+
7
+ export * from "./block-operations.js"
8
+ export * from "./TIGERTabulatedBlockEntity.js"
9
+ export * from "./TIGERTractEntity.js"