UrbanAccessAnalyzer.geometry_levels¶
Bridge from UAA's Polars edge results to geohierarchy's any-polygon aggregation.
UAA represents street-network edges (and their per-edge access scores) as a
Polars DataFrame with a WKB geometry column, while the geohierarchy
package works with GeoPandas GeoDataFrames and aggregates line data onto an
arbitrary polygon layer (an H3 grid, administrative boundaries, or any other
polygon GeoDataFrame) via its edges_to_level helper. This module does
the small amount of glue work in between: converting UAA's Polars/WKB edge
table into a GeoDataFrame (the same conversion :meth:AccessibilityAnalyzer
.to_h3 already did before this refactor) and handling columns that aren't
plain numeric quantities -- e.g. categorical access-score labels -- which
geohierarchy's aggregation strategies (Max/Min) don't natively
support since they call Polars numeric-only operations internally. This is an
optional dependency of UAA: geohierarchy is only imported when a function
in this module is actually called, behind the geohierarchy extra.
edges_to_level(edges_df, level_gdf, id_col, columns, agg=None, geometry_col='geometry', crs=None)
¶
Aggregate columns from a Polars WKB edge table onto a polygon level.
Converts edges_df (a Polars DataFrame with a WKB-encoded
geometry_col, as produced throughout UAA) into a GeoDataFrame, then
delegates to :func:geohierarchy.edges_to_level to length-weight the
requested columns onto level_gdf.
Non-numeric columns (e.g. categorical access-score labels) can't be
aggregated by geohierarchy's Max/Min strategies directly,
since those call Polars numeric-only expressions internally. For any
column resolved to a Max/Min strategy that isn't already
numeric, this function encodes it to integer codes ordered the same way
Polars would sort the raw values (so the numeric max/min matches the
string max/min UAA previously produced), aggregates, then decodes the
result back to the original labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edges_df
|
DataFrame
|
Polars DataFrame with a WKB |
required |
level_gdf
|
GeoDataFrame
|
Target polygon GeoDataFrame to aggregate onto -- an H3 grid, an administrative boundary layer, or any other polygon layer. |
required |
id_col
|
str
|
Name of the unique id column in |
required |
columns
|
Union[str, List[str]]
|
Column name or list of column names in |
required |
agg
|
Aggregation strategy (a
:class: |
None
|
|
geometry_col
|
str
|
Name of the WKB geometry column in |
'geometry'
|
crs
|
Coordinate reference system the result should use. Defaults to
|
None
|
Returns:
| Type | Description |
|---|---|
GeoDataFrame
|
A copy of |
GeoDataFrame
|
aggregated |
Raises:
| Type | Description |
|---|---|
ImportError
|
If the optional |