transitlos.map¶
Lightweight, tile-based folium map builder -- reusable across any transitLOS study.
build_city_map is column-agnostic: every field it renders (the score
column, circle-size/opacity candidate fields, census-level GeoDataFrames,
stats-panel data) is supplied by the caller, not hardcoded to any specific
study's schema (e.g. a particular census provider's column names). A study
with a different set of census columns, a different scoring column name, or
no census data at all works without changing this package -- only the
caller's own column lists change.
build_city_map(h3_by_resolution, edges_gdf, tiles_dir, out_html, score_col='level_of_service', street_min_zoom=14, census_by_level=None, circle_fields=None, opacity_fields=None, stats_by_area=None, is_us=False, stops_chunks=None, routes_chunks=None, stops_gdf=None, routes_gdf=None, region='global', skip_tile_build=False, external_tile_writers=None, force_development_tiles=False, force_census_tiles=False, stats_scope_cfg=None, development_gdf=None, use_pmtiles=True, renderer='maplibre', enable_place_comparison=False, downloads_manifest=None, share_source_map=None, country=None, special_levels=None, special_level_labels=None, include_streets=True, include_development=True)
¶
Build and save one city's transit-LOS map (include_streets / include_development = False: no street / development layer).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
h3_by_resolution
|
Dict[int, GeoDataFrame]
|
Mapping of H3 resolution -> GeoDataFrame (h3
polygon geometry + |
required |
edges_gdf
|
GeoDataFrame
|
Street-edges GeoDataFrame with |
required |
tiles_dir
|
str
|
Directory vector tiles are written to. |
required |
out_html
|
str
|
Output map HTML path. |
required |
score_col
|
str
|
Column name colored (red-yellow-green) on every level. |
'level_of_service'
|
street_min_zoom
|
int
|
Minimum zoom streets become visible at. |
14
|
census_by_level
|
Optional[Dict[str, GeoDataFrame]]
|
Optional mapping of census level name -> GeoDataFrame
with the same geometry/score/field conventions as
|
None
|
circle_fields
|
Optional[List[str]]
|
Numeric columns selectable in the "Circle size by" dropdown. Defaults to every numeric, non-identifier column found on the finest H3 resolution's GeoDataFrame. |
None
|
opacity_fields
|
Optional[List[str]]
|
Numeric columns selectable in the "Opacity by"
dropdown (affects hexagons/circles/census, never streets).
Defaults to the same list as |
None
|
stats_by_area
|
Optional[Dict[str, GeoDataFrame]]
|
Optional |
None
|
is_us
|
bool
|
Whether |
False
|
development_gdf
|
Optional[GeoDataFrame]
|
Optional polygon GeoDataFrame (e.g. census block
groups) with an |
None
|
stops_gdf
|
Optional[GeoDataFrame]
|
Optional stop-level GeoDataFrame (point geometry) with a
|
None
|
routes_gdf
|
Optional[GeoDataFrame]
|
Optional route-level GeoDataFrame -- one Line/
MultiLineString feature per route -- as produced by
|
None
|
region
|
str
|
|
'global'
|
external_tile_writers
|
Optional[Dict[tuple, Any]]
|
Optional |
None
|
skip_tile_build
|
bool
|
If True, skip regenerating vector tiles entirely
and reuse whatever already exists on disk under |
False
|
enable_place_comparison
|
bool
|
Whether the stats panel's "Place rank" tab
(cross-city, population-weighted median level_of_service, ranked
across the |
False
|
use_pmtiles
|
bool
|
If True (default), generate and use PMTiles (.pmtiles) format for vector tiles. PMTiles are single-file archives that are faster to generate and easier to host. If False, use legacy XYZ PBF directory structure for backward compatibility. |
True
|
renderer
|
str
|
"maplibre" (default) or "folium". MapLibre reads the
.pmtiles written by the tile build directly -- no XYZ/pbf
extraction step -- and gives fast base-layer parity (per-level
coloring, popups, hover, layer switcher) but NOT the scenario
editor or stats panel. Pass "folium" to get the full
Leaflet-based editor (route drawing, grade-separation paint,
live recolor, Distribution/Regression/ANOVA tabs) -- Folium's
editor still requires XYZ PBF tiles internally (extracted from
the same .pmtiles by |
'maplibre'
|
Returns:
| Type | Description |
|---|---|
str
|
Absolute path to the saved HTML file. |
Note
HierarchyMap embeds tiles_dir verbatim into the browser-side
Leaflet tile URL, so an absolute filesystem path would produce a
map.html that only loads correctly if a web server happened to be
rooted at /. tiles_dir is converted to a path relative to
out_html's directory, and tile-writing is done with the working
directory temporarily switched to that same directory so on-disk
tiles land exactly where the relative URL expects them.
build_download_panel_block(manifest_json, base_path='results', place_options=None)
¶
Shared HTML+JS for the "Download data" panel.
Used by both _inject_maplibre_download_panel_into_saved_html (one
city's own map, place_options=None) and combined_map.py (which
passes place_options -- one {value, label, base_path} per city --
to add the place dropdown described in the task; base_path there is
each city's own relative path from the combined map's HTML location,
e.g. "../beerseba/results", since the combined map has no downloads
of its own to point at).
manifest_json is a JSON object (baked in, same pattern as
_stats_json_data) shaped:
{"scopes": ["metro","core"], "h3_resolutions": [5,7,9,11],
"census_levels": ["county","tract",...], "has_stops": true,
"has_routes": true}
For the combined map, manifest_json is instead a JSON mapping of
place value -> that same per-place object (window.__downloadManifests),
since different cities can have different resolutions/levels/census
availability.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
manifest_json
|
str
|
JSON of what can be downloaded (see above). |
required |
base_path
|
str
|
Relative path of the results folder. |
'results'
|
place_options
|
Optional[List[dict]]
|
Optional |
None
|
Returns:
| Type | Description |
|---|---|
str
|
HTML and script of the panel. |
build_place_rank_panel_block(place_manifest, weight_columns=(), fetch_prefix='')
¶
The bottom-left 📊 stats popup, reduced to ONLY its "Place rank" tab.
Public entry point for a caller with no per-place stats_by_area
GeoDataFrame of its own -- concretely, CS_transitLOS/code/combined_map.py
(a lightweight page generator with no geopandas/per-h3-cell data,
assembling a page that iframes other already-built city map.htmls
rather than owning any map data itself). It reuses the exact same
_stats_panel_html/_stats_panel_js a real per-city build_city_map
call uses for its own "Place rank" tab -- one implementation, two
call sites -- with the other four tabs (Distribution/Regression/ANOVA/
Discretization) omitted entirely via place_rank_only=True, since this
caller has no per-place h3 data to feed them.
place_manifest: [{"key": ..., "label": ...}, ...] -- the live roster
(e.g. from combined_map.py's own _available_cities()), NOT this
module's hand-maintained _DEFAULT_CS_PLACE_MANIFEST fallback.
weight_columns: candidate weight-column keys for the tab's own
weight-column
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
place_manifest
|
List[Dict[str, str]]
|
|
required |
weight_columns
|
Sequence[str]
|
Candidate weight columns. |
()
|
fetch_prefix
|
str
|
Prefix of the |
''
|
Returns:
| Type | Description |
|---|---|
str
|
HTML and script of the panel. |
build_route_lines(gtfs_dirs, aoi=None, exclude_no_shape_routes=True)
¶
Build one line feature per GTFS route_id across one or more feeds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gtfs_dirs
|
Union[str, Path, Iterable[Union[str, Path]]]
|
A GTFS directory, or an iterable of them (one per feed). Zipped feeds are not handled here -- pass extracted directories. |
required |
aoi
|
Optional[GeoDataFrame]
|
Optional area of interest (any CRS); routes whose geometry does not intersect its union are dropped, so a metro-scale map isn't carrying intercity coach routes running hundreds of km away. |
None
|
exclude_no_shape_routes
|
bool
|
2026-09-01, user-requested default: a route
with no real |
True
|
Returns:
| Type | Description |
|---|---|
GeoDataFrame
|
A WGS84 GeoDataFrame with one row per |
GeoDataFrame
|
|
GeoDataFrame
|
|
GeoDataFrame
|
|
GeoDataFrame
|
( |
GeoDataFrame
|
(GTFS |
GeoDataFrame
|
(GTFS |
GeoDataFrame
|
of the route's trips had real |
GeoDataFrame
|
every trip fell back to the straight-line stop-sequence |
GeoDataFrame
|
connect-the-dots geometry), plus LineString/MultiLineString |
GeoDataFrame
|
|