dhd.city

Module defining the class City which allows to load information from Open Street Map (OSM) about the street network and the buildings geometries of a given city.

Inputs

The user must provide the name of the considered city (name), for instance ‘Vevey, Switzerland’. Heating sources and natural barriers (rivers, railways,…) coordinates may as well be provided as lists of shapely geometries.

Outputs

All the city information is organized in dataframes. The streets network (streets), the buildings to be connected (sinks), the heating sources (sources) and the natural barriers (barriers) are respectively obtained with the methods get_streets(), select_sinks(), get_sources() and get_barriers().

Class

class dhd.city.City(name, sources=None, barriers=None)[source]

Class to define a city with the geometry of its buildings and streets. Sources and natural barriers may also be considered if provided as shapely objects.

Parameters:
  • name (string) – Name of the city to load.
  • sources (list, optional) – List of the heating source(s) as shapely Point geometries. Default is None.
  • barriers (list, optional) – List of the natural barriers as shapely LineString geometries. Default is None.
static complete_geometries(streets, graph)[source]

Create a LineString geometry for edges without geometry ; in-place.

The LineString is a single line matching the coordinates of the two edge ends.

Parameters:
  • streets (DataFrame) – Dataframe of the street network.
  • graph (Graph) – Graph of the street network.
get_barriers()[source]

Store the barriers (City.barriers) in a dataframe with unique column ‘geometry’ for the shapely LineString of the barrier and return it.

The barriers may be any constraint impossible to cross when connecting the sinks/sources to the heating network (rivers, railways,…).

If City.barriers is None or not a valid type (list of shapely LineStrings), the exception BarrierError is raised.

Returns:sources
Dataframe of the heating source(s) with the following structure:
  • INDEX: Integers.
  • COLUMNS:
    • ’geometry’: Point geometry of the source.
Return type:DataFrame
get_sources()[source]

Store the source(s) (City.sources) in a dataframe with unique column ‘geometry’ for the shapely Point of the source and return it.

If City.sources is None or not a valid type (list of shapely Points), the exception SourceError is raised.

Returns:sources
Dataframe of the heating source(s) with the following structure:
  • INDEX: Integers.
  • COLUMNS:
    • ’geometry’: Point geometry of the source.
Return type:DataFrame
get_streets()[source]

Store the streets network in a dataframe and return it.

Returns:streets
Dataframe of the street network with the following structure:
  • INDEX: Integers.
  • COLUMNS:
    • ’idA’: index of the edge first node,
    • ’idB’: index of the edge second node,
    • ’geometry’: LineString edge geometry,
    • ’weight’: weight (length) of the edge.
Return type:DataFrame
static init_barriers(barriers)[source]

Store the barriers (barriers) in a dataframe with unique column ‘geometry’ for the shapely LineString of the barrier.

Parameters:barriers (list) – List of shapely LineString representing the barriers coordinates.
Returns:DataFrame of the barriers.
Return type:DataFrame
init_buildings()[source]

Load the geometries (Polygons) of the buildings of the considered city.

The geometries are projected on the CRS used for the street network. All attributes but ‘geometry’ are dropped.

Returns:Dataframe of the buildings of the city.
Return type:DataFrame
static init_sources(sources)[source]

Store the source(s) (sources) in a dataframe with unique column ‘geometry’ for the shapely Point of the source.

Parameters:sources (list) – List of shapely Points representing the source(s) coordinates.
Returns:DataFrame of the heating source(s).
Return type:DataFrame
static init_streets(graph)[source]

Convert the street graph to a DataFrame with source and target labels ‘idA’ and ‘idB’.

All arguments but ‘idA’, ‘idB’ and ‘geometry’ are dropped.

Parameters:graph (Graph) – Graph of the street network.
Returns:Dataframe of the street network.
Return type:DataFrame
reset_barriers(barriers)[source]

Reset the list of shapely LineString used to define the natural barriers(s).

Parameters:barriers (list, optional) – List of the natural barriers as shapely LineString geometries. Default is None.
reset_sources(sources)[source]

Reset the list of shapely Point used to define the source(s).

Parameters:sources (list) – List of the heating source(s) as shapely Point geometries. Default is None.
select_sinks(min_load=0)[source]

Select the sinks to be connected to the distrcit heating network.

Only buildings with area larger than min_area are selected.

Parameters:min_load (float, optional) – Buildings with a load larger than min_load ([kW]) are selected to be connected to the district heating network. Default is 0.
Returns:sinks
Dataframe of the selected buildings (sinks) with the following structure:
  • INDEX: Integers.
  • COLUMNS:
    • ’geometry’: Polygon geometry of the building (sink),
    • ’load’: heating load of the building (building area).
Return type:DataFrame
set_buildings()[source]

Store the buildings geometries in a dataframe and return it.

Returns:buildings
Dataframe of the buildings of the city with the following structure:
  • INDEX: Integers.
  • COLUMNS:
    • ’geometry’: Polygon geometry of the building,
    • ’load’: heating load of the building (building area).
Return type:DataFrame
set_buildings_load(buildings)[source]

Set the building load equal to its area ; in-place.

Parameters:buildings (DataFrame) – Dataframe of the buildings of the city
static set_geometries_order(streets, graph)[source]

Reverse alle edges (LineString) not pointing in the right direction ; in-place.

The streets network streets is modified so that the edge between two nodes always point from ‘idA’ to ‘idB’.

Parameters:
  • streets (DataFrame) – Dataframe of the street network.
  • graph (Graph) – Graph of the street network.
set_graph()[source]

Load the street network from OSM and save it as a MultiDiGraph.

Returns:
Return type:MultiDiGraph
static set_indices(streets)[source]

Set indices of the streets dataframe streets ; in-place.

static set_streets_weight(streets)[source]

Set the streets weight equal to theirt length ; in-place.

simplify_graph()[source]

Turn the MultiDiGraph of the street network to a simple Graph and reset its nodes label to integers.

Returns:
Return type:Graph