UrbanAccessAnalyzer¶
UrbanAccessAnalyzer: street networks from OpenStreetMap and access scores to points of interest.
The four main classes, used in this order:
- :class:
AreaOfInterest-- the study area (geocoded by name or read from a file); - :class:
StreetNetwork-- the walk / bike / drive network of that area, built from an.osm.pbffile; - :class:
PointsOfInterest-- schools, stops, shops... from OpenStreetMap or your own table, with a score; - :class:
AccessibilityAnalyzer-- how well each street, node or H3 cell reaches those points within given distances.
AreaOfInterest(gdf)
¶
A geographic area of interest, backing every other class's spatial extent.
Wrap an existing AOI GeoDataFrame.
Prefer :meth:from_name or :meth:from_file over calling this
directly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gdf
|
GeoDataFrame
|
AOI geometry, any CRS. |
required |
from_name(name, buffer=0.0)
classmethod
¶
Geocode a place name into an AOI via Nominatim.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Place name/query, e.g. |
required |
buffer
|
float
|
Optional buffer (meters, applied in local UTM) around the geocoded geometry. |
0.0
|
Returns:
| Type | Description |
|---|---|
'AreaOfInterest'
|
A new :class: |
from_file(path, bounds=None)
classmethod
¶
Load an AOI from any vector file format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
File path (see
:func: |
required |
bounds
|
Optional bbox filter. |
None
|
Returns:
| Type | Description |
|---|---|
'AreaOfInterest'
|
A new :class: |
plot(m=None, **kwargs)
¶
Draw this AOI's outline on a Folium map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
m
|
Existing |
None
|
|
**kwargs
|
Passed through to
:func: |
{}
|
Returns:
| Type | Description |
|---|---|
|
The |
StreetNetwork(nodes, edges, crs)
¶
A street network for routing, backed by Polars node/edge tables.
Internally just two Polars DataFrames (nodes, edges) in a
projected metric CRS -- see :mod:UrbanAccessAnalyzer.osm_io and
:mod:UrbanAccessAnalyzer.graph_ops for how they're built and
manipulated. No networkx/osmnx graph object exists anywhere in this
class.
from_pbf(pbf_path, aoi=None, network_type='walk', simplify_distance=None, ignore_oneway=False, crop_buffer_m=500.0)
classmethod
¶
Build a street network from a local (or Geofabrik-downloaded) PBF file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pbf_path
|
str
|
Path to a |
required |
aoi
|
Optional[AreaOfInterest]
|
AOI used both for downloading (if needed) and for bbox prefiltering during load. |
None
|
network_type
|
str
|
One of |
'walk'
|
simplify_distance
|
Optional[float]
|
If given, run
:func: |
None
|
ignore_oneway
|
bool
|
Forwarded to :func: |
False
|
crop_buffer_m
|
float
|
Metres to buffer |
500.0
|
Returns:
| Type | Description |
|---|---|
'StreetNetwork'
|
A new :class: |
simplify(cluster_distance, protected_node_ids=None)
¶
Cluster-simplify this network's topology; see :func:UrbanAccessAnalyzer.graph_ops.simplify.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cluster_distance
|
float
|
Max edge length used to chain nodes into a cluster. |
required |
protected_node_ids
|
Optional[list[int]]
|
Node ids to keep as singleton clusters. |
None
|
Returns:
| Type | Description |
|---|---|
'StreetNetwork'
|
A new, simplified :class: |
crop(aoi, crop_buffer_m=500.0)
¶
Crop this network to an AOI; see :func:UrbanAccessAnalyzer.graph_ops.crop_by_aoi_connected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
aoi
|
AreaOfInterest
|
Area to crop to. |
required |
crop_buffer_m
|
float
|
Metres to buffer |
500.0
|
snap_points(points, max_dist=None, min_edge_length=1.0)
¶
Snap POI points onto this network, splitting edges as needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
'PointsOfInterest'
|
Points to snap. Reprojected to this network's CRS first
if |
required |
max_dist
|
Optional[float]
|
Maximum snap distance. |
None
|
min_edge_length
|
float
|
See :func: |
1.0
|
Returns:
| Type | Description |
|---|---|
|
Tuple |
|
|
network and |
to_gdf()
¶
Export edges as a GeoDataFrame.
save(folder)
¶
Persist nodes/edges as Parquet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
folder
|
str
|
Destination directory (created if missing). Writes
|
required |
load(folder)
classmethod
¶
Load a network previously written by :meth:save.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
folder
|
str
|
Folder written by :meth: |
required |
Returns:
| Type | Description |
|---|---|
'StreetNetwork'
|
The loaded network. |
plot(m=None, **kwargs)
¶
Draw this network's edges on a Folium map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
m
|
Existing Folium map to draw on; |
None
|
|
**kwargs
|
Passed to :func: |
{}
|
Returns:
| Type | Description |
|---|---|
|
The Folium map. |
PointsOfInterest(df, crs=None)
¶
A set of scored points of interest, backed by a Polars DataFrame with WKB geometry.
Wrap an existing POI DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
POI table with a WKB |
required |
crs
|
Optional[str]
|
CRS of |
None
|
from_overpass(kind, bounds)
classmethod
¶
Fetch a named OSM POI category via Overpass.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kind
|
str
|
One of the convenience functions in
:mod: |
required |
bounds
|
GeoDataFrame
|
AOI GeoDataFrame defining the query extent. |
required |
Returns:
| Type | Description |
|---|---|
'PointsOfInterest'
|
A new :class: |
'PointsOfInterest'
|
func: |
Raises:
| Type | Description |
|---|---|
ValueError
|
For an unrecognized |
assign_score_by_values(column, value_priority, out_column='poi_score')
¶
Assign a [0, 1] score from a categorical column; see :func:UrbanAccessAnalyzer.scoring.score_by_values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
column
|
str
|
Categorical column to score. |
required |
value_priority
|
list
|
Values from best to worst; the best gets score 1. |
required |
out_column
|
str
|
Name of the new score column. |
'poi_score'
|
Returns:
| Type | Description |
|---|---|
'PointsOfInterest'
|
A new :class: |
to_h3(resolution, columns=None, method='max')
¶
Rasterize these points to H3 cells; see :func:UrbanAccessAnalyzer.h3_ops.from_df.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resolution
|
int
|
H3 resolution. |
required |
columns
|
Optional[list]
|
Columns to carry onto the cells; |
None
|
method
|
Union[str, dict]
|
How several points in one cell combine ( |
'max'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per H3 cell. |
to_gdf()
¶
Export as a GeoDataFrame, in self.crs (EPSG:4326 if unset).
AccessibilityAnalyzer(street_network, points)
¶
Orchestrates a :class:StreetNetwork + :class:PointsOfInterest into isochrones.
default_distance_matrix(distance_steps, poi_score_col='poi_score', score_bins=None)
¶
See :func:UrbanAccessAnalyzer.isochrones.default_distance_matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
distance_steps
|
Sequence[float]
|
Walking distances (m) of the access levels, from best to worst. |
required |
poi_score_col
|
str
|
POI score column. |
'poi_score'
|
score_bins
|
Optional[int]
|
Number of score bins; |
None
|
Returns:
| Type | Description |
|---|---|
|
The distance matrix (score bins x access levels). |
run(distance_matrix, poi_score_col='poi_score', access_score_values=None, min_edge_length=1.0, max_dist=None, undirected=True, verbose=True, unreached_access_score=0.0, chunk_h3_resolution=None, chunk_buffer_m=1000.0)
¶
Compute the multi-tier access-score isochrone; see :func:UrbanAccessAnalyzer.isochrones.graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
distance_matrix
|
See :func: |
required | |
poi_score_col
|
Optional[str]
|
Score column on |
'poi_score'
|
access_score_values
|
Optional[Sequence]
|
Explicit access-score labels, positionally
aligned with |
None
|
min_edge_length
|
float
|
Minimum snap/split segment length (meters). |
1.0
|
max_dist
|
Optional[float]
|
Maximum POI-to-edge snap distance (meters). |
None
|
undirected
|
bool
|
Ignore one-way restrictions during the search. |
True
|
verbose
|
bool
|
Print per-tier progress. |
True
|
unreached_access_score
|
Optional[float]
|
Score given to the parts of the network no
POI reaches. Defaults to |
0.0
|
chunk_h3_resolution
|
Optional[int]
|
If set, computes node access in
memory-bounded H3-res-N chunks instead of one whole-network
pass -- see :func: |
None
|
chunk_buffer_m
|
float
|
Buffer (meters) forwarded when
|
1000.0
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Tuple |
DataFrame
|
func: |
to_gdf(edge_access=None)
¶
Export the last (or given) edge-access result as a street-edges GeoDataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_access
|
Optional[DataFrame]
|
Result of :meth: |
None
|
Returns:
| Type | Description |
|---|---|
GeoDataFrame
|
GeoDataFrame of scored edge segments, in the street network's CRS. |
to_level(level_gdf, id_col, edge_access=None, columns=None, agg=None)
¶
Aggregate the last (or given) edge-access result onto an arbitrary polygon layer.
Generalizes :meth:to_h3 to any polygon GeoDataFrame (an H3
grid, administrative boundaries, or any other polygon layer), via
:func:UrbanAccessAnalyzer.geometry_levels.edges_to_level (which in
turn requires the optional geohierarchy dependency).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
level_gdf
|
GeoDataFrame
|
Target polygon GeoDataFrame to aggregate onto. |
required |
id_col
|
str
|
Name of the unique id column in |
required |
edge_access
|
Optional[DataFrame]
|
Result of :meth: |
None
|
columns
|
Optional[list]
|
Attribute columns to aggregate; defaults to
|
None
|
agg
|
Aggregation strategy (a
:class: |
None
|
Returns:
| Type | Description |
|---|---|
GeoDataFrame
|
A copy of |
GeoDataFrame
|
aggregated |
to_h3(resolution, edge_access=None, method='max')
¶
Rasterize the last (or given) edge-access result to H3 cells.
Thin convenience wrapper: builds an H3 grid over the edges' extent
via the optional geohierarchy dependency's
:func:~geohierarchy.h3_cells, then delegates to :meth:to_level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resolution
|
int
|
H3 resolution. |
required |
edge_access
|
Optional[DataFrame]
|
Result of :meth: |
None
|
method
|
str
|
Aggregation method for |
'max'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Polars DataFrame with an |
DataFrame
|
aggregated |