Compare commits

...

2 Commits

Author SHA1 Message Date
Majid Rezaei
af33e81474 Merge remote-tracking branch 'origin/node-and-edges-names' into node-and-edges-names
# Conflicts:
#	DistrictHeatingNetworkCreator.py
2024-01-25 17:05:39 -05:00
majidr
69ca73ddf4 nodes and edges names 2024-01-25 17:02:53 -05:00

View File

@ -125,48 +125,36 @@ class DistrictHeatingNetworkCreator:
"""
G = nx.Graph()
# Initialize counters for buildings and junctions
# Add building nodes
building_idx = 1
junction_idx = 1
# Dictionary to hold node labels and their corresponding positions
node_positions = {}
# Add building nodes with proper naming and position attributes
for centroid in self.centroids_gdf.geometry:
node_label = f"Building_{building_idx}"
G.add_node(node_label, pos=(centroid.x, centroid.y), type='building')
node_positions[node_label] = (centroid.x, centroid.y)
label = f"Building_{building_idx}"
G.add_node(label, pos=(centroid.x, centroid.y), type='building')
building_idx += 1
# Add junction nodes from the nearest points with proper naming and position attributes
for point in self.nearest_points:
node_label = f"Junction_{junction_idx}"
G.add_node(node_label, pos=(point.x, point.y), type='junction')
node_positions[node_label] = (point.x, point.y)
junction_idx += 1
# Add additional junction nodes for points along the LineStrings
for line in self.gdf_clean.geometry:
# Add junction nodes for the points along the line strings
junction_idx = 1
junction_positions = {} # To keep track of junction positions
for line in self.gdf_cleanest.geometry:
for point in line.coords:
point_obj = Point(point)
# Check if the point is not already added as a junction or building
if point_obj not in node_positions.values():
node_label = f"Junction_{junction_idx}"
G.add_node(node_label, pos=(point_obj.x, point_obj.y), type='junction')
node_positions[node_label] = (point_obj.x, point_obj.y)
if point_obj not in junction_positions:
label = f"Junction_{junction_idx}"
G.add_node(label, pos=(point_obj.x, point_obj.y), type='junction')
junction_positions[point_obj] = label
junction_idx += 1
# Add edges with lengths as weights for the road network
# Add edges
for line in self.gdf_cleanest.geometry:
# Create edges between the nodes of the LineString
points = list(line.coords)
for start, end in zip(points[:-1], points[1:]):
start_node = [label for label, pos in node_positions.items() if pos == start][0]
end_node = [label for label, pos in node_positions.items() if pos == end][0]
G.add_edge(start_node, end_node, weight=LineString([start, end]).length)
start_point_obj = Point(start)
end_point_obj = Point(end)
start_label = junction_positions.get(start_point_obj)
end_label = junction_positions.get(end_point_obj)
if start_label and end_label:
G.add_edge(start_label, end_label, weight=LineString([start, end]).length)
# Return the graph
return G
def plot_network_graph(self, network_graph):