Skip to content

transitlos.population

Join an access-score GeoDataFrame with population data.

Composition decision (read before changing this file): access_gdf is street-edge (line) geometry, while population sources are polygon (US Census ACS/DHC tract/blockgroup) or raster (WorldPop) geometry. Rather than rasterizing the edges to H3 first, this module treats the population source as the target polygon level and aggregates access_gdf's level_of_service (and any other requested edge columns) onto it via geohierarchy.edges_to_level -- this is the same composition UrbanAccessAnalyzer.api.AccessibilityAnalyzer.to_level/.to_h3 already use internally, just with the population source's own polygons as level_gdf instead of an H3 grid or admin boundary layer supplied by the caller. This keeps population counts exactly as reported by the source (no raster resampling error from forcing them onto an edge-derived grid) and produces one row per population polygon with both a population and an aggregated level_of_service column, ready for equity.equity_statistics.

For WorldPop (population_source="worldpop"), which ships a raster rather than a polygon layer, the raster is first vectorized into a per-pixel polygon grid (_worldpop_raster_to_gdf) so the same edges_to_level call can be reused. This is O(n_pixels) in memory, so pass a coarse resolution ("1km" is the WorldPop default probed here) for large AOIs.

cross_with_population(access_gdf, population_source='worldpop', aoi=None, region_for_census=None, id_col='edge_id', access_columns=None, census_level='tract', census_dataset='acs', worldpop_date=None, worldpop_resolution='1km', worldpop_folder=None, **kwargs)

Combine access_gdf (street edges with an level_of_service column) with population data.

Parameters:

Name Type Description Default
access_gdf GeoDataFrame

Street-edges GeoDataFrame with an level_of_service column (e.g. from transitlos.level_of_service.compute_level_of_service).

required
population_source str

"worldpop" (global gridded population, any country) or "us_census" (pycensus.census.countries.usa.acs5/.dhc, US only).

'worldpop'
aoi Optional[GeoDataFrame]

Area of interest, required for "worldpop" (used to download the raster) and used as a fallback to derive us_census's states if region_for_census is not given.

None
region_for_census Optional[Union[str, list]]

For "us_census": state name(s)/abbreviation(s)/ FIPS code(s) forwarded to pycensus.census.countries.usa.acs5.load/.dhc.load as states. If None, derived from aoi.

None
id_col str

Name to give the population polygon's unique-id column in the returned GeoDataFrame (GEOID for us_census is renamed to this; a synthetic pixel index is used for worldpop).

'edge_id'
access_columns Optional[list]

Edge columns from access_gdf to aggregate onto the population polygons. Defaults to ["level_of_service"].

None
census_level str

Geometry level forwarded to pycensus.census.countries.usa.acs5.load/ .dhc.load (only used when population_source="us_census").

'tract'
census_dataset str

"acs" or "dhc" -- which pycensus.usa submodule to use for "us_census".

'acs'
worldpop_date

Year (or date/datetime) forwarded to download_worldpop_population; required for "worldpop".

None
worldpop_resolution str

"100m" or "1km", forwarded to download_worldpop_population. "1km" is the safer default to keep the pixel-grid vectorization tractable.

'1km'
worldpop_folder Optional[str]

Download destination forwarded to download_worldpop_population.

None
**kwargs

Extra keyword arguments forwarded to the underlying pycensus loader.

{}

Returns:

Type Description
GeoDataFrame

GeoDataFrame with one row per population polygon: id_col,

GeoDataFrame

geometry, population, and the aggregated access_columns.

Raises:

Type Description
ValueError

If population_source is not "worldpop"/"us_census", or a required argument for the chosen source is missing.