cityImage API reference#
This page documents the curated public API after the refactor. The package keeps cityImage-specific semantics at the top level and delegates generic operations to specialised libraries:
file reading and CRS handling to GeoPandas;
OpenStreetMap acquisition to OSMnx;
graph algorithms to NetworkX, iGraph, and python-louvain;
raster/zonal-statistics operations to rasterio/rasterstats;
optional 3D mesh/ray operations to PyVista and Dask;
optional static plotting to Matplotlib and mapclassify.
The public API therefore focuses on stable cityImage schemas and computational urban-image semantics: networks, barriers, regions, land use, landmarks, visibility, and imageability scoring. Low-level implementation helpers and generic GeoPandas/Shapely operations are intentionally not listed here.
Schema and adapters#
Raised when a GeoDataFrame does not match a cityImage schema contract. |
|
|
Simple validation report returned by schema-checking helpers. |
|
Return required columns that are absent from a DataFrame. |
|
Raise a SchemaError if required columns are missing. |
|
Validate that a GeoDataFrame has a geometry column with valid entries. |
|
Validate list-like land-use columns used by pragmatic scoring. |
|
Return buildings with common non-semantic cityImage defaults populated. |
|
Validate the minimal cityImage node table contract. |
|
Validate the minimal cityImage edge table contract. |
|
Validate the minimal cityImage building table contract. |
|
Return a nodes GeoDataFrame matching the minimal cityImage schema. |
|
Return an edges GeoDataFrame matching the minimal cityImage schema. |
|
Return a buildings GeoDataFrame matching the cityImage building schema. |
|
Standardize any provided cityImage input tables. |
IO and OSM bridge API#
These helpers preserve cityImage output schemas while delegating acquisition and file IO to GeoPandas and OSMnx.
|
Load line geometries from file and convert them to cityImage network schema. |
|
Load building polygons from file and convert them to cityImage schema. |
|
Download raw OSM features through OSMnx and optionally project them. |
|
Download an OSM network and convert it to cityImage network schema. |
|
Download OSM buildings and convert them to cityImage building schema. |
|
Download OSM features and build the combined cityImage barrier layer. |
|
Build cityImage nodes/edges from a line GeoDataFrame. |
|
Download OSM highway features with OSMnx and build a pedestrian network. |
|
Build a cityImage pedestrian network from already-downloaded OSM features. |
|
Filter OSM highway features using cityImage pedestrian-network semantics. |
Buildings#
|
Select buildings within a polygon or centroid-distance study area. |
Angles and graph semantics#
|
Return coordinates at |
|
Compute the angle between two endpoint-connected LineStrings. |
|
Create an undirected NetworkX graph from cityImage node/edge GeoDataFrames. |
|
Create an undirected NetworkX MultiGraph from cityImage graph GeoDataFrames. |
|
Create dual-node and dual-edge GeoDataFrames from a primal street graph. |
|
Create a NetworkX graph from dual-node and dual-edge GeoDataFrames. |
|
Map a dual-graph node dictionary to a dictionary keyed by primal edge IDs. |
|
Convert a NetworkX graph with geometry attributes into node/edge GeoDataFrames. |
|
Return node degree counts from an edge GeoDataFrame with |
Network topology#
|
Cleans a street network by applying a series of topology and geometry corrections to nodes and edges GeoDataFrames. |
|
The function identify pseudo-nodes, namely nodes that represent intersection between only 2 segments. |
|
Removes duplicate nodes in a network based on coincident geometry, updating both nodes and edges GeoDataFrames. |
|
Cleans and deduplicates network edges, and removes unused nodes. |
|
Removes duplicate edges with the same start and end nodes (same vertexes) in a network GeoDataFrame. |
|
The function removes dead-ends. |
|
Fix the network topology by removing (fake) self-loops and adding fixed edges. |
|
Node the network at shared, un-noded vertices. |
|
Remove disconnected islands from a graph. |
|
The function adjusts the edges LineString coordinates consistently with their relative u and v nodes' coordinates. |
|
Consolidates nodes in a spatial network that are within a given distance (tolerance), preserving topology and unclustered nodes. |
|
Consolidate edge geometries after node consolidation. |
Centrality#
Centrality wrappers keep cityImage node/edge output semantics while delegating centrality algorithms to graph libraries.
|
Calculate centrality values for a NetworkX graph. |
|
Calculate reach centrality from an igraph graph. |
|
Calculate straightness centrality from an igraph graph. |
|
Assign local opportunity counts to nodes and to the NetworkX graph. |
|
Attach edge-level centrality values to an edges GeoDataFrame. |
Barriers#
Barrier helpers convert roads, waterways, coastlines, railways, and parks into
the Lynchian edge semantics used by cityImage.
Return OSM tag queries needed to build the full barrier layer externally. |
|
|
Build a combined cityImage barrier layer from already-downloaded OSM features. |
|
Build road barrier features from already-downloaded OSM highway features. |
|
Build water barrier features from already-downloaded OSM water features. |
|
Build railway barrier features from already-downloaded OSM railway features. |
|
Build park barrier features from already-downloaded OSM leisure features. |
|
Assign water barriers lying along/crossing each street segment. |
|
Assign park barrier IDs lying along or containing each street segment. |
|
Return barrier IDs along a given edge, excluding touching/crossing barriers. |
|
Add boolean |
Regions and districts#
|
Identify edge-based regions using delegated python-louvain partitioning. |
|
Identify node-based regions using delegated python-louvain partitioning. |
|
Assign a precomputed dual-graph partition to primal street segments. |
|
Assign a precomputed primal-graph partition to street nodes. |
|
Create district polygons from edge-based partition labels. |
|
Assign edge-based district IDs to nodes using nearest street segment. |
|
Assign node-based district IDs to edges. |
|
Assign polygon-based district IDs to nodes using nearest polygon. |
|
Amend node membership based on connectivity and minimum district size. |
|
Identify nodes lying on a district boundary. |
Land use#
Land-use functions cover OSM-derived land-use semantics and sparse/non-OSM attribute workflows.
|
Classify sparse attribute values using explicit category lists. |
Convert per-row triplets into per-row macro-group labels. |
|
|
Classify cityImage land-use groups into DMA functional categories. |
|
Derive raw cityImage land-use candidates from OSM-style tag columns. |
|
Assign land-use labels to buildings by spatially matching against other_gdf. |
|
Collect labels from Point/MultiPoint geometries intersecting each building. |
|
Assign land-use labels from polygon layers to building polygons. |
|
Classify sparse/non-OSM land-use attributes attached to buildings. |
|
Spatially attach sparse/non-OSM land-use labels to buildings. |
|
Find land-use labels in buildings_gdf[land_uses_column] matching a regex pattern. |
|
Find UNCLASSIFIED items in "<token>:<group>:<domain>" triplets. |
Landmarks and imageability scoring#
These functions implement the cityImage landmark and imageability model: structural, visual, cultural, and pragmatic salience, followed by global/local score composition.
|
Configuration for high-level cityImage building scoring. |
|
The function computes the "Structural Landmark Component" sub-scores of each building. |
|
Calculate visibility landmark sub-scores. |
|
Compute a cultural landmark component per building. |
|
Compute a pragmatic landmark component from semantic land-use labels. |
|
Compute component and global landmarkness scores. |
|
The function computes landmarkness at the local level. |
|
Compute requested building-level cityImage component scores. |
|
Compute global cityImage landmarkness scores from component columns. |
|
Compute local cityImage landmarkness scores from component columns. |
|
Run the high-level building component/global/local scoring pipeline. |
|
Return numeric weights after validating their values and optional sum. |
Building height and terrain elevation#
Height helpers are optional. Raster workflows require the height extra.
Terminology: the DTM (bare-earth terrain) provides node z and building
base; a surface model (DSM — first-return elevations including rooftops,
often distributed under the generic name DEM) compared against the DTM provides
above-ground building heights. assign_elevations_from_rasters is the one-stop
entry point for cities without building-height data.
|
One-stop elevation assignment from rasters, for cities without height data. |
|
Assign per-building ground elevation ( |
|
Compute per-building base elevation and height from DEM and DTM rasters. |
Assign base and height attributes from a detailed building layer. |
|
|
Sample a DTM raster to assign elevation to point nodes. |
Visibility#
2D visibility is part of the core geospatial workflow. 3D sight-line workflows
are optional and require the visibility3d extra, or all.
|
Return the area of the 2D advance-visibility polygon around a building. |
|
Compute visible 3D sight lines between observer nodes and target buildings. |
|
Split candidate sight lines by 2D planimetric obstruction status. |
|
Check 3D visibility for sight lines with candidate obstructions. |
|
Filters potential observer-target pairs by minimum distance and generates sight line geometries. |
|
Sample representative coordinates along a LineString. |
|
Extrude a 2D building polygon into a 3D PyVista solid. |
|
Merge temporary GeoPackage sight-line chunks. |
Geometry and small utilities#
Only cityImage-specific geometry helpers are exposed. Generic envelope, convex-hull, distance, file-loading, and arbitrary dataframe helpers were removed from the public API; use GeoPandas/Shapely/Pandas directly for those.
|
Compute a centre line from consistently oriented LineStrings. |
|
Split a LineString at one or more point intersections. |
Merge or explode MultiLineString geometries into LineString rows. |
|
|
Convert one-part MultiPolygons to Polygons and explode remaining MultiPolygons. |
|
Scale numeric values to the unit interval. |
Plotting#
Plotting is optional and imported lazily. Use these public plotting entry points rather than internal axis, legend, or colorbar helpers.
|
Class for creating a basic matplotlib plot with a title and customizable settings. |
|
Create a grid of static GeoDataFrame plots. |
|
It plots the geometries of a single GeoDataFrame, coloring on the bases of the values contained in column, using a given scheme. |
|
It plots the geometries of different GeoDataFrames, coloring on the bases of the values contained in the provided column, using a given scheme. |
|
It plots the geometries of a GeoDataFrame, coloring on the bases of the values contained in two or more provided columns, using a given scheme. |
|
It generates a categorical random color map, given the number of classes |
It returns a Kindlmann color map. |
|
|
Normalizes a value n from one range to another range. |
|
Lightens the given color by multiplying (1-luminosity) by the given amount. |
|
Generates a list of random HSV colors given the number of classes, minimum and maximum values in the HSV spectrum. |