Added apt.dat to groundnet / twr/ threshold / ils.xml files converter, made STG object elevation recalculator accept whole directory structures as input
This commit is contained in:
23
utils/__init__.py
Executable file → Normal file
23
utils/__init__.py
Executable file → Normal file
@@ -3,6 +3,7 @@
|
||||
|
||||
import math
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
|
||||
def get_fg_tile_span(lat):
|
||||
@@ -92,6 +93,8 @@ def get_fg_tile_path(lon, lat):
|
||||
return f"{hem}{int(top_lon):03d}{pole}{int(top_lat):02d}/{hem}{int(main_lon):03d}{pole}{int(main_lat):02d}/{get_fg_tile_index(lon, lat)}"
|
||||
|
||||
def make_fgelev_pipe(fgelev, fgscenery, fgdata):
|
||||
print("Creating pipe to fgelev … ", end="")
|
||||
sys.stdout.flush()
|
||||
env = os.environ.copy()
|
||||
env["FG_SCENERY"] = os.pathsep.join(fgscenery)
|
||||
env["FG_ROOT"] = fgdata
|
||||
@@ -100,5 +103,25 @@ def make_fgelev_pipe(fgelev, fgscenery, fgdata):
|
||||
pipe.stdout.readline()
|
||||
pipe.stdin.flush()
|
||||
pipe.stdin.flush()
|
||||
print("done")
|
||||
return pipe
|
||||
|
||||
def isiterable(o, striterable=False):
|
||||
if isinstance(o, str):
|
||||
return striterable
|
||||
else:
|
||||
try:
|
||||
iter(o)
|
||||
return True
|
||||
except TypeError:
|
||||
return False
|
||||
|
||||
def wrap_period(n, min, max):
|
||||
while n > max:
|
||||
n -= max - min
|
||||
|
||||
while n < min:
|
||||
n += max - min
|
||||
|
||||
return n
|
||||
|
||||
|
||||
0
utils/constants.py
Executable file → Normal file
0
utils/constants.py
Executable file → Normal file
28
utils/files.py
Normal file
28
utils/files.py
Normal file
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env python
|
||||
#-*- coding:utf-8 -*-
|
||||
|
||||
import os
|
||||
|
||||
from fgtools.utils import isiterable
|
||||
|
||||
def find_input_files(paths, prefix="", suffix=""):
|
||||
if not isiterable(paths):
|
||||
if isinstance(paths, str):
|
||||
paths = [paths]
|
||||
else:
|
||||
raise TypeError("paths is not iterable")
|
||||
|
||||
files = []
|
||||
for path in paths:
|
||||
if os.path.isfile(path) and os.path.split(path)[-1].startswith(prefix) and path.endswith(suffix):
|
||||
files.append(path)
|
||||
elif os.path.isdir(path):
|
||||
files += find_input_files([os.path.join(path, s) for s in os.listdir(path)])
|
||||
else:
|
||||
print(f"Input file / directory {path} does not exist - skipping")
|
||||
|
||||
return files
|
||||
|
||||
def write_xml_header(f):
|
||||
f.write('<?xml version="1.0" encoding="UTF-8"?>\n')
|
||||
|
||||
42
utils/geo.py
Normal file
42
utils/geo.py
Normal file
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env python
|
||||
#-*- coding:utf-8 -*-
|
||||
|
||||
import math
|
||||
|
||||
from fgtools.utils import wrap_period
|
||||
|
||||
EARTH_RADIUS = 6378138.12
|
||||
|
||||
def great_circle_distance_m(lon1, lat1, lon2, lat2):
|
||||
lon1, lat1, lon2, lat2 = map(math.radians, (lon1, lat1, lon2, lat2))
|
||||
return abs(EARTH_RADIUS * math.acos(math.sin(lat1) * math.sin(lat2) + math.cos(lat1) * math.cos(lat2) * math.cos(lon1 - lon2)))
|
||||
|
||||
def great_circle_distance_km(lon1, lat1, lon2, lat2):
|
||||
return great_circle_distance_m(lon1, lat1, lon2, lat2) / 1000
|
||||
|
||||
def get_bearing_deg(lon1, lat1, lon2, lat2):
|
||||
dlon = (lon2 - lon1)
|
||||
x = math.cos(math.radians(lat2)) * math.sin(math.radians(dlon))
|
||||
y = math.cos(math.radians(lat1)) * math.sin(math.radians(lat2)) - math.sin(math.radians(lat1)) * math.cos(math.radians(lat2)) * math.cos(math.radians(dlon))
|
||||
brg = math.atan2(x, y)
|
||||
brg = math.degrees(brg)
|
||||
|
||||
return wrap_period(brg, 0, 360)
|
||||
|
||||
def apply_heading_distance(lon, lat, heading, distance):
|
||||
lon = math.radians(lon)
|
||||
lat = math.radians(lat)
|
||||
heading = math.radians(heading)
|
||||
distance /= EARTH_RADIUS
|
||||
|
||||
if distance < 0:
|
||||
distance = abs(distance)
|
||||
heading -= math.pi
|
||||
|
||||
lat = math.asin(math.sin(lat) * math.cos(distance) + math.cos(lat) * math.sin(distance) * math.cos(heading))
|
||||
|
||||
if math.cos(lat) > 1e-15:
|
||||
lon = math.pi - (math.pi - lon - math.asin(math.sin(heading) * math.sin(distance) / math.cos(lat)) % (2 * math.pi))
|
||||
|
||||
return wrap_period(math.degrees(lon), -180, 180), wrap_period(math.degrees(lat), -90, 90)
|
||||
|
||||
0
utils/interpolator.py
Executable file → Normal file
0
utils/interpolator.py
Executable file → Normal file
12
utils/unit_convert.py
Normal file
12
utils/unit_convert.py
Normal file
@@ -0,0 +1,12 @@
|
||||
#!/usr/bin/env python
|
||||
#-*- coding:utf-8 -*-
|
||||
|
||||
import math
|
||||
|
||||
def m2ft(m):
|
||||
return m * 3.2808399
|
||||
|
||||
def ft2m(ft):
|
||||
return ft / 3.2808399
|
||||
|
||||
|
||||
Reference in New Issue
Block a user