Skip to content

Commit f7e4e7b

Browse files
committed
Dialog box added to visualizer.
1 parent dca6bab commit f7e4e7b

File tree

1 file changed

+68
-4
lines changed

1 file changed

+68
-4
lines changed

Tools/graphMLVis/visualize_graphML.py

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,73 @@
66
from shapely.ops import unary_union
77
from shapely.geometry import Polygon
88
import math
9+
import os
10+
from tkinter import *
11+
from tkinter import filedialog
12+
13+
# start of dialog box
14+
window = Tk()
15+
16+
# variables acquired through dialog box
17+
class Paths:
18+
def __init__(self, graphml_path, node_type):
19+
self.graphml_path, self.node_type = graphml_path, node_type
20+
21+
def changegraphml(self, path):
22+
self.graphml_path = os.path.normpath(path)
23+
24+
def changenodetype(self):
25+
self.node_type = radio_var.get()
26+
27+
dVars = Paths(os.path.normpath("Tools\gis2graph\graph_files\King_county_NG911.graphml"), "EMS")
28+
29+
# submit button logic
30+
def submit():
31+
dVars.changegraphml(fEntry0.get())
32+
window.destroy()
33+
34+
# file selecting button logic
35+
def buttonSelect():
36+
file_path = filedialog.askopenfilename()
37+
fEntry0.delete(0, END)
38+
fEntry0.insert(0, os.path.normpath(file_path))
39+
40+
# dialog box title
41+
window.title("Visualizer Setup")
42+
43+
# first file selecting row for .graphml file to load
44+
fLabel0 = Label(window, text="Select .graphml File to Visualize: ")
45+
fLabel0.grid(row=0, column=0)
46+
fEntry0 = Entry(window, width=55)
47+
fEntry0.grid(row=0, column=1)
48+
fEntry0.insert(0, os.path.normpath("Tools\gis2graph\graph_files\King_county_NG911.graphml"))
49+
fButton0 = Button(window, text="Select File", command=buttonSelect)
50+
fButton0.grid(row=0, column=2)
51+
52+
# radio buttons for node type to visualize
53+
radio_var = StringVar()
54+
rLabel = Label(window, text="Select which node type to visualize.")
55+
rLabel.grid(row=3, column=0)
56+
typeRB1 = Radiobutton(window, text="EMS", variable=radio_var, value="EMS", command=dVars.changenodetype)
57+
typeRB1.grid(row=4, column=0)
58+
typeRB2 = Radiobutton(window, text="FIRE", variable=radio_var, value="FIRE", command=dVars.changenodetype)
59+
typeRB2.grid(row=4, column=1)
60+
typeRB3 = Radiobutton(window, text="LAW", variable=radio_var, value="LAW", command=dVars.changenodetype)
61+
typeRB3.grid(row=4, column=2)
62+
typeRB1.deselect()
63+
typeRB2.deselect()
64+
typeRB3.deselect()
65+
typeRB1.select()
66+
67+
# submit button
68+
submitB = Button(window, text="Submit", command=submit)
69+
submitB.grid(row=5, column=1)
70+
71+
window.mainloop()
72+
973

1074
# Load data from XML
11-
tree = ET.parse('Tools\gis2graph\graph_files\King_county_NG911.graphml')
75+
tree = ET.parse(dVars.graphml_path)
1276
root = tree.getroot()
1377

1478
# Initialize the network graph
@@ -31,8 +95,8 @@
3195

3296
square_counter = 0
3397

34-
psap_layer = gpd.read_file("Tools\gis2graph\GIS_data\Layers\PSAP_layer.gpkg")
35-
provisioning_layer = gpd.read_file("Tools\gis2graph\GIS_data\Layers\Provisioning_layer.gpkg")
98+
psap_layer = gpd.read_file(os.path.normpath("Tools\gis2graph\GIS_data\Layers\PSAP_layer.gpkg"))
99+
provisioning_layer = gpd.read_file(os.path.normpath("Tools\gis2graph\GIS_data\Layers\Provisioning_layer.gpkg"))
36100

37101
# create series of boolean values denoting whether geometry is within King County
38102
psap_within_kc = psap_layer.within(provisioning_layer.iloc[21].geometry)
@@ -105,7 +169,7 @@
105169
G.nodes[node_id]['pos'] = (node_x, node_y)
106170
G.nodes[node_id]['color'] = 'cyan'
107171
#change EMS with FIRE or LAW to see fire/police nodes
108-
elif type_element is not None and type_element.text == 'EMS':
172+
elif type_element is not None and type_element.text == dVars.node_type:
109173
node_id = node.get('id')
110174

111175
for data in node.findall(f'.//{{{nsmap["xmlns"]}}}data', namespaces = nsmap):

0 commit comments

Comments
 (0)