python convert_wpt_cup.py poitiers_vfr.csv --name LFBI
Last active
February 16, 2022 16:11
-
-
Save scls19fr/8cb7208fab72eb17ecd18a9fc97aeaad to your computer and use it in GitHub Desktop.
Convert CSV file of waypoints with degrees/minutes/seconds to .cup files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Convert CSV file of waypoints with degrees/minutes/seconds to .cup files | |
Usage: | |
$ python convert_wpt_cup.py poitiers_vfr.csv --name "%s@LFBI" --country "FR" | |
""" | |
import click | |
import re | |
import os | |
import pandas as pd | |
from aerofiles.seeyou.writer import Writer | |
from aerofiles.seeyou.converter import WaypointStyle | |
COORD_PATTERN = re.compile(r"(\d+)°(\d+)['’](\d+)[\"”]([NSEW])") | |
SGN_DIR = {"N": 1, "S": -1, "E": 1, "W": -1} | |
def convert_dms(s): | |
m = COORD_PATTERN.match(s) | |
(dd, mm, ss, d) = m.groups() | |
dd = int(dd) | |
mm = int(mm) | |
ss = int(ss) | |
sgn = SGN_DIR[d] | |
return sgn * (dd + mm / 60.0 + ss / 3600.0) | |
@click.command() | |
@click.argument("csv_input") | |
@click.option("--name", default="", help="Name of waypoint") | |
@click.option("--country", default="FR", help="Country code") | |
def main(csv_input, name, country): | |
print("Loading %s" % csv_input) | |
df = pd.read_csv(csv_input) | |
print(df) | |
df["shortname"] = df.name.copy() | |
df["country"] = country | |
if name != "": | |
df.name = df.name.map(lambda s: name + "/" + s) | |
assert df.name.is_unique, "names must be unique" | |
df.latitude = df.latitude.map(convert_dms) | |
df.longitude = df.longitude.map(convert_dms) | |
if "elevation" not in df.columns: | |
df["elevation"] = 0 | |
print("") | |
print(df) | |
(root, _) = os.path.splitext(csv_input) | |
xls_output = root + ".xlsx" | |
print("") | |
print("Writing %s" % xls_output) | |
df["lat_long"] = df["latitude"].map(str).str.replace(",", ".") + " " + df["longitude"].map(str).str.replace(",", ".") | |
df.to_excel(xls_output, index=False) | |
cup_output = root + ".cup" | |
print("") | |
print("Writing %s" % cup_output) | |
with open(cup_output, "wb") as fd: | |
w = Writer(fd) | |
for (_, wpt) in df.iterrows(): | |
w.write_waypoint( | |
wpt["name"], | |
wpt.shortname, | |
wpt.country, | |
wpt.latitude, | |
wpt.longitude, | |
elevation=wpt.elevation, | |
style=WaypointStyle.NORMAL, | |
runway_direction=u"", | |
runway_length=u"", | |
frequency=u"", | |
description=wpt.desc, | |
) | |
if __name__ == "__main__": | |
main() |
We can make this file beautiful and searchable if this error is corrected: Illegal quoting in line 6.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name,latitude,longitude,desc | |
E,46°33’32”N,000°30’02”E,"St Julien - l’Ars : voie ferrée" | |
EA,46°35’30”N,000°23’40”E,"Usine Buxerolles (cheminée blanche, route)" | |
W,46°38’48”N,000°10’13”E,"Vouillé/route, rivière Auxance" | |
WA,46°37’43”N,000°15’51”E,"Rond-point de Moulinet" | |
S,46°26'55"N,000°16'10"E,"Réservoir d'eau" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name,code,country,lat,lon,elev,style,rwdir,rwlen,freq,desc | |
"LFBI/E","E",FR,4633.533N,00030.033E,0m,1,,,,"St Julien - l’Ars : voie ferrée" | |
"LFBI/EA","EA",FR,4635.500N,00023.667E,0m,1,,,,"Usine Buxerolles (cheminée blanche, route)" | |
"LFBI/W","W",FR,4638.800N,00010.217E,0m,1,,,,"Vouillé/route, rivière Auxance" | |
"LFBI/WA","WA",FR,4637.717N,00015.850E,0m,1,,,,"Rond-point de Moulinet" | |
"LFBI/S","S",FR,4626.917N,00016.167E,0m,1,,,,"Réservoir d'eau" |
A tester
"Circuit3Ch",Circuit3Ch,,4650.408N,00043.660E,0m,1,,,,
Faire une appli Python avec https://pypi.org/project/PySimpleGUI/
Remarque :
Utiliser plutôt des noms de la forme LFBI/WA plutôt que WA@LFBI
car cela semble plus "standard"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not to be used for real flight - use at your own risk
Ne pas utiliser pour le vol réel - à utiliser à vos risques et périls