Spaces:
Runtime error
Runtime error
JanuaryDesk
commited on
Commit
·
9268c51
1
Parent(s):
005a6b1
Add PZC support
Browse files- app.py +29 -16
- lib/JTSParser.dll +0 -0
- requirements.txt +1 -1
app.py
CHANGED
@@ -43,7 +43,7 @@ import os
|
|
43 |
lib_path = os.path.abspath("lib/JTSParser.dll")
|
44 |
|
45 |
Reflection.Assembly.LoadFile(lib_path)
|
46 |
-
import
|
47 |
|
48 |
# App
|
49 |
|
@@ -62,19 +62,26 @@ def dock(x, limit):
|
|
62 |
|
63 |
default_path = "JTS_assets/ridge.map"
|
64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
with gr.Blocks(analytics_enabled=False) as demo:
|
66 |
with gr.Row():
|
67 |
with gr.Column(scale=1):
|
68 |
-
file_input = gr.File(default_path, label="Map File (NB
|
|
|
69 |
labels_checkbox = gr.Checkbox(True, label="Labels")
|
70 |
labels_size_threshold_number = gr.Number(0, label="Label Size Threshold", info="1 => Tactical, 2 => Normal, 3 => Important")
|
71 |
# with gr.Row():
|
72 |
with gr.Accordion("Roads"):
|
73 |
with gr.Row():
|
74 |
-
path_checkbox = gr.Checkbox(label="Path")
|
75 |
-
road_checkbox = gr.Checkbox(label="Road")
|
76 |
-
pike_checkbox = gr.Checkbox(True, label="Pike")
|
77 |
-
railway_checkbox = gr.Checkbox(True, label="
|
78 |
with gr.Row():
|
79 |
road_offset_number = gr.Number(0.3, label="Road Offset")
|
80 |
elevation_scale_number = gr.Number(0.1, label="Elevation Scale")
|
@@ -85,12 +92,15 @@ with gr.Blocks(analytics_enabled=False) as demo:
|
|
85 |
def plot(data):
|
86 |
with open(data[file_input].name) as f:
|
87 |
map_str = f.read()
|
88 |
-
|
89 |
-
|
|
|
|
|
|
|
90 |
height_mat = np.empty([map_file.Height, map_file.Width])
|
91 |
for i in range(map_file.Height):
|
92 |
for j in range(map_file.Width):
|
93 |
-
height_mat[i,j] =
|
94 |
|
95 |
surface = go.Surface(
|
96 |
x = np.arange(map_file.Width),
|
@@ -103,15 +113,18 @@ with gr.Blocks(analytics_enabled=False) as demo:
|
|
103 |
road_offset = data[road_offset_number]
|
104 |
|
105 |
road_items = [
|
106 |
-
(
|
107 |
-
(
|
108 |
-
(
|
109 |
-
(
|
110 |
]
|
111 |
|
112 |
-
for
|
|
|
|
|
|
|
113 |
if data[checkbox]:
|
114 |
-
for road in
|
115 |
x_line = []
|
116 |
y_line = []
|
117 |
z_line = []
|
@@ -178,7 +191,7 @@ with gr.Blocks(analytics_enabled=False) as demo:
|
|
178 |
|
179 |
return {output_plot: fig}
|
180 |
|
181 |
-
plot_button.click(plot, {file_input,
|
182 |
labels_checkbox, labels_size_threshold_number,
|
183 |
path_checkbox, road_checkbox, pike_checkbox, railway_checkbox,
|
184 |
elevation_scale_number, road_offset_number}, {output_plot})
|
|
|
43 |
lib_path = os.path.abspath("lib/JTSParser.dll")
|
44 |
|
45 |
Reflection.Assembly.LoadFile(lib_path)
|
46 |
+
from YYZ import JTS
|
47 |
|
48 |
# App
|
49 |
|
|
|
62 |
|
63 |
default_path = "JTS_assets/ridge.map"
|
64 |
|
65 |
+
road_names_map = {
|
66 |
+
"NB": ["Path", "Road", "Pike", "Rail"],
|
67 |
+
"CWB": ["Trail", "Road", "Pike", "Rail"],
|
68 |
+
"PZC": ["Trail", "Secondary", "Primary", "Rail"]
|
69 |
+
}
|
70 |
+
|
71 |
with gr.Blocks(analytics_enabled=False) as demo:
|
72 |
with gr.Row():
|
73 |
with gr.Column(scale=1):
|
74 |
+
file_input = gr.File(default_path, label="Map File (NB/CWB/PZC)", file_types=[".map"])
|
75 |
+
code_dropdown = gr.Dropdown(choices=["NB", "CWB", "PZC"], value="NB", label="Series")
|
76 |
labels_checkbox = gr.Checkbox(True, label="Labels")
|
77 |
labels_size_threshold_number = gr.Number(0, label="Label Size Threshold", info="1 => Tactical, 2 => Normal, 3 => Important")
|
78 |
# with gr.Row():
|
79 |
with gr.Accordion("Roads"):
|
80 |
with gr.Row():
|
81 |
+
path_checkbox = gr.Checkbox(label="Path/Trail")
|
82 |
+
road_checkbox = gr.Checkbox(label="Road/Secondary")
|
83 |
+
pike_checkbox = gr.Checkbox(True, label="Pike/Primary")
|
84 |
+
railway_checkbox = gr.Checkbox(True, label="Rail")
|
85 |
with gr.Row():
|
86 |
road_offset_number = gr.Number(0.3, label="Road Offset")
|
87 |
elevation_scale_number = gr.Number(0.1, label="Elevation Scale")
|
|
|
92 |
def plot(data):
|
93 |
with open(data[file_input].name) as f:
|
94 |
map_str = f.read()
|
95 |
+
|
96 |
+
code = data[code_dropdown]
|
97 |
+
map_file = JTS.JTSParser.FromCode(code).ParseMap(map_str, False)
|
98 |
+
network = JTS.HexNetwork.FromMapFile(map_file)
|
99 |
+
|
100 |
height_mat = np.empty([map_file.Height, map_file.Width])
|
101 |
for i in range(map_file.Height):
|
102 |
for j in range(map_file.Width):
|
103 |
+
height_mat[i,j] = network.HexMat[i, j].Height
|
104 |
|
105 |
surface = go.Surface(
|
106 |
x = np.arange(map_file.Width),
|
|
|
113 |
road_offset = data[road_offset_number]
|
114 |
|
115 |
road_items = [
|
116 |
+
(path_checkbox, 'gray'),
|
117 |
+
(road_checkbox, 'green'),
|
118 |
+
(pike_checkbox, 'pink'),
|
119 |
+
(railway_checkbox, 'black')
|
120 |
]
|
121 |
|
122 |
+
for road_idx, (checkbox, color) in enumerate(road_items):
|
123 |
+
road_name = road_names_map[code][road_idx]
|
124 |
+
road_type = map_file.CurrentTerrainSystem.Road.GetValue(road_name)
|
125 |
+
|
126 |
if data[checkbox]:
|
127 |
+
for road in network.SimplifyRoad(road_type):
|
128 |
x_line = []
|
129 |
y_line = []
|
130 |
z_line = []
|
|
|
191 |
|
192 |
return {output_plot: fig}
|
193 |
|
194 |
+
plot_button.click(plot, {file_input, code_dropdown,
|
195 |
labels_checkbox, labels_size_threshold_number,
|
196 |
path_checkbox, road_checkbox, pike_checkbox, railway_checkbox,
|
197 |
elevation_scale_number, road_offset_number}, {output_plot})
|
lib/JTSParser.dll
CHANGED
Binary files a/lib/JTSParser.dll and b/lib/JTSParser.dll differ
|
|
requirements.txt
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
-
plotly
|
2 |
numpy
|
3 |
pythonnet
|
|
|
1 |
+
plotly
|
2 |
numpy
|
3 |
pythonnet
|