mainegeo.entities
1from dataclasses import dataclass 2from enum import Enum 3from mainegeo.lookups import CountyData 4 5class TownType(Enum): 6 """ 7 Enumeration of geography types used in `mainegeo.matching.TownReference` objects. 8 """ 9 TOWN = "Town" 10 CITY = "City" 11 PLANTATION = "Plantation" 12 RESERVATION = "Reservation" 13 UNORGANIZED = "Unorganized Township" 14 ISLAND = "Island Group" 15 16@dataclass(frozen=True) 17class Cousub: 18 """ 19 An object representing a U.S. Census Bureau county subdivision (`COUSUB`_). 20 21 Args: 22 geocode: The ten-digit Census code (state FIPS + county FIPS + county subdivision GEOID) 23 name: Census full name for county subdivision (basename + geoclass) 24 basename: Census base name for county subdivision 25 geoclass: Census `CLASSFP`_ code 26 27 .. _COUSUB: https://www.census.gov/library/reference/code-lists/ansi.html#cousub 28 .. _CLASSFP: https://www.census.gov/library/reference/code-lists/class-codes.html 29 """ 30 geocode: str|int = None 31 name: str = None 32 basename: str = None 33 geoclass: str = None 34 35@dataclass 36class County: 37 """ 38 An object representing a county. 39 40 Args: 41 name: Full name of the county 42 code: First three letters of the county name (commonly used by SoS) 43 fips: String or integer FIPS code (used by Census) 44 45 Can be initiated with any argument. If not all arguments are provided, 46 the others will be populated from a lookup table. 47 """ 48 name: str = None 49 code: str = None 50 fips: str|int = None 51 52 def __post_init__(self): 53 if self.fips: 54 self.fips = int(self.fips) 55 56 if not all((self.name, self.code, self.fips)): 57 lookup = CountyData.get_lookup() 58 fips = self.fips 59 code = self.code 60 name = self.name 61 self.fips = fips or lookup.code_to_fips.get(code) or lookup.name_to_fips.get(name) 62 self.code = code or lookup.fips_to_code.get(fips) or lookup.name_to_code.get(name) 63 self.name = name or lookup.fips_to_name.get(fips) or lookup.code_to_name.get(code) 64 65 def __hash__(self): 66 return hash(self.fips)
class
TownType(enum.Enum):
6class TownType(Enum): 7 """ 8 Enumeration of geography types used in `mainegeo.matching.TownReference` objects. 9 """ 10 TOWN = "Town" 11 CITY = "City" 12 PLANTATION = "Plantation" 13 RESERVATION = "Reservation" 14 UNORGANIZED = "Unorganized Township" 15 ISLAND = "Island Group"
Enumeration of geography types used in mainegeo.matching.TownReference objects.
TOWN =
<TownType.TOWN: 'Town'>
CITY =
<TownType.CITY: 'City'>
PLANTATION =
<TownType.PLANTATION: 'Plantation'>
RESERVATION =
<TownType.RESERVATION: 'Reservation'>
UNORGANIZED =
<TownType.UNORGANIZED: 'Unorganized Township'>
ISLAND =
<TownType.ISLAND: 'Island Group'>
@dataclass(frozen=True)
class
Cousub:
17@dataclass(frozen=True) 18class Cousub: 19 """ 20 An object representing a U.S. Census Bureau county subdivision (`COUSUB`_). 21 22 Args: 23 geocode: The ten-digit Census code (state FIPS + county FIPS + county subdivision GEOID) 24 name: Census full name for county subdivision (basename + geoclass) 25 basename: Census base name for county subdivision 26 geoclass: Census `CLASSFP`_ code 27 28 .. _COUSUB: https://www.census.gov/library/reference/code-lists/ansi.html#cousub 29 .. _CLASSFP: https://www.census.gov/library/reference/code-lists/class-codes.html 30 """ 31 geocode: str|int = None 32 name: str = None 33 basename: str = None 34 geoclass: str = None
An object representing a U.S. Census Bureau county subdivision (COUSUB).
Arguments:
- geocode: The ten-digit Census code (state FIPS + county FIPS + county subdivision GEOID)
- name: Census full name for county subdivision (basename + geoclass)
- basename: Census base name for county subdivision
- geoclass: Census CLASSFP code
@dataclass
class
County:
36@dataclass 37class County: 38 """ 39 An object representing a county. 40 41 Args: 42 name: Full name of the county 43 code: First three letters of the county name (commonly used by SoS) 44 fips: String or integer FIPS code (used by Census) 45 46 Can be initiated with any argument. If not all arguments are provided, 47 the others will be populated from a lookup table. 48 """ 49 name: str = None 50 code: str = None 51 fips: str|int = None 52 53 def __post_init__(self): 54 if self.fips: 55 self.fips = int(self.fips) 56 57 if not all((self.name, self.code, self.fips)): 58 lookup = CountyData.get_lookup() 59 fips = self.fips 60 code = self.code 61 name = self.name 62 self.fips = fips or lookup.code_to_fips.get(code) or lookup.name_to_fips.get(name) 63 self.code = code or lookup.fips_to_code.get(fips) or lookup.name_to_code.get(name) 64 self.name = name or lookup.fips_to_name.get(fips) or lookup.code_to_name.get(code) 65 66 def __hash__(self): 67 return hash(self.fips)
An object representing a county.
Arguments:
- name: Full name of the county
- code: First three letters of the county name (commonly used by SoS)
- fips: String or integer FIPS code (used by Census)
Can be initiated with any argument. If not all arguments are provided, the others will be populated from a lookup table.