Expand description
Defines the FIPSCode types to represent FIPS geographic region codes (and “code fragments”) very efficiently.
§Encoding Scheme
A table of how FIPS Geo IDs are structured is provided in the module-level documentation for crate::parser
(slightly modified from
the source table in the standard).
The rows in the table up to and including Block (that is, all but the last five rows) form a linear order with
respect to prefix inclusion (“is prefix of”). This encoding scheme is for these codes. The last four rows are
treated separately.
In the following table, we describe the data “fragments” and their storage requirements.
| Decimal Digits | Actual Max Value | Bits | Capacity (2^bits - 1) | |
|---|---|---|---|---|
| Sate | 2 | 56 | 7 | 127 |
| County | 3 | 840 | 10 | 1,023 |
| Tract | 6 | 990,101 | 20 | 1,048,575 |
| Subtotal | 37 | Bits needed for tract code | ||
| Monotonically Increasing Id’s | ||||
| homeId | 4 | 9,999 | 14 | 16,383 |
| publicschoolId | 3 | 999 | 10 | 1,023 |
| privateschoolId | 4 | 1,722 | 11 | 2,047 |
| workplaceId | 5 | 14,938 | 14 | 16,383 |
| Max: | 14 | |||
| Total: | 51 |
State codes for states have values <= 56, but there are “state codes” for outlying areas, some historic codes, and maritime extension codes in use in the wild. We therefore use an extra bit than strictly required to represent it. To the 51 bits apparently required to store this data we add an additional 4 bits for a category tag to distinguish between home, public school, private school, workplace, and cencus tract, a field useful for representing ASPR synthetic population data, for example. Only 2 bits are required to distinguish these 4 categories, so the additional 2 bits are left unused / for future use.
We encode this data into a u64 as follows:
| Data | State | County | Tract | Category Tag | Monotonically increasing ID number | Reserved / Unused |
|---|---|---|---|---|---|---|
| Bits | 63…57 | 57…47 | 46…27 | 26…23 | 22…9 | 8…0 |
| Ex. Value | AK, AZ, … | 258 | 223,100 | Home, Work, … | 12,345 | 0 |
| Bit Count | 7 | 10 | 20 | 4 | 14 | 9 |
| Capacity | 128 | 1,024 | 1,048,576 | 16 | 16,384 | 512 |
| Decimal Digits | 2 | 3 | 6 | - | 3 to 5 | - |
| Max Observed Value | 56 | 840 | 990,101 | 4 | 14,938 | - |
Observe that:
- We give the “category tag” 4 bits to allow up to 16 distinct categories. In some applications this field might be unused.
- The least significant 9 bits is completely unused by this encoding. It may be used for application-specific storage.
- The field for ID number only requires 10 bits for
publicschoolId, for example. That is, the storage it requires depends on the category tag. - The category tag is encoded after the tract code but before the ID field so that numerical ordering coincides with the hierarchical ordering.
- Likewise, the unused 9 bits are the least significant bits so that numerical ordering coincides with the hierarchical ordering modulo those bits.
§Nonhierarchical FIPS Codes
The encoding of the previous section excludes the nonhierarchical codes of the last five rows from the first table above:
- Places
- Congressional District (113th Congress)
- State Legislative District (Upper Chamber)
- State Legislative District (Lower Chamber)
- ZCTA
We could easily accommodate these codes as well in a variety of ways, e.g.:
- assign each of these a category tag and store their corresponding code fragments in the ID field
- use the 14 bits of the ID field and the unused 10 least significant bits, allowing the category tag to remain orthogonal
We leave them unspecified until we have a use case for them.
Structs§
- ExpandedFIPS
Code - A struct that holds an expanded version of a
FIPSCodein which all fields are represented by their associated numeric types. - FIPS
Code - Encodes a hierarchical FIPS geographic region code in 64 bits. Excludes the nonhierarchical codes places, congressional or state legislative districts, and ZIP code tabulation areas. (See the module level documentation.)