-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdict2djikml.py
executable file
·194 lines (170 loc) · 7.46 KB
/
dict2djikml.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
from string import Template
import sys
from waypoint import WayPoint
def dict2djikml (dic,output_filename,reverse_coordonates_transformer,
altitude,onfinish='hover',speed = 5,turnmode = 'Auto',
over_time_before_picture=0):
extra_points=[]
if onfinish == 'hover':
ON_FINISH = "Hover"
elif onfinish == 'gohome':
ON_FINISH = "GoHome"
elif onfinish == 'autoland':
ON_FINISH = "AutoLand"
elif onfinish == 'gofirstpoint':
ON_FINISH = "GoFirstPoint"
else:
sys.exit('onfinish shoud be hover or gohome')
XML_string = """<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document xmlns="">
<name>Path</name>
<open>1</open>
<ExtendedData xmlns:mis="www.dji.com">
<mis:type>Waypoint</mis:type>
<mis:stationType>0</mis:stationType>
</ExtendedData>
<Style id="waylineGreenPoly">
<LineStyle>
<color>FF0AEE8B</color>
<width>6</width>
</LineStyle>
</Style>
<Style id="waypointStyle">
<IconStyle>
<Icon>
<href>https://cdnen.dji-flighthub.com/static/app/images/point.png</href>
</Icon>
</IconStyle>
</Style>
<Folder>
<name>Waypoints</name>
<description>Waypoints in the Mission.</description>\n"""
#name = None
#lon = None
#lat = None
#height = None
#heading = None
##gimbal = None
all_coordinates = ""
#waypoint_number = 1
waypoint_start = Template(""" <Placemark>
<name>Waypoint$waypoint_number</name>
<visibility>1</visibility>
<description>Waypoint</description>
<styleUrl>#waypointStyle</styleUrl>
<ExtendedData xmlns:mis="www.dji.com">
<mis:useWaylineAltitude>false</mis:useWaylineAltitude>
<mis:heading>$heading</mis:heading>
<mis:turnMode>$turnmode</mis:turnMode>
<mis:gimbalPitch>$gimbal</mis:gimbalPitch>
<mis:useWaylineSpeed>false</mis:useWaylineSpeed>
<mis:speed>$speed</mis:speed>
<mis:useWaylineHeadingMode>true</mis:useWaylineHeadingMode>
<mis:useWaylinePointType>true</mis:useWaylinePointType>
<mis:pointType>LineStop</mis:pointType>
<mis:cornerRadius>0.2</mis:cornerRadius>""")
waypoint_end = Template("""
</ExtendedData>
<Point>
<altitudeMode>relativeToGround</altitudeMode>
<coordinates>$lon,$lat,$height</coordinates>
</Point>
</Placemark>""")
hover_template = Template("""
<mis:actions param="$over_time_before_picture" accuracy="0" cameraIndex="0" payloadType="0" payloadIndex="0">Hovering</mis:actions>""")
shoot_template = Template("""
<mis:actions param="0" accuracy="0" cameraIndex="0" payloadType="0" payloadIndex="0">ShootPhoto</mis:actions>""")
shoot_str = """
<mis:actions param="0" accuracy="0" cameraIndex="0" payloadType="0" payloadIndex="0">ShootPhoto</mis:actions>"""
gimbal_template = Template("""
<mis:actions param="$gimbal_angle" accuracy="1" cameraIndex="0" payloadType="0" payloadIndex="0">GimbalPitch</mis:actions>""")
aircraftyaw_template = Template("""
<mis:actions param="$aircraftyaw" accuracy="0" cameraIndex="0" payloadType="0" payloadIndex="0">AircraftYaw</mis:actions>""")
record_template = Template("""
<mis:actions param="0" accuracy="0" cameraIndex="0" payloadType="0" payloadIndex="0">StartRecording</mis:actions>""")
stoprecord_template = Template("""
<mis:actions param="0" accuracy="0" cameraIndex="0" payloadType="0" payloadIndex="0">StopRecording</mis:actions>""")
all_coordinates_template = Template("$lon,$lat,$height")
xml_end = Template(""" </Folder>
<Placemark>
<name>Wayline</name>
<description>Wayline</description>
<visibility>1</visibility>
<ExtendedData xmlns:mis="www.dji.com">
<start_altitude>$altitude</start_altitude>
<used_altitude>$altitude</used_altitude>
<mis:altitude>50.0</mis:altitude>
<mis:autoFlightSpeed>5.0</mis:autoFlightSpeed>
<mis:actionOnFinish>$ON_FINISH</mis:actionOnFinish>
<mis:headingMode>UsePointSetting</mis:headingMode>
<mis:gimbalPitchMode>UsePointSetting</mis:gimbalPitchMode>
<mis:powerSaveMode>false</mis:powerSaveMode>
<mis:waypointType>LineStop</mis:waypointType>
<mis:droneInfo>
<mis:droneType>COMMON</mis:droneType>
<mis:advanceSettings>false</mis:advanceSettings>
<mis:droneCameras/>
<mis:droneHeight>
<mis:useAbsolute>false</mis:useAbsolute>
<mis:hasTakeoffHeight>false</mis:hasTakeoffHeight>
<mis:takeoffHeight>0.0</mis:takeoffHeight>
</mis:droneHeight>
</mis:droneInfo>
</ExtendedData>
<styleUrl>#waylineGreenPoly</styleUrl>
<LineString>
<tessellate>1</tessellate>
<altitudeMode>relativeToGround</altitudeMode>
<coordinates>$all_coordinates</coordinates>
</LineString>
</Placemark>
</Document>
</kml>""")
if (speed > 15) or (speed <= 0):
sys.exit('speed should be >0 or <=15 m/s ')
speed=str(speed)
if '.' not in speed:
speed = speed+'.0'
waypoint_nb=0
#print(dic)
for waypoint in dic :
#print(waypoint)
# 'path_name': 'prof1',
# 'path_az': 200.65033592212384,
# 'drone_e': 764492.0107411736,
# 'drone_n': 6362186.929337244,
# 'drone_z': 1262.9225386835942,
# 'drone_pitch': -75.0,
# 'drone_fov_lat': 52.17119955656284,
# 'drone_fov_lon': 36.22411610965541,
# 'drone_az': -45}
name = 'WP_'+str(waypoint_nb)
lat , lon = reverse_coordonates_transformer.transform(waypoint['drone_e'],waypoint['drone_n'])
tmp_extra_point= WayPoint(lat, lon,wp_text=name,alt=str(waypoint['drone_z']))
extra_points.append(tmp_extra_point)
height = waypoint['drone_z']
heading = waypoint['drone_az']
gimbal = waypoint['drone_pitch']
actions_sequence = ON_FINISH
gimbal=str(gimbal)
if '.' not in gimbal:
gimbal = gimbal+'.0'
#print(F'{name}\t{lat}\t{lon}\t{heading}\t{gimbal}')
XML_string += waypoint_start.substitute(
turnmode=turnmode, waypoint_number=waypoint_nb,
speed=speed, heading=heading, gimbal=gimbal)
if over_time_before_picture > 0:
XML_string += hover_template.substitute(over_time_before_picture=over_time_before_picture)
XML_string += shoot_str
XML_string += waypoint_end.substitute(lon=lon, lat=lat, height=height,)+"\n"
all_coordinates += all_coordinates_template.substitute(
lon=lon, lat=lat, height=height)+" "
waypoint_nb += 1
# remove last space from coordinates string
all_coordinates = all_coordinates[:-1]
XML_string += xml_end.substitute(all_coordinates=all_coordinates,
ON_FINISH=ON_FINISH, altitude=altitude)
with open(output_filename, 'w',encoding="utf-8") as output_file:
output_file.write(XML_string)
return extra_points