Skip to content
Snippets Groups Projects
Commit 88cb2040 authored by Pedro L. Magalhães's avatar Pedro L. Magalhães
Browse files

Added a method for creating edge geometries.

parent 112a6490
Branches
No related tags found
1 merge request!6Stats
......@@ -11,7 +11,7 @@ from networkx import MultiDiGraph, MultiGraph
from pandas import MultiIndex, Series
from numpy import float64, int64
from geopandas import GeoDataFrame, read_file
from shapely.geometry import Point
from shapely.geometry import Point, LineString
import contextily as cx
# local, internal
......@@ -1229,6 +1229,18 @@ def convert_edge_path(
# return statement
return node_path
# *****************************************************************************
# *****************************************************************************
def create_edge_geometry(network: MultiDiGraph, edge_key) -> LineString:
"Returns a newly-created geometry for a given edge."
return LineString(
[(network.nodes[edge_key[0]][osm.KEY_OSMNX_X],
network.nodes[edge_key[0]][osm.KEY_OSMNX_Y]),
(network.nodes[edge_key[1]][osm.KEY_OSMNX_X],
network.nodes[edge_key[1]][osm.KEY_OSMNX_Y])]
)
# *****************************************************************************
# *****************************************************************************
......@@ -18,47 +18,6 @@ from .network import Network
# *****************************************************************************
# *****************************************************************************
def review_final_network(network: Network):
# check that the network topology is a tree
if network.has_tree_topology():
print("The network has a tree topology.")
else:
print("The network does not have a tree topology.")
# check the existence of forward and reverse arcs between the same nodes
has_forward_reverse_arcs(network, print_result=True)
# *****************************************************************************
# *****************************************************************************
def has_forward_reverse_arcs(network: Network, print_result: bool = True) -> bool:
"""Returns True if there are simultaneous forward and reverse arcs."""
# check the existence of forward and reverse arcs in the same segment
forward_reverse_arcs = [ # get the arcs selected
arc_key[0:2]
for arc_key in network.edges(keys=True)
if True in network.edges[arc_key][Network.KEY_ARC_TECH].options_selected
]
forward_reverse_arcs = [ # get the selected arcs that exist both ways
arc_key
for arc_key in forward_reverse_arcs
if (arc_key[1], arc_key[0]) in forward_reverse_arcs
]
if print_result:
if len(forward_reverse_arcs) == 0:
print(
"The network has no forward and reverse arcs in" + " the same segment."
)
else:
print("The network has forward and reverse arcs in" + " the same segment.")
# *****************************************************************************
# *****************************************************************************
def run_mvesipp_analysis(
problem: InfrastructurePlanningProblem = None,
......
......@@ -12,6 +12,7 @@ from pandas import concat, MultiIndex, Series
import networkx as nx
import osmnx as ox
from shapely.geometry import Point, LineString
from shapely import intersects
# local, internal
......@@ -2643,6 +2644,23 @@ class TestGisUtils:
# *************************************************************************
# *************************************************************************
def test_create_edge_geometry(self):
G = nx.MultiDiGraph()
edge_key = (0, 1)
G.add_node(0, x=0, y=0)
G.add_node(1, x=1, y=1)
G.add_edge(0, 1, length=2**0.5)
first_geo = gis_utils.create_edge_geometry(G, edge_key)
edge_key = (2, 3)
G.add_node(2, x=0, y=1)
G.add_node(3, x=1, y=0)
G.add_edge(2, 3, length=2**0.5)
second_geo = gis_utils.create_edge_geometry(G, edge_key)
assert intersects(first_geo, second_geo)
# *************************************************************************
# *************************************************************************
# *****************************************************************************
# *****************************************************************************
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment