Skip to content

Commit

Permalink
Alpha 1
Browse files Browse the repository at this point in the history
  • Loading branch information
NelisV committed May 13, 2021
1 parent 9be1c20 commit cc3363e
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 27 deletions.
1 change: 1 addition & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"dat_dir": "/"}
2 changes: 1 addition & 1 deletion export.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
for item in data['features']:
coordinates = item['geometry']['coordinates'][0][0]
feature = item['properties']
headerline ='{}|{}|{}|{}|{}|{}|{}|{}|{}|{}\n'.format(feature['ICAO'], feature['IsOceanic'], feature['IsExtensio'], len(coordinates), feature['MinLat'], feature['MinLon'], feature['MaxLat'], feature['MaxLon'], feature['CenterLat'], feature['CenterLon'])
headerline = '{}|{}|{}|{}|{}|{}|{}|{}|{}|{}\n'.format(feature['ICAO'], feature['IsOceanic'], feature['IsExtensio'], len(coordinates), round(float(feature['MinLat']), 6), round(float(feature['MinLon']), 6), round(float(feature['MaxLat']), 6), round(float(feature['MaxLon']), 6), round(float(feature['CenterLat']), 6), round(float(feature['CenterLon']), 6))
print(headerline)
print(feature['PointCount'])

Expand Down
18 changes: 9 additions & 9 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
firpoint_list = None
firheader_list = None
# file_name = 'source/FIRBoundaries_test.dat'
file_name = 'source/FIRBoundaries.dat'

# file_name = 'source/FIRBoundaries.dat'


def fir_header(header):
Expand Down Expand Up @@ -36,9 +35,9 @@ def airspace_close():
return fir_dict


def geojson_writer(features):
def geojson_writer(features, output_dir):
'''Create GeoJSON Header'''

print(output_dir)
basedict = {}
crsdict = {}
propertydict = {}
Expand All @@ -55,16 +54,17 @@ def geojson_writer(features):
basedict['features'] = feature_list

'''write to text file'''
name = section[2]
outputfile = open('output/{}.geojson'.format(name), 'w')
print(output_dir)
outputfile = open(output_dir, 'w')
outputfile.write(json.dumps(basedict, indent=4))
# print(json.dumps(basedict, indent=4))
outputfile.close()
print_string = 'GeoJSON saved to {}.geojson'.format(name)
print_string = 'GeoJSON saved to {}'.format(output_dir)
print(print_string)


if __name__ == "__main__":
def dat_import(file_name, output_dir):
global airspace_count, firpoint_list
with open(file_name) as fir_file:
csv_reader = csv.reader(fir_file, delimiter='|')
for row in csv_reader:
Expand All @@ -85,4 +85,4 @@ def geojson_writer(features):
{'type': 'Feature', 'properties': {'id': airspace_count, 'ICAO': item['ICAO'], 'IsOceanic': item['IsOceanic'], 'IsExtension': item['IsExtension'], 'PointCount': item['PointCount'], 'MinLat': item['MinLat'], 'MinLon': item['MinLon'], 'MaxLat': item['MaxLat'], 'MaxLon': item['MaxLon'], 'CenterLat': item['CenterLat'], 'CenterLon': item['CenterLon']}, 'geometry': {'type': 'MultiPolygon', 'coordinates': [[item['Coordinates']]]}}], filename]
features.append(section)

geojson_writer(features)
geojson_writer(features, output_dir)
138 changes: 121 additions & 17 deletions tkinter_test.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,105 @@
import tkinter as tk
from tkinter import ttk
from tkinter import filedialog
from main import dat_import
import json
import webbrowser

filename = None
dirname = None
settings = None


# file explorer window
def browsefiles():
filename = filedialog.askopenfilename(initialdir="/",
global filename
local_filename = filedialog.askopenfilename(initialdir=settings['dat_dir'],
title="Select a File",
filetypes=(("Text files", "*.txt*"), ("all files", "*.*")))
if filename:
filetypes=(("FIRBoundaries.dat", "*.dat*"), ("all files", "*.*")))
print(filename)
if local_filename:
filename = local_filename
file_info.configure(text=filename)
config('W')
switchButtonState('A', 1)
else:
pass
file_info.configure(text=filename)


def browsedirectory():
global dirname
local_dirname = filedialog.asksaveasfilename(
defaultextension='.geojson', filetypes=[("GeoJSON files", '*.geojson')],
initialdir=settings['dat_dir'],
title="Save As")

if local_dirname:
dirname = local_dirname
file_info3.configure(text=dirname)
if filename:
switchButtonState('B', 1)
else:
file_info3.configure(text=dirname)


# action to call function
def datparser():
try:
dat_import(filename, dirname)
description4 = "file saved to: " + dirname
des_text4 = tk.Label(tab1, text=description4)
des_text4.grid(row=6, column=0, sticky=tk.W, pady=5, columnspan=2)

except:
print('parse error')
description4 = 'Parsing error, check if you used a valid FIRBoundaries file'
des_text4 = tk.Label(tab1, text=description4)
des_text4.grid(row=6, column=0, sticky=tk.W, pady=5, columnspan=2)


# action to display parse button
def switchButtonState(button, state):
if button == 'A':
if state == 0:
button_file3['state'] = tk.DISABLED
if state == 1:
button_file3['state'] = tk.NORMAL
if button == 'B':
if state == 0:
button_datimport['state'] = tk.DISABLED
if state == 1:
button_datimport['state'] = tk.NORMAL


# configuration saver/loader
def config(mode='R'):
global settings
if mode == 'W':

if filename:
defaultdir = filename.rsplit('/', 1)[0]+'/'
settings['dat_dir'] = defaultdir

with open('config.json', 'w') as outfile:
json.dump(settings, outfile)
elif mode == 'R':
with open('config.json', 'r') as readfile:
settings = json.load(readfile)


def callback(url):
webbrowser.open_new(url)


# Load config file
config()

# First line
root = tk.Tk()

# configure root
root.title('VAT-Spy GeoJSON')
root.geometry('800x600')
root.geometry('500x400')
root.columnconfigure(1, weight=1)
root.rowconfigure(2, weight=1)
root.iconbitmap('vattech.ico')
Expand All @@ -28,13 +108,16 @@ def browsefiles():
tabControl = ttk.Notebook(root)
tab1 = ttk.Frame(tabControl)
tab2 = ttk.Frame(tabControl)
tab3 = ttk.Frame(tabControl)

tabControl.add(tab1, text='DAT to GeoJSON')
tabControl.add(tab2, text='GeoJSON to DAT')
tabControl.add(tab3, text='About')

tabControl.pack(expand=1, fill="both")

# tab1
# load firboundaries.dat file
description = "Browse to a valid VAT-Spy firboundaries.dat file"
des_text = tk.Label(tab1, text=description)
des_text.grid(row=1, column=0, sticky=tk.W, pady=5, columnspan=2)
Expand All @@ -43,16 +126,37 @@ def browsefiles():
button_file.grid(row=2, column=0, sticky=tk.W, padx=5, pady=5)

file_info = tk.Label(tab1, text='No file selected')
file_info.grid(row=3, column=0, sticky=tk.W, pady=5, columnspan=2)

# categories = ['Work', 'Hobbies', 'Health', 'Bills']
# cat_label = tk.Label(tab1, text='Category: ')
# cat_label.grid(row=2, column=0, sticky=tk.W, padx=5, pady=5)
# cat_inp = ttk.Combobox(tab1, values=categories)
# cat_inp.grid(row=2, column=1, sticky=tk.W, padx=5, pady=5)
# cat_inp.current(2)
#
# cat_inp.bind("<<ComboboxSelected>>", lambda x: print('itemselected: {}'.format(cat_inp.get())))

# Last line
file_info.grid(row=2, column=1, sticky=tk.W, pady=5, columnspan=2)

# select a save location
description3 = "GeoJSON save location"
des_text3 = tk.Label(tab1, text=description3)
des_text3.grid(row=3, column=0, sticky=tk.W, pady=5, columnspan=2)

button_file3 = tk.Button(tab1, text='Save As', command=browsedirectory, state=tk.DISABLED)
button_file3.grid(row=4, column=0, sticky=tk.W, padx=5, pady=5)

file_info3 = tk.Label(tab1, text='No directory selected')
file_info3.grid(row=4, column=1, sticky=tk.W, pady=5, columnspan=2)

button_datimport = tk.Button(tab1, text='Parse', command=datparser, state=tk.DISABLED)
button_datimport.grid(row=5, column=0, sticky=tk.W, padx=5, pady=5)

# tab about
description5 = "VAT-Spy - GeoJSON converter by NelisV"
des_text5 = tk.Label(tab3, text=description5)
des_text5.grid(row=1, column=0, sticky=tk.W, pady=5, columnspan=2)

description6 = "Development - Alpha 1"
des_text6 = tk.Label(tab3, text=description6)
des_text6.grid(row=2, column=0, sticky=tk.W, pady=5, columnspan=2)

link1 = tk.Label(tab3, text="Program GitHub", fg="blue", cursor="hand2")
link1.grid(row=4, column=0, sticky=tk.W, pady=5, columnspan=2)
link1.bind("<Button-1>", lambda e: callback("https://github.com/NelisV/vatspy-geojson"))

link2 = tk.Label(tab3, text="VAT-Spy Data Project", fg="blue", cursor="hand2")
link2.grid(row=5, column=0, sticky=tk.W, pady=5, columnspan=2)
link2.bind("<Button-1>", lambda e: callback("https://github.com/vatsimnetwork/vatspy-data-project"))

root.mainloop()

0 comments on commit cc3363e

Please sign in to comment.