-
Notifications
You must be signed in to change notification settings - Fork 0
/
CZML_builder.py
103 lines (97 loc) · 3.32 KB
/
CZML_builder.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import json
path_outline_width = 3
path_width = 3
path_lead_time = 0
path_trail_time = 100000
path_resolution = 5
point_outline_width = 2
point_pixel_size = 6
point_height_reference = "NONE"
m1_color = [255, 102, 0, 150] # orange
m3_color = [0, 153, 255, 150] # blue
color = [m1_color, m3_color]
def get_start_stop(df):
starttime = str(min(df['datetime_begin'])).replace(" ", "T").replace(".000", "Z")
stoptime = str(max(df['datetime_end'])).replace(" ", "T").replace(".000", "Z")
availability = starttime + "/" + stoptime
return (starttime, stoptime, availability)
def get_4D_coords(group):
coords = []
t = 0
for _,row in group.iterrows():
coords.extend([t, row['lon_begin'], row['lat_begin'], row['alt_begin (m)']])
t += row['duration']
return coords
def get_path(group, path_id, starttime, availability, color):
path = {
"id": path_id,
"availability": availability,
"position": {
"epoch": starttime,
"cartographicDegrees": get_4D_coords(group)
},
"path": {
"material": {
"polylineOutline": {
"color": {
"rgba": color
},
"outlineColor": {
"rgba": color
},
"outlineWidth": path_outline_width
}
},
"width": path_width,
"leadTime": path_lead_time,
"trailTime": path_trail_time,
"resolution": path_resolution
}
}
return path
def get_point(group, point_id, starttime, availability, color):
point = {
"id": point_id,
"availability": availability,
"position": {
"epoch": starttime,
"cartographicDegrees": get_4D_coords(group)
},
"point": {
"color": {
"rgba": [255,255,255,200] # white center instead of color
},
"outlineColor": {
"rgba": color
},
"outlineWidth": point_outline_width,
"pixelSize": point_pixel_size,
"heightReference": point_height_reference
}
}
return point
def czml(df_list, file_path, path=True, point=True):
czml_output = []
starttime, _, availability = get_start_stop(df_list[0])
global_element = {
"id": "document",
"name": "m1vsm3",
"version": "1.0",
"author": "your_name", "clock": {"interval": availability,
"currentTime": starttime,
"multiplier": 100
}
}
czml_output.append(global_element)
index = 0
for df in df_list:
for name, group in df.groupby('flight_identifier'):
starttime, _, availability = get_start_stop(group)
name = str(name) + str(index)
if path:
czml_output.append(get_path(group, name, starttime, availability, color[index]))
if point:
czml_output.append(get_point(group, name, starttime, availability, color[index]))
index += 1
with open(file_path, 'w') as outfile:
json.dump(czml_output, outfile)