-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path03_BBox_creator.py
98 lines (82 loc) · 3.07 KB
/
03_BBox_creator.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
import pandas as pd
import os
import sys
import glob
import numpy as np
'''
Script adds a bounding box with ~2 miles around target area. This information can be useful for the pilot for flight planning
input:iii_sitename_user_renamed.wpt
output:iii_sitename_user_renamed_BBox.wpt
'''
def decimal_degrees_to_ddm(decimal_degrees):
'''
function to calculate decimal degrees to decimal minutes
'''
degrees = int(decimal_degrees) # get degrees
decimal_minutes = (decimal_degrees - degrees) * 60 # convert minutes to decimal minutes
decimal_minutes = np.round(decimal_minutes, decimals=1) # round to format necessary for gfp format (1 decimal)
return degrees, decimal_minutes # get degree integer and decimal minutes
def convert2stringLon(val):
'''
function to convert Longitude to string with E/W indicator and d/m as deg and minute sign
'''
deg = val[0]
min = val[1]
if deg<0:
EastWest = 'W'
min = abs(min) # remove minus sign
deg = abs(deg) # remove minus sign
else:
EastWest = 'E'
return('{:1}{:02d}°{:04.1f}\''.format(EastWest,deg,min))
def convert2stringLat(val):
'''
function to convert Latitude to string with S/N indicator and d/m as deg and minute sign
'''
deg = val[0]
min = val[1]
if deg<0:
NorthSouth = 'S'
min = abs(min) # remove minus sign
deg = abs(deg) # remove minus sign
else:
NorthSouth = 'N'
return('{:1}{:02d}°{:04.1f}\''.format(NorthSouth,deg,min))
def BBoxCeator(fname):
f = pd.read_csv(fname)
corners = [min(f.iloc[:,2]), max(f.iloc[:,2]), min(f.iloc[:,3]), max(f.iloc[:,3])]
# minLat, maxLat, minLon, maxLon
'''
Latitude: each minute is approx 1 mile: [+2,-2] for minutes of maxLat and minLat
Longitute at Lat 68: apporximately 3 minutes correspond to 2 km --> [+3,-3] for minutes of maxLon, minLon
'''
cornersDDM = list(map(decimal_degrees_to_ddm, corners))
bbox_enhancers = [-2,2,-3,+3]
for i in range(0, len(bbox_enhancers)):
deg = cornersDDM[i][0]
minu = cornersDDM[i][1]+bbox_enhancers[i]
if abs(minu) > 60:
print(minu)
print(int(np.round(minu/60,decimals=0)))
deg = deg + int(np.round(minu/60,decimals=0))
print(deg)
minu = np.round(abs(minu) % 60,decimals=1)
print(minu)
cornersDDM[i] = (deg,minu)
# combine to ll,ul,lr,ur
ll = cornersDDM[0],cornersDDM[2] #Latmin + Lonmin
ul = cornersDDM[1],cornersDDM[2] #Latmax + Lonmin
lr = cornersDDM[0],cornersDDM[3] #
ur = cornersDDM[1],cornersDDM[3]
bbox = pd.DataFrame(data = [ll,ul,lr,ur])
lats = list(map(convert2stringLat,bbox.iloc[:,0]))
lons = list(map(convert2stringLon,bbox.iloc[:,1]))
bbox = pd.DataFrame(data={'lat':lats,'lon':lons})
bbox.to_csv(fname[:-4]+'_BBox.txt',header=False,index = False)
if __name__ == '__main__':
fnames = glob.glob(f'{sys.argv[1]}\*_renamed.wpt')
print(f'{sys.argv[1]}')
print(fnames)
list(map(BBoxCeator,fnames))
#print(ll,ul,lr,ur)
#reconvert>