Skip to content

Commit

Permalink
Merge pull request #2 from NelisV/development
Browse files Browse the repository at this point in the history
Alpha 2
  • Loading branch information
NelisV authored Aug 30, 2021
2 parents 16fb412 + 11ef20c commit 66171c8
Show file tree
Hide file tree
Showing 6 changed files with 416 additions and 128 deletions.
23 changes: 5 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
# vatspy-geojson
To convert firboundaries.dat to GeoJSON:
1. Create a subfolder in the root directory called /source/.
2. Paste firboundaries.dat in the created folder.
3. Run main.py.
Alpha version including GUI

firboundaries.geojson is created in /output/
- Unzip the release version.
- Run the executable.


- When editing in QGIS, it is advised to first convert to ESRI Shapefile.
- Copy the sectors you want to edit to a new layer (important).
- Make you changes.
- When finished save your layer to GeoJSON.

To convert GeoJSON to firboundaries.dat:
1. Paste firboundaries.geojson you created in /output/
2. Run export.py
3. enter filename for input file (default is firboundaries.geojson)
3. firboundaries.dat created in /export/

- Make sure to only update/change the sectors you edited.
To pack as executable using pyinstaller execute: </br>
```pyinstaller --onefile --windowed --icon=vattech.ico main.py```
31 changes: 0 additions & 31 deletions export.py

This file was deleted.

42 changes: 42 additions & 0 deletions export_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import json


def dat_export(file_name, output_dir):
print('file_name {}'.format(file_name))
print('output_dir {}'.format(output_dir))
with open(file_name) as json_file:
data = json.load(json_file)
f = open(output_dir, 'w')
for item in data['features']:
coordinates = item['geometry']['coordinates'][0][0]
feature = item['properties']
if 'IsExtensio' in feature:
header_line = '{}|{}|{}|{}|{}|{}|{}|{}|{}|{}\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))
elif 'IsExtension' in feature:
header_line = '{}|{}|{}|{}|{}|{}|{}|{}|{}|{}\n'.format(feature['ICAO'], feature['IsOceanic'],
feature['IsExtension'], 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))
f.write(header_line)
for coord in coordinates:
val1 = round(coord[1], 6)
val2 = round(coord[0], 6)
coord_line = '{}|{}\n'.format(val1, val2)
f.write(coord_line)
f.close()


if __name__ == "__main__":
dat_export('F:/Documents/Dutchvacc/SCT werk/VATSPY/PR.328/328.geojson',
'F:/Documents/Dutchvacc/SCT werk/VATSPY/PR.328/328test.dat')
88 changes: 88 additions & 0 deletions import_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import csv
import json

airspace_count = 0
fir_list = []
firpoint_list = None
firheader_list = None
# file_name = 'source/FIRBoundaries_test.dat'
# file_name = 'source/FIRBoundaries.dat'


def fir_header(header):
global airspace_count, firheader_list
airspace_count += 1
firheader_list = header


def airspace_pnt(firpoint_list, point):
coords = [float(point[0]), float(point[1])]
coords.reverse()
point = [coords]
if firpoint_list == None:
firpoint_list = point
else:
firpoint_list = firpoint_list + point
return firpoint_list


def airspace_close():
global firheader_list, firpoint_list
header = firheader_list + [firpoint_list]
keys = ['ICAO', 'IsOceanic', 'IsExtension', 'PointCount', 'MinLat', 'MinLon', 'MaxLat', 'MaxLon', 'CenterLat', 'CenterLon', 'Coordinates']
fir_dict = dict(zip(keys, header))
firpoint_list = None
return fir_dict


def geojson_writer(features, output_dir):
'''Create GeoJSON Header'''
print(output_dir)
basedict = {}
crsdict = {}
propertydict = {}
feature_list = []
basedict['type'] = "FeatureCollection"
basedict['name'] = ''
propertydict['name'] = "urn:ogc:def:crs:OGC:1.3:CRS84"
crsdict['type'] = "name"
crsdict['properties'] = propertydict
basedict['crs'] = crsdict
for section in features:
feature_list = feature_list + section[1]

basedict['features'] = feature_list

'''write to text file'''
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 {}'.format(output_dir)
print(print_string)


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:
if len(row) > 2:
if airspace_count > 0:
fir_list.append(airspace_close())
fir_header(row)
else:
firpoint_list = airspace_pnt(firpoint_list, row)
fir_list.append(airspace_close())

features = []
airspace_count = 0
for item in fir_list:
airspace_count += 1
filename = 'firboundaries'
section = [12582, [
{'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, output_dir)
Loading

0 comments on commit 66171c8

Please sign in to comment.