diff --git a/scripts/geolocation-logs-to-kml.py b/scripts/geolocation-logs-to-kml.py new file mode 100644 index 00000000..cc54281b --- /dev/null +++ b/scripts/geolocation-logs-to-kml.py @@ -0,0 +1,186 @@ +""" +Create KML file from geolocation logs. +""" + +from modules.common.mavlink.modules import drone_odometry +from modules.common.kml.modules import ground_locations_to_kml +from modules import drone_odometry_local +from modules.flight_interface import local_global_conversion +from modules.common.kml.modules import location_ground + + +HOME_LOCATION_LATITUDE = 43.47685623168945 # degrees +HOME_LOCATION_LONGITUDE = -80.56877136230469 # degrees +HOME_LOCATION_ALTITUDE = 348.7200012207031 # metres above sea level + + +def main() -> int: + """ + Main function. + """ + geolocation_coordinates = [ + [10.96412141420508, -1.7535836556833015], + [10.824626334516953, -1.3758263570293336], + [10.740049315297938, -1.8419246342642135], + [10.599233569351886, -1.4647170118602102], + [10.782211303710938, -1.6095728874206543], + [10.85372264201112, -1.454620121973409], + [10.703139244840514, -1.0468352921107207], + [10.67474502551541, -1.5252007142664867], + [10.523028245282054, -1.1178878568013508], + [10.688896179199219, -1.2867846488952637], + [9.93025878559225, -1.72464107287649], + [9.79536041556695, -1.3745671151390852], + [9.694509979482978, -1.8176162288245652], + [9.558324937336236, -1.4680781413579387], + [9.744794845581055, -1.596706748008728], + [9.960777081029136, -1.6791483180065343], + [9.834803206427397, -1.3515932104253807], + [9.683211817881576, -1.788617906132208], + [9.555821505291407, -1.4616527304959317], + [9.758810043334961, -1.5706747770309448], + [10.371559282542183, -1.7709655167075604], + [10.250081186856779, -1.4501775831900199], + [10.045146997993921, -1.8996753546295213], + [9.922035071963693, -1.579567633730599], + [10.147351264953613, -1.6755025386810303], + [10.284857658760435, -1.7980182868305539], + [10.149321578943383, -1.4415424066271871], + [9.922116203466699, -1.941054095685029], + [9.784561680492526, -1.5854185904972506], + [10.035395622253418, -1.6920098066329956], + [10.11707835468907, -1.7458657900188919], + [9.976810167660433, -1.3791857802344774], + [9.740855959361516, -1.8942306250266254], + [9.598436275714041, -1.5284465521335768], + [9.858487129211426, -1.6374623775482178], + [10.085153565129666, -1.7509984216910344], + [9.954782531582193, -1.4106646590348728], + [9.73458328604436, -1.8892480175315858], + [9.602351346555693, -1.5496891743538244], + [9.844383239746094, -1.6506069898605347], + [10.00542310545116, -1.7698958162314635], + [9.87159176652444, -1.4217712073055597], + [9.719802540800119, -1.8825331489985138], + [9.58441990449117, -1.535054549104773], + [9.795486450195312, -1.6527905464172363], + [9.924479613968668, -1.7552396072138974], + [9.797773484206546, -1.42666071397226], + [9.7040733884765, -1.842162064670874], + [9.576237636553817, -1.5140536062634826], + [9.750801086425781, -1.6349531412124634], + [10.056653015527381, -1.6659844930319383], + [9.945659692919696, -1.3761880070642598], + [9.75596129882244, -1.7845727710210335], + [9.64361064933754, -1.4953415583713283], + [9.850590705871582, -1.580852746963501], + [10.192898070643356, -1.6941876596080645], + [10.08838387698024, -1.4198973959022128], + [9.910545243554637, -1.8055364763922817], + [9.8048241096792, -1.531748787715475], + [9.999269485473633, -1.613139271736145], + [10.245754611263429, -1.6299646247792592], + [10.138223878567763, -1.3495725067584907], + [9.951284862030295, -1.744885783269507], + [9.842566081915416, -1.4653021604981313], + [10.044498443603516, -1.5477713346481323], + [10.393891895735285, -1.7344048194256718], + [10.285827782155243, -1.452358757536371], + [10.099557332608667, -1.8486109144105491], + [9.990407821228482, -1.5674022340494442], + [10.192439079284668, -1.6510233879089355], + [10.413459078573164, -1.7511082591524847], + [10.307392576673863, -1.4741353537548847], + [10.129784321711067, -1.86114823755815], + [10.022690119866814, -1.5849678253314514], + [10.218352317810059, -1.6681561470031738], + [10.54637168443922, -1.6897972263239764], + [10.444498878172563, -1.4221625389901495], + [10.27096302410055, -1.7966423801620894], + [10.16812621717975, -1.5297506018062672], + [10.357507705688477, -1.6098835468292236], + [10.48241367852133, -1.7239468475119284], + [10.376501177836658, -1.4465273559721283], + [10.198247232789765, -1.8341780667659517], + [10.091303617549436, -1.5575534410292278], + [10.287137031555176, -1.6408685445785522], + [10.410838058471453, -1.6428572256832012], + [10.291459659413094, -1.3306559325718361], + [10.090277772705058, -1.7673576774855964], + [9.969592766193394, -1.4561657484742048], + [10.190567970275879, -1.5496604442596436], + [7.720697013326741, 1.8625177876289838], + [7.634643270724434, 2.204649756102592], + [7.527653073080431, 1.8075562634533624], + [7.4407798378012515, 2.1507995807670164], + [7.581176280975342, 2.0062077045440674], + [12.890380696057893, 3.8093527146060313], + [12.815303802030046, 4.133784459954408], + [12.561653712986693, 3.7306456139089175], + [12.485510239113276, 4.053910180008601], + [12.688065528869629, 3.931558609008789], + [9.634291453293624, 0.08882535691319601], + [9.792006011312195, -0.41606719123484076], + [9.852289040619246, 0.1625812744239513], + [10.00712003075442, -0.3466616338802698], + [9.821788787841797, -0.13018354773521423], + ] + + result, home_location = drone_odometry.DronePosition.create( + HOME_LOCATION_LATITUDE, + HOME_LOCATION_LONGITUDE, + HOME_LOCATION_ALTITUDE, + ) + if not result: + return False, None + + local_geolocation_coordinates = [] + for geolocation_coordinate in geolocation_coordinates: + result, local_coordinate = drone_odometry_local.DronePositionLocal.create( + geolocation_coordinate[0], + geolocation_coordinate[1], + 0, + ) + if not result: + return False, None + local_geolocation_coordinates.append(local_coordinate) + + ground_locations = [] + for i, local_geolocation_coordinate in enumerate(local_geolocation_coordinates): + result, world_geolocation_coordinate = local_global_conversion.drone_position_global_from_local( + home_location, + local_geolocation_coordinate, + ) + if not result: + return False, None + + ground_location = location_ground.LocationGround( + i, + world_geolocation_coordinate.latitude, + world_geolocation_coordinate.longitude, + ) + if not result: + return False, None + ground_locations.append(ground_location) + + print(f"Number of coordinates: {len(ground_locations)}") + + result, file_path = ground_locations_to_kml.ground_locations_to_kml( + ground_locations, + "geolocation-flight-2", + "./scripts", + ) + if not result: + return False, None + + print(f"KML file saved to: {file_path}") + + return 0 + + +if __name__ == "__main__": + result_main = main() + if result_main < 0: + print(f"ERROR: Status code: {result_main}") + + print("Done!")