Skip to main content

Module fips_code

Module fips_code 

Source
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 DigitsActual Max ValueBitsCapacity (2^bits - 1)
Sate2567127
County3840101,023
Tract6990,101201,048,575
Subtotal37Bits needed for tract code
Monotonically Increasing Id’s
homeId49,9991416,383
publicschoolId3999101,023
privateschoolId41,722112,047
workplaceId514,9381416,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:

DataStateCountyTractCategory TagMonotonically increasing ID numberReserved / Unused
Bits63…5757…4746…2726…2322…98…0
Ex. ValueAK, AZ, …258223,100Home, Work, …12,3450
Bit Count710204149
Capacity1281,0241,048,5761616,384512
Decimal Digits236-3 to 5-
Max Observed Value56840990,101414,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§

ExpandedFIPSCode
A struct that holds an expanded version of a FIPSCode in which all fields are represented by their associated numeric types.
FIPSCode
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.)