iduedu.add_elevation

iduedu.add_elevation(urban_graph, elevation, *, column='elevation', method='linear', sample_distance=20.0, structure_columns=('bridge', 'tunnel'), band=1)[source]

Add node heights and edge grades to a graph.

Nodes get elevation (metres). Every edge is sampled along its geometry at steps of at most sample_distance and gets, in the direction from u to v:

  • grade: rise over length between its ends, positive uphill;

  • grade_max: the steepest absolute grade between two neighbouring samples;

  • ascent and descent: metres climbed and descended along the edge, both non-negative.

Edges on a bridge or in a tunnel (a structure_columns tag other than no) get a straight profile between their ends, and the nodes inside such structures get heights interpolated between the ends of the structure instead of the ground below or above them.

Parameters:
  • urban_graph (UrbanGraph) – Graph in a projected (metric) CRS.

  • elevation (Union[str, PathLike, GeoDataFrame, Callable]) – Source of heights: a raster file (read with rasterio, bilinear interpolation, any CRS), a GeoDataFrame of points or contour lines with heights in column, or a function f(x, y) -> z of coordinate arrays in the graph CRS.

  • column (str) – Height column of an elevation GeoDataFrame.

  • method (Literal['linear', 'nearest', 'idw']) – Interpolation between the heights of a GeoDataFrame: "linear" on a triangulation (the nearest height outside the data), "nearest" or "idw" (inverse squared distance to the eight nearest points).

  • sample_distance (float) – Largest step, in metres, between samples along an edge, and between points taken from contour lines.

  • structure_columns (Iterable[str]) – Edge columns that mark bridges and tunnels.

  • band (int) – Band of a raster file.

Return type:

UrbanGraph

Returns:

A new UrbanGraph with the added columns. Nodes without data have NaN and so do the edges that touch them.

Raises:
  • ImportError – If elevation is a raster path and rasterio is not installed.

  • ValueError – If the graph CRS is missing or geographic, or the source does not cover the graph.