Network

ultimodel.CreateNetwork.Edges(country, taz, taz_cn='country', taz_geo='geometry')

Create network edges from OSM

Parameters:
  • country (str) –

    code or name of country

  • taz (gpd.GeoDataFrame) –

    GeoDataFrame including the TAZ

  • taz_geo (str, default: 'geometry' ) –

    Name of geometry column in TAZ layer

  • taz_cn (str, default: 'country' ) –

    Name of column in TAZ layer that defines the country of the TAZ

get_polygon(taz_id, proj_crs=3035, buffer=2500)

Define polygon(s) for network extraction; split islands and exclaves and apply buffer to include all streets near the border

Parameters:
  • taz_id (str) –

    Name of ID-column in TAZ layer

  • proj_crs (int, default: 3035 ) –

    EPSG number of projected crs for defining buffer in meter, default 3035 (LAEA europe)

  • buffer (float, default: 2500 ) –

    buffer in meter

Returns:
  • GeoDataFrame with polygons for extraction; multiple polygons if there are islands or exclaves

get_edges(filter_highway, polygons)

Get network for selected highway types from OSM for specified country

Parameters:
  • filter_highway (list) –

    List of OSM highway types to include; only main types (e.g. motorway), respective link-types (e.g. motorway_link) are included automatically

  • polygons (gpd.GeoDataFrame) –

    polygons of country / region to extract network from, several polygons possible

set_attributes(taz_id, start_id=0)

Overlay self.edges with TAZ layer to split links at borders and assign TAZ-ID Set length, travel time, highway type and ID of self.edges GeoDataFrame

Parameters:
  • taz_id (str) –

    Name of ID-column in TAZ layer

  • start_id (int, default: 0 ) –

    start of IDs for each edge, default 0

Returns:
  • self.edges is updated with necessary attributes

set_nodes(nodes, order_col, nodeid_col='node_id', linkid_col='ultimo_id')

Set start and end node for each edge in self.edges based on node GDF

Parameters:
  • nodes (gpd.GeoDataFrame) –

    GeoDataFrame with start and end node per edge

  • order_col (str) –

    Name of column with order of nodes per edge in nodes

  • nodeid_col (str, default: 'node_id' ) –

    Name of column with node ID in nodes, default "node_id"

  • linkid_col (str, default: 'ultimo_id' ) –

    Name of column with link ID in nodes, default "ultimo_id"

Returns:
  • self.edges includes from and to nodes

connect_subgraphs(nodes, edges=None, node_id='node_id', node_geo='geometry', edge_id='ultimo_id', edge_from='from_node', edge_to='to_node')

Ensure that the road network is connected, i.e. each node is connected to each other. If there are multiple subgraphs, connect the larger subgraphs and remove singular edges.

Parameters:
  • nodes (gpd.GeoDataFrame) –

    network nodes

  • edges (gpd.GeoDataFrame, default: None ) –

    network edges; if None, use self.edges

  • node_id (str, default: 'node_id' ) –

    column name with ID in nodes

  • node_geo (str, default: 'geometry' ) –

    column name with geometry in nodes

  • edge_id (str, default: 'ultimo_id' ) –

    column name with ID in edges

  • edge_from (str, default: 'from_node' ) –

    column name with ID of start node in edges

  • edge_to (str, default: 'to_node' ) –

    column name with ID of end node in edges

Returns:
  • gpd.GeoDataFrame

    GeoDataFrames with 1) final network edges and 2) final network nodes

ultimodel.CreateNetwork.Nodes(edges)

Create nodes at the ends of edges

Parameters:
  • edges (gpd.GeoDataFrame) –

    GeoDataFrame with LineString-Objects

init_nodes()

init node GeoDataFrame

create_nodes(id_col, geom_col='geometry')

Create nodes at the ends of each LineString in edges !! only works with LineStrings, not with MultiLineString !! use gpd.GeoDataFrame.explode() to transform MultiLineString to LineString

Parameters:
  • id_col (str) –

    name of column with unique identifier in edges GDF

  • geom_col (str, default: 'geometry' ) –

    name of geometry column in edges GDF, default "geometry"

remove_duplicates()

Remove duplicate nodes (i.e. at the same coordinates)

--> result: GeoDataFrame self.nodes.unique without duplicates

Returns:
  • None

set_node_id(id_col='node_id', start=0)

Set ID per unique node and assign this ID to all nodes

--> result: GeoDataFrame of self.nodes, self.nodes_unique with ID column

Parameters:
  • id_col (str, default: 'node_id' ) –

    name of ID column for nodes, default "node_id"

  • start (int, default: 0 ) –

    start of IDs for each node, default 0

Returns:
  • None

ultimodel.CreateNetwork.Connectors()

Connect the TAZ to the road network: find possible connector locations and identify corresponding nodes

find_connector_locations(taz, pop, taz_id='nuts_id', taz_geom='geom', epsg_pop=4326)

Identify suitable connector locations per TAZ depending on population density

--> result is self.connectors as GeoDataFrame with connector locations; Point layer

Parameters:
  • epsg_pop (int, default: 4326 ) –

    CRS of population dataframe, default 4326

  • taz (gpd.GeoDataFrame) –

    GeoDataFrame with the TAZ

  • taz_geom (str, default: 'geom' ) –

    name of geometry column in TAZ GDF

  • taz_id (str, default: 'nuts_id' ) –

    name of ID column for TAZ IDs

  • pop (gpd.GeoDataFrame) –

    GeoDataFrame of points with population density

Returns:
  • None

identify_connector_nodes(nodes, node_no='node_id', node_geom='geometry', zone='nuts_id', weight='weight', country_check=False)

Move connector locations to network nodes

Parameters:
  • nodes (gpd.GeoDataFrame) –

    GeoDataFrame Points; network nodes

  • node_no (str, default: 'node_id' ) –

    column name with node identifier

  • node_geom (str, default: 'geometry' ) –

    name of geometry column in nodes GDF

  • zone (str, default: 'nuts_id' ) –

    column name with zone identifier

  • weight (str, default: 'weight' ) –

    column name with weight of connector

  • country_check (bool, default: False ) –

    ensure that connectors are moved to nodes within the same country

Returns:
  • gpd.GeoDataFrame

    GeoDataFrame with connector nodes

ultimodel.CreateNetwork.Ferries(taz, scope=None, taz_cn='cntr_code', taz_geo='geometry')

Create connections over water between islands and main land, using ferry routes and bridges as reference

Parameters:
  • taz (gpd.GeoDataFrame) –

    GeoDataFrame with TAZ cells

  • scope (str | list, default: None ) –

    region of taz to be considered; default None includes all taz, str with country code reduces taz to country, list with country codes reduces taz to countries in list

  • taz_cn (str, default: 'cntr_code' ) –

    name of column with country code in taz

  • taz_geo (str, default: 'geometry' ) –

    name of geometry column in taz

find_ferry_routes(buffer_water=0.05)

Extract ferry routes from OSM for water body around region (defined by scope in init)

--> result: self.ferry and self.nodes include ferry routes and their end nodes

Parameters:
  • buffer_water (float, default: 0.05 ) –

    buffer to use around land mass to extract water polygon, in degrees

Returns:
  • None

ferry_national(region_id='id', ferry_buffer=0.01)

Create GeoDataFrames of ferry routes and nodes with a country; filter other relations out of self.ferry and self.nodes

Parameters:
  • region_id (str, default: 'id' ) –

    name of column with identifier

  • ferry_buffer (float, default: 0.01 ) –

    buffer to use to look for end nodes in coast region

Returns:
  • gpd.GeoDataFrame

    GeoDataFrame ferry_routes with national ferry routes and GeoDataFrame ferry_nodes with respective nodes

ferry_international(ferry_buffer=0.01)

Create GeoDataFrame of ferry routes and nodes between different countries, filter national relations out of self.ferry and self.nodes

Parameters:
  • ferry_buffer (float, default: 0.01 ) –

    buffer to use to look for end nodes in coast region

Returns:
  • gpd.GeoDataFrame

    GeoDataFrame ferry_routes with international ferry routes and GeoDataFrame ferry_nodes with respective nodes

ferry_to_road(ferry_routes, ferry_nodes, network_roads, network_nodes, ferry_buffer_m=2500, speed_ferry=30, roads_id='ultimo_id', roads_fr='from_node', roads_to='to_node', node_id='node_id')

Connect ferry end nodes to road network and add as links (direct lines)

Parameters:
  • ferry_routes (gpd.GeoDataFrame) –

    GeoDataFrame with ferry routes (lines)

  • ferry_nodes (gpd.GeoDataFrame) –

    GeoDataFrame with ferry nodes (points)

  • network_roads (gpd.GeoDataFrame) –

    GeoDataFrame with road network (lines)

  • network_nodes (gpd.GeoDataFrame) –

    GeoDataFrame with unique road network nodes (points)

  • ferry_buffer_m (float, default: 2500 ) –

    buffer size around ferry nodes for finding connecting roads in meter

  • speed_ferry (float, default: 30 ) –

    speed on ferry link in kph

  • roads_id (str, default: 'ultimo_id' ) –

    name of column with road identifier in network_roads

  • roads_fr (str, default: 'from_node' ) –

    name of column with from node in network_roads

  • roads_to (str, default: 'to_node' ) –

    name of column with to node in network_roads

  • node_id (str, default: 'node_id' ) –

    name of column with node identifier in network_nodes

Returns:
  • gpd.GeoDataFrame

    GeoDataFrame of road network, connected along ferry routes

ultimodel.CreateNetwork.CombineNetworks(taz, roads, taz_cn='cntr_code')

Merge road networks of multiple countries / regions to create a routable international network

Parameters:
  • taz (gpd.GeoDataFrame) –

    TAZ for regions

  • roads (gpd.GeoDataFrame) –

    road network covering all regions

  • taz_cn (str, default: 'cntr_code' ) –

    column name for country in taz

find_borders(buffer=2500, taz_geo='geometry')

Create polygons with a defined buffer around the borders

--> result: self.border contains border polygons

Parameters:
  • buffer (float, default: 2500 ) –

    buffer width in m

  • taz_geo (str, default: 'geometry' ) –

    name of geometry column in TAZ

Returns:
  • None

get_border_roads(roads_cn='cn')

Find all roads within the border buffer

--> result: self.border_roads as GDF with all roads within border buffer

Parameters:
  • roads_cn (str, default: 'cn' ) –

    column name with country attribute in roads GDF

Returns:
  • None

connect_border_roads(nodes_int, id_st=900000000, roads_cn='cn', roads_type='type', filter_types=None, roads_id='ultimo_id', roads_fr='from_node', roads_to='to_node', node_id='node_id', node_geo='geometry')

Create new directed lines between the nearest end nodes of each country at the border

--> result: self.network_int as GDF with connected network, --> result: self.dict_borders as dictionary with number of connected roads

Parameters:
  • nodes_int (gpd.GeoDataFrame) –

    contains nodes of network

  • id_st (int, default: 900000000 ) –

    start ID for new lines

  • roads_cn (str, default: 'cn' ) –

    column name for country in self.network

  • roads_type (str, default: 'type' ) –

    column name for road type in self.network

  • filter_types (list, default: None ) –

    types of roads to be included for international connections

  • roads_id (str, default: 'ultimo_id' ) –

    column name for id in self.network

  • roads_fr (str, default: 'from_node' ) –

    column name for the start node in self.network

  • roads_to (str, default: 'to_node' ) –

    column name for the destination node in self.network

  • node_id (str, default: 'node_id' ) –

    column name for id in nodes

  • node_geo (str, default: 'geometry' ) –

    column name for geometry in nodes

Returns:
  • None

ultimodel.CreateNetwork.ckdnearest(gdA, gdB, bcolA, bcolB, n)

Find n number of nearest nodes from gdA to gdB and calculate their distance

Parameters:
  • gdA (gpd.GeoDataFrame) –

    Nodes A, Point geometry; find n nearest points in gdB for all points in gdA

  • gdB (gpd.GeoDataFrame) –

    Nodes B, Point geometry; contains nodes that are assigned to gdA

  • bcolA (str) –

    name of ID column in gdA

  • bcolB (str) –

    name of ID column in gdB

  • n (int) –

    number of nearest nodes to find per node from gdA

Returns:
  • pd.DataFrame with all nodes from gdA, the IDs of their n nearest nodes from gdB and their distances

ultimodel.CreateNetwork.graph_from_gdf(nodes, edges, node_id='node_id', node_geo='geometry', edge_id='edge_id', edge_from='from_node', edge_to='to_node')

Create a MultiDiGraph from nodes and edges in the GeoDataFrame format

Parameters:
  • nodes (gpd.GeoDataFrame) –

    Nodes, include id

  • edges (gpd.GeoDataFrame) –

    Edges, include id, from node id and to node id (directed)

  • node_id (str, default: 'node_id' ) –

    id column in nodes

  • node_geo (str, default: 'geometry' ) –

    geometry column in nodes

  • edge_id (str, default: 'edge_id' ) –

    id column in edges

  • edge_from (str, default: 'from_node' ) –

    from node column in edges

  • edge_to (str, default: 'to_node' ) –

    to node column in edges

Returns:
  • MultiDiGraph

    MultiDiGraph

ultimodel.CreateNetwork.subordinate_road_length(taz_sub, sub_type='secondary')

Calculate the subordinate network length per TAZ for a selected category

Parameters:
  • taz_sub (gpd.GeoDataFrame) –

    TAZ GeoDataFrame

  • sub_type (str, default: 'secondary' ) –

    highway type for subordinate network

Returns:
  • gpd.GeoDataFrame

    GeoDataFrame with aggregated network length per TAZ