pytidycensus.geography
Geographic boundary data retrieval and processing using pygris.
Functions
|
Get block group boundaries for a state, optionally filtered by county. |
|
Get US county boundaries, optionally filtered by state. |
|
Download and load geographic boundary data using pygris. |
|
Get US state boundaries. |
|
Get census tract boundaries for a state, optionally filtered by county. |
- pytidycensus.geography.get_geography(geography, year=2022, state=None, county=None, keep_geo_vars=False, cache_dir=None, cb=True, **kwargs)[source]
Download and load geographic boundary data using pygris.
- Parameters:
geography (str) – Geography type (e.g., ‘county’, ‘tract’, ‘block group’, ‘state’, ‘zcta’, ‘place’)
year (int, default 2022) – Census year for boundaries
state (str, int, or list, optional) – State(s) to filter data for. Can be state name, abbreviation, or FIPS code.
county (str, int, or list, optional) – County(ies) to filter data for (requires state). Can be county name or FIPS code.
keep_geo_vars (bool, default False) – Whether to keep all geographic variables
cache_dir (str, optional) – Directory for caching downloaded files (currently not used with pygris)
cb (bool, default True) – If True, download generalized cartographic boundary files (1:500k). If False, download detailed TIGER/Line files. Note: For 2020 state-level data, cartographic boundaries may fail due to Census Bureau access restrictions. The function will automatically fall back to detailed TIGER/Line files (cb=False) if this occurs.
**kwargs – Additional parameters passed to underlying pygris functions
- Returns:
Geographic boundary data
- Return type:
Notes
Automatic Fallback: If downloading cartographic boundary files (cb=True) fails with file system errors (common for 2020 state-level GENZ files), the function will automatically retry with detailed TIGER/Line files (cb=False) and issue a warning. This ensures robust data retrieval without requiring manual intervention.
Examples
>>> # Get county boundaries for Texas >>> tx_counties = get_geography("county", state="TX", year=2022) >>> >>> # Get tract boundaries for Harris County, TX >>> harris_tracts = get_geography( ... "tract", ... state="TX", ... county="201", ... year=2022 ... ) >>> >>> # Get 2020 state boundaries (will auto-fallback if needed) >>> states_2020 = get_geography("state", year=2020)
- pytidycensus.geography.get_state_boundaries(year=2022, cb=True, **kwargs)[source]
Get US state boundaries.
- Parameters:
- Returns:
State boundaries
- Return type:
- pytidycensus.geography.get_county_boundaries(state=None, year=2022, cb=True, **kwargs)[source]
Get US county boundaries, optionally filtered by state.
- Parameters:
- Returns:
County boundaries
- Return type:
- pytidycensus.geography.get_tract_boundaries(state, county=None, year=2022, cb=True, **kwargs)[source]
Get census tract boundaries for a state, optionally filtered by county.
- Parameters:
- Returns:
Tract boundaries
- Return type: