Spaces:
Runtime error
Runtime error
Commit
·
052a6c6
1
Parent(s):
fef059a
init
Browse files- .gitignore +1 -0
- JTS_assets/ridge.map +241 -0
- README.md +2 -2
- app.py +217 -0
- lib/JTSParser.dll +0 -0
- lib/JTSParser.runtimeconfig.json +9 -0
- requirements.txt +3 -0
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
__pycache__/
|
JTS_assets/ridge.map
ADDED
@@ -0,0 +1,241 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
2
|
2 |
+
32 22
|
3 |
+
50 10 0 12931 0
|
4 |
+
ceeeee evo e
|
5 |
+
e e e ff eeee eee
|
6 |
+
f eeeee eee
|
7 |
+
f e eee
|
8 |
+
o
|
9 |
+
oo c
|
10 |
+
e oc
|
11 |
+
f eeeeeee vv
|
12 |
+
eee r e ve
|
13 |
+
eeee eee
|
14 |
+
eeeeec e e eeee
|
15 |
+
eeeeee o e eeeeee eee
|
16 |
+
eeee o eeeeeee e
|
17 |
+
eee eee eeeee e f
|
18 |
+
e eeee eeee f
|
19 |
+
oee eee eeeee
|
20 |
+
eeee eeee
|
21 |
+
e e eee
|
22 |
+
eeeee e
|
23 |
+
eeeeee v e e
|
24 |
+
eeeeee v eeeee e
|
25 |
+
eeeev eeeeee eee
|
26 |
+
76666777776665666666766677777767
|
27 |
+
76767777766666766676776777776667
|
28 |
+
77767777766677666677777777676667
|
29 |
+
77767777766667667787777777766566
|
30 |
+
77777777767666777787777777765556
|
31 |
+
87777787777777778877676667665556
|
32 |
+
78888888887777777766666666665445
|
33 |
+
77788888887777666666665555555454
|
34 |
+
77889988777666666655555555655565
|
35 |
+
77889877766666666666665566656666
|
36 |
+
88888887766677777676666666666666
|
37 |
+
88778887666677777777667776766666
|
38 |
+
77778877766677777776677777766655
|
39 |
+
77778777777787777766777777665555
|
40 |
+
77778877778877666667777766665565
|
41 |
+
77778887778877767677777666665665
|
42 |
+
77778878888787778777776666655666
|
43 |
+
88887777888877888777666666666676
|
44 |
+
88777787888888887766777666667777
|
45 |
+
77777788888888877777776677667777
|
46 |
+
66777778888899877888766677667777
|
47 |
+
77777777778899878877767677777777
|
48 |
+
1
|
49 |
+
B @ ! %
|
50 |
+
4
|
51 |
+
"2 DB4D 4
|
52 |
+
B DD
|
53 |
+
@ (
|
54 |
+
$D !
|
55 |
+
DB4D (
|
56 |
+
DB4T 1
|
57 |
+
22 B$
|
58 |
+
"2 DD
|
59 |
+
D
|
60 |
+
|
61 |
+
|
62 |
+
(
|
63 |
+
1
|
64 |
+
|
65 |
+
0
|
66 |
+
|
67 |
+
|
68 |
+
B4D (
|
69 |
+
DD %
|
70 |
+
DD DL
|
71 |
+
1
|
72 |
+
% 22 DH
|
73 |
+
ND %
|
74 |
+
21 H D
|
75 |
+
4 26H %D
|
76 |
+
22 B % H22
|
77 |
+
D 24B2 DH +
|
78 |
+
DD 4 24B2 % )4
|
79 |
+
DR4B2 B DJ3 B
|
80 |
+
*2 )
|
81 |
+
1 1
|
82 |
+
22 * *
|
83 |
+
*1 *1
|
84 |
+
1 1
|
85 |
+
D 22 *
|
86 |
+
DD 22 *1
|
87 |
+
DH 22 1
|
88 |
+
% 22 *2
|
89 |
+
DD 22 )
|
90 |
+
DD 22 1
|
91 |
+
DD 22 *
|
92 |
+
B )
|
93 |
+
*1 22
|
94 |
+
1
|
95 |
+
* )
|
96 |
+
*1 )
|
97 |
+
1 %
|
98 |
+
* H
|
99 |
+
*1 )
|
100 |
+
1 %H
|
101 |
+
)
|
102 |
+
)
|
103 |
+
)
|
104 |
+
)
|
105 |
+
)
|
106 |
+
)
|
107 |
+
)
|
108 |
+
)
|
109 |
+
)
|
110 |
+
)
|
111 |
+
)
|
112 |
+
%
|
113 |
+
H
|
114 |
+
)
|
115 |
+
)
|
116 |
+
)
|
117 |
+
0
|
118 |
+
1
|
119 |
+
|
120 |
+
|
121 |
+
|
122 |
+
|
123 |
+
|
124 |
+
|
125 |
+
(
|
126 |
+
#8
|
127 |
+
!
|
128 |
+
|
129 |
+
|
130 |
+
|
131 |
+
|
132 |
+
|
133 |
+
|
134 |
+
|
135 |
+
|
136 |
+
|
137 |
+
|
138 |
+
|
139 |
+
|
140 |
+
|
141 |
+
0
|
142 |
+
1
|
143 |
+
$L,B84
|
144 |
+
9A 'ZX
|
145 |
+
,.G0 "#9
|
146 |
+
( ( !A"X8 !
|
147 |
+
, ,,M,A $/G0$(
|
148 |
+
$,MH=MAA &Q"P A
|
149 |
+
(<MAC!A (8 "P
|
150 |
+
+!A ##8< (
|
151 |
+
! ,/MLA
|
152 |
+
$]MAA
|
153 |
+
$ 0 "!A
|
154 |
+
&VP
|
155 |
+
"^@
|
156 |
+
!
|
157 |
+
(
|
158 |
+
/0
|
159 |
+
'P
|
160 |
+
.X0
|
161 |
+
!GP
|
162 |
+
,.@
|
163 |
+
!A
|
164 |
+
|
165 |
+
1
|
166 |
+
"<@
|
167 |
+
!
|
168 |
+
|
169 |
+
|
170 |
+
|
171 |
+
($^0
|
172 |
+
$W2!@
|
173 |
+
" @
|
174 |
+
$(0
|
175 |
+
&W@
|
176 |
+
"\@
|
177 |
+
!
|
178 |
+
|
179 |
+
|
180 |
+
|
181 |
+
|
182 |
+
|
183 |
+
|
184 |
+
|
185 |
+
|
186 |
+
|
187 |
+
|
188 |
+
1
|
189 |
+
4 (6
|
190 |
+
UN * Z
|
191 |
+
7 9
|
192 |
+
Z;
|
193 |
+
M 7
|
194 |
+
(6 MH=M ;7 P
|
195 |
+
( DC%M Z
|
196 |
+
,(!D =V 0 ,
|
197 |
+
V
|
198 |
+
N
|
199 |
+
U
|
200 |
+
N
|
201 |
+
|
202 |
+
V
|
203 |
+
V
|
204 |
+
V
|
205 |
+
V
|
206 |
+
Z
|
207 |
+
3
|
208 |
+
|
209 |
+
!A
|
210 |
+
3#
|
211 |
+
0
|
212 |
+
1
|
213 |
+
|
214 |
+
|
215 |
+
|
216 |
+
|
217 |
+
(
|
218 |
+
!
|
219 |
+
(
|
220 |
+
!
|
221 |
+
|
222 |
+
0
|
223 |
+
"
|
224 |
+
|
225 |
+
|
226 |
+
|
227 |
+
|
228 |
+
|
229 |
+
|
230 |
+
|
231 |
+
|
232 |
+
|
233 |
+
|
234 |
+
|
235 |
+
0
|
236 |
+
12.385 20.5333 1 0 0 La Belle Alliance
|
237 |
+
30.423 5.4333 1 0 0 La Haye
|
238 |
+
9.615 10.4333 1 0 0 La Haye-Sainte
|
239 |
+
9.846 0.5333 1 0 0 Mont-St.-Jean Farm
|
240 |
+
28.577 6.5667 1 0 0 Papelotte
|
241 |
+
11.692 8.6 1 0 0 The Sand Pit
|
README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
---
|
2 |
title: JTS3DMap
|
3 |
emoji: 📚
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
sdk_version: 3.35.2
|
8 |
app_file: app.py
|
|
|
1 |
---
|
2 |
title: JTS3DMap
|
3 |
emoji: 📚
|
4 |
+
colorFrom: red
|
5 |
+
colorTo: blue
|
6 |
sdk: gradio
|
7 |
sdk_version: 3.35.2
|
8 |
app_file: app.py
|
app.py
ADDED
@@ -0,0 +1,217 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
from pythonnet import load
|
4 |
+
|
5 |
+
load("coreclr", runtime_config="lib\JTSParser.runtimeconfig.json")
|
6 |
+
|
7 |
+
import clr
|
8 |
+
from System import Reflection
|
9 |
+
|
10 |
+
import os
|
11 |
+
|
12 |
+
lib_path = os.path.abspath("lib\JTSParser.dll")
|
13 |
+
|
14 |
+
Reflection.Assembly.LoadFile(lib_path)
|
15 |
+
import YYZ.JTS.NB
|
16 |
+
|
17 |
+
import numpy as np
|
18 |
+
import plotly.graph_objects as go
|
19 |
+
import math
|
20 |
+
|
21 |
+
"""
|
22 |
+
def greet(name):
|
23 |
+
return "Hello " + name + "!"
|
24 |
+
|
25 |
+
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
26 |
+
"""
|
27 |
+
|
28 |
+
def test():
|
29 |
+
fig = go.Figure()
|
30 |
+
|
31 |
+
fig.add_trace(go.Scatter3d(
|
32 |
+
x=["2017-01-01", "2017-02-10", "2017-03-20"],
|
33 |
+
y=["A", "B", "C"],
|
34 |
+
z=[1, 1000, 100000],
|
35 |
+
name="z",
|
36 |
+
))
|
37 |
+
|
38 |
+
fig.update_layout(
|
39 |
+
scene=dict(
|
40 |
+
xaxis=dict(type="date"),
|
41 |
+
yaxis=dict(type="category"),
|
42 |
+
zaxis=dict(type="log"),
|
43 |
+
annotations=[
|
44 |
+
dict(
|
45 |
+
showarrow=False,
|
46 |
+
x="2017-01-01",
|
47 |
+
y="A",
|
48 |
+
z=0,
|
49 |
+
text="Point 1",
|
50 |
+
xanchor="left",
|
51 |
+
xshift=10,
|
52 |
+
opacity=0.7),
|
53 |
+
dict(
|
54 |
+
x="2017-02-10",
|
55 |
+
y="B",
|
56 |
+
z=4,
|
57 |
+
text="Point 2",
|
58 |
+
textangle=0,
|
59 |
+
ax=0,
|
60 |
+
ay=-75,
|
61 |
+
font=dict(
|
62 |
+
color="black",
|
63 |
+
size=12
|
64 |
+
),
|
65 |
+
arrowcolor="black",
|
66 |
+
arrowsize=3,
|
67 |
+
arrowwidth=1,
|
68 |
+
arrowhead=1),
|
69 |
+
dict(
|
70 |
+
x="2017-03-20",
|
71 |
+
y="C",
|
72 |
+
z=5,
|
73 |
+
ax=50,
|
74 |
+
ay=0,
|
75 |
+
text="Point 3",
|
76 |
+
arrowhead=1,
|
77 |
+
xanchor="left",
|
78 |
+
yanchor="bottom"
|
79 |
+
)]
|
80 |
+
),
|
81 |
+
)
|
82 |
+
return fig
|
83 |
+
|
84 |
+
|
85 |
+
def dock(x, limit):
|
86 |
+
x1 = math.floor(x)
|
87 |
+
yield x1
|
88 |
+
x2 = min(math.ceil(x), limit)
|
89 |
+
if x2 != x1:
|
90 |
+
yield x2
|
91 |
+
|
92 |
+
default_path = "JTS_assets/ridge.map"
|
93 |
+
|
94 |
+
with gr.Blocks(analytics_enabled=False) as demo:
|
95 |
+
with gr.Row():
|
96 |
+
with gr.Column(scale=1):
|
97 |
+
file_input = gr.File(default_path, label="Map File (NB or CWB)", file_types=[".map"])
|
98 |
+
labels_checkbox = gr.Checkbox(True, label="Labels")
|
99 |
+
labels_size_threshold_number = gr.Number(0, label="Label Size Threshold", info="1 => Tactical, 2 => Normal, 3 => Important")
|
100 |
+
# with gr.Row():
|
101 |
+
with gr.Accordion("Roads"):
|
102 |
+
with gr.Row():
|
103 |
+
path_checkbox = gr.Checkbox(label="Path")
|
104 |
+
road_checkbox = gr.Checkbox(label="Road")
|
105 |
+
pike_checkbox = gr.Checkbox(True, label="Pike")
|
106 |
+
railway_checkbox = gr.Checkbox(True, label="Railway")
|
107 |
+
with gr.Row():
|
108 |
+
road_offset_number = gr.Number(0.3, label="Road Offset")
|
109 |
+
elevation_scale_number = gr.Number(0.1, label="Elevation Scale")
|
110 |
+
plot_button = gr.Button("Plot")
|
111 |
+
with gr.Column(scale=2):
|
112 |
+
output_plot = gr.Plot()
|
113 |
+
|
114 |
+
def plot(data):
|
115 |
+
with open(data[file_input].name) as f:
|
116 |
+
map_str = f.read()
|
117 |
+
map_file = YYZ.JTS.NB.MapFile.Parse(map_str)
|
118 |
+
graph = YYZ.JTS.NB.InfantryColumnGraph.FromMapFile(map_file)
|
119 |
+
height_mat = np.empty([map_file.Height, map_file.Width])
|
120 |
+
for i in range(map_file.Height):
|
121 |
+
for j in range(map_file.Width):
|
122 |
+
height_mat[i,j] = graph.HexMat[i, j].Height
|
123 |
+
|
124 |
+
surface = go.Surface(
|
125 |
+
x = np.arange(map_file.Width),
|
126 |
+
y = np.arange(map_file.Height),
|
127 |
+
z = height_mat
|
128 |
+
)
|
129 |
+
|
130 |
+
gl = []
|
131 |
+
|
132 |
+
road_offset = data[road_offset_number]
|
133 |
+
|
134 |
+
road_items = [
|
135 |
+
(YYZ.JTS.NB.RoadType.Path, path_checkbox, 'gray'),
|
136 |
+
(YYZ.JTS.NB.RoadType.Road, road_checkbox, 'green'),
|
137 |
+
(YYZ.JTS.NB.RoadType.Pike, pike_checkbox, 'pink'),
|
138 |
+
(YYZ.JTS.NB.RoadType.Railway, railway_checkbox, 'black')
|
139 |
+
]
|
140 |
+
|
141 |
+
for road_type, checkbox, color in road_items:
|
142 |
+
if data[checkbox]:
|
143 |
+
for road in graph.SimplifyRoad(road_type):
|
144 |
+
x_line = []
|
145 |
+
y_line = []
|
146 |
+
z_line = []
|
147 |
+
|
148 |
+
for node in road:
|
149 |
+
x_line.append(node.X)
|
150 |
+
y_line.append(node.Y)
|
151 |
+
z_line.append(node.Height + road_offset)
|
152 |
+
|
153 |
+
g = go.Scatter3d(
|
154 |
+
x=x_line, y=y_line, z=z_line,
|
155 |
+
line=dict(
|
156 |
+
color=color,
|
157 |
+
width=2
|
158 |
+
)
|
159 |
+
)
|
160 |
+
|
161 |
+
gl.append(g)
|
162 |
+
|
163 |
+
fig = go.Figure([surface] + gl)
|
164 |
+
|
165 |
+
|
166 |
+
scene = {
|
167 |
+
"aspectratio": {"x": 1, "y": 1, "z": data[elevation_scale_number]},
|
168 |
+
'yaxis': {'autorange': 'reversed'},
|
169 |
+
}
|
170 |
+
|
171 |
+
if data[labels_checkbox]:
|
172 |
+
|
173 |
+
labels_x = []
|
174 |
+
labels_y = []
|
175 |
+
labels_z = []
|
176 |
+
labels_text = []
|
177 |
+
|
178 |
+
for label in map_file.Labels:
|
179 |
+
if label.Size >= data[labels_size_threshold_number]:
|
180 |
+
max_height = -1
|
181 |
+
x = label.X
|
182 |
+
y = label.Y
|
183 |
+
for dx in dock(x, map_file.Width-1):
|
184 |
+
for dy in dock(y, map_file.Height-1):
|
185 |
+
max_height = max(max_height, map_file.HeightMap[dy, dx])
|
186 |
+
labels_x.append(x)
|
187 |
+
labels_y.append(y)
|
188 |
+
labels_z.append(max_height)
|
189 |
+
labels_text.append(label.Name)
|
190 |
+
|
191 |
+
scene["annotations"] = [
|
192 |
+
dict(
|
193 |
+
showarrow=False,
|
194 |
+
x=x,
|
195 |
+
y=y,
|
196 |
+
z=z,
|
197 |
+
text=text,
|
198 |
+
xanchor="left",
|
199 |
+
xshift=10,
|
200 |
+
opacity=0.7,
|
201 |
+
bgcolor="white"
|
202 |
+
)
|
203 |
+
for x, y, z, text in zip(labels_x, labels_y, labels_z, labels_text)
|
204 |
+
]
|
205 |
+
|
206 |
+
fig.update_layout(scene=scene, showlegend=False)
|
207 |
+
|
208 |
+
return {output_plot: fig}
|
209 |
+
|
210 |
+
plot_button.click(plot, {file_input,
|
211 |
+
labels_checkbox, labels_size_threshold_number,
|
212 |
+
path_checkbox, road_checkbox, pike_checkbox, railway_checkbox,
|
213 |
+
elevation_scale_number, road_offset_number}, {output_plot})
|
214 |
+
# plot_button.click(lambda data: {output_img: test()}, {file_input, path_checkbox, road_checkbox, pike_checkbox, plot_button}, {output_img})
|
215 |
+
|
216 |
+
if __name__ == "__main__":
|
217 |
+
demo.launch()
|
lib/JTSParser.dll
ADDED
Binary file (43.5 kB). View file
|
|
lib/JTSParser.runtimeconfig.json
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"runtimeOptions": {
|
3 |
+
"tfm": "net6.0",
|
4 |
+
"framework": {
|
5 |
+
"name": "Microsoft.NETCore.App",
|
6 |
+
"version": "6.0.0"
|
7 |
+
}
|
8 |
+
}
|
9 |
+
}
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
plotly
|
2 |
+
numpy
|
3 |
+
pythonnet
|