Skip to content

UrbanAccessAnalyzer.grading

Grade street accessibility to several types of points of interest (POIs).

Each POI type is described by a small config dict::

{
    "name": "groceries",           # label, also the output column name
    "query": osm_io.groceries,     # callable(bounds) -> POI table, see osm_io
    "geometry": "Point",           # "Point" or "Polygon" (e.g. parks)
    "importance": 8,               # relative weight in the final score
    "max_distance": 1500,          # meters walked beyond which the POI is worthless
    "icon": "🛒",                  # optional emoji shown on the maps
}

query can be an OSM query (:mod:UrbanAccessAnalyzer.osm_io, :func:UrbanAccessAnalyzer.osm_io.tag_query) or your own file (:func:query_from_file).

Grading, per POI type:

  1. Distances max_distance * j / n_steps (j = 1..n_steps) are the walk-distance tiers; the score of a street node is 100 * (n_steps - j + 1) / n_steps for the closest tier it falls in (so 100 right next to a POI and 100 / n_steps at max_distance), and 0 beyond max_distance.
  2. Point POIs are snapped onto the street network. Polygon POIs (parks) enter the network wherever their boundary touches a street, and every node inside the polygon scores 100.

The final score of a node is the importance-weighted mean of its per-type scores; an edge takes the mean of its two end nodes.

query_from_file(path, name_column=None)

Build a POI query from your own vector file (points or polygons).

Any format GeoPandas reads works: GeoPackage, GeoJSON, Shapefile, GeoParquet, FlatGeobuf, ... in any CRS. Only the features inside the download area are kept.

Parameters:

Name Type Description Default
path str

Path to the file.

required
name_column Optional[str]

Column with the POI names (shown on the maps), if any.

None

Returns:

Type Description
Callable

A function query(bounds) to use as the "query" of a POI config.

fetch_pois(specs, bounds, crs, max_retries=3, retry_wait=5.0)

Run every config's query over bounds and return one GeoDataFrame per POI type.

Parameters:

Name Type Description Default
specs Sequence[dict]

POI configs (see module docstring).

required
bounds GeoDataFrame

Download area.

required
crs

CRS to project the results to (normally network.crs).

required
max_retries int

Attempts per query (public Overpass servers are often busy).

3
retry_wait float

Seconds between attempts.

5.0

Returns:

Type Description
dict[str, GeoDataFrame]

{name: GeoDataFrame}. Point configs are collapsed to one point

dict[str, GeoDataFrame]

per feature; Polygon configs keep their polygons. A type whose

dict[str, GeoDataFrame]

query fails or returns nothing maps to an empty GeoDataFrame.

grade(network, specs, pois, n_steps=5, max_snap_dist=150.0, min_edge_length=30.0, score_col='access_score')

Grade every street edge by its walk distance to each POI type, then combine.

Parameters:

Name Type Description Default
network StreetNetwork

Street network (projected CRS, meters).

required
specs Sequence[dict]

POI configs (see module docstring).

required
pois dict[str, GeoDataFrame]

Output of :func:fetch_pois, in network.crs.

required
n_steps int

Number of distance tiers per POI type.

5
max_snap_dist Optional[float]

Max distance (m) from a POI to the nearest street.

150.0
min_edge_length float

Minimum edge length (m) created when snapping POIs.

30.0
score_col str

Name of the combined 0-100 score column.

'access_score'

Returns:

Type Description
GeoDataFrame

(edges_gdf, snapped_network). edges_gdf has one row per street

StreetNetwork

edge with one 0-100 column per POI type (named name) plus the

tuple[GeoDataFrame, StreetNetwork]

importance-weighted score_col.

poi_table(specs, pois)

One EPSG:4326 table of all POIs for mapping, with columns type, name, icon.

icon is the config's optional "icon" emoji (default "📍"), which :func:UrbanAccessAnalyzer.plotting.general_map draws on each POI (poi_column="type", poi_icon_column="icon").

Parameters:

Name Type Description Default
specs Sequence[dict]

The POI configs (each with name and optional icon).

required
pois dict[str, GeoDataFrame]

{config name: POI GeoDataFrame}.

required

Returns:

Type Description
GeoDataFrame

One GeoDataFrame in EPSG:4326 with type, name, icon and geometry.