Added XPlane scenery DSF/TXT to FlightGear scenery STG converter
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
#-*- coding:utf-8 -*-
|
||||
|
||||
import math
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
def get_fg_tile_span(lat):
|
||||
if lat >= 89:
|
||||
@@ -31,9 +33,72 @@ def get_fg_tile_span(lat):
|
||||
else:
|
||||
return 12
|
||||
|
||||
def get_fg_tile_index(lon, lat):
|
||||
tile_width = get_fg_tile_span(lat)
|
||||
x = math.floor((lon - math.floor(math.floor(lon / tile_width) * tile_width)) / tile_width)
|
||||
y = trunc((lat - math.floor(lat)) + 8)
|
||||
return ((lon + 180) << 14) + ((lat + 90) << 6) + (y << 3) + x
|
||||
def get_fg_tile_index(dlon, dlat):
|
||||
tile_width = get_fg_tile_span(dlat)
|
||||
lon = math.floor(dlon)
|
||||
lat = math.floor(dlat)
|
||||
if tile_width <= 1:
|
||||
x = math.floor((dlon - lon) / tile_width)
|
||||
else:
|
||||
lon = int(math.floor(lon / tile_width) * tile_width)
|
||||
x = 0
|
||||
|
||||
if lat == 90:
|
||||
lat = 89
|
||||
y = 7
|
||||
else:
|
||||
y = math.floor((dlat - math.floor(dlat)) * 8)
|
||||
|
||||
return ((lon + 180) << 14) + ((lat + 90) << 6) + (y << 3) + x
|
||||
|
||||
def get_fg_tile_coords(index):
|
||||
lon = index >> 14;
|
||||
index -= lon << 14;
|
||||
lon -= 180;
|
||||
|
||||
lat = index >> 6;
|
||||
index -= lat << 6;
|
||||
lat -= 90;
|
||||
|
||||
return lon, lat
|
||||
|
||||
def get_fg_tile_path(lon, lat):
|
||||
top_lon = int(lon / 10);
|
||||
main_lon = int(lon);
|
||||
if (lon < 0) and (top_lon * 10 != lon):
|
||||
top_lon -= 1;
|
||||
top_lon *= 10
|
||||
if top_lon >= 0:
|
||||
hem = "e"
|
||||
else:
|
||||
hem = "w"
|
||||
top_lon *= -1;
|
||||
if main_lon < 0:
|
||||
main_lon *= -1
|
||||
|
||||
top_lat = int(lat / 10)
|
||||
main_lat = int(lat)
|
||||
if (lat < 0) and (top_lat * 10 != lat):
|
||||
top_lat -= 1
|
||||
top_lat *= 10
|
||||
if top_lat >= 0:
|
||||
pole = "n"
|
||||
else:
|
||||
pole = "s"
|
||||
top_lat *= -1
|
||||
if main_lat < 0:
|
||||
main_lat *= -1
|
||||
|
||||
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):
|
||||
env = os.environ.copy()
|
||||
env["FG_SCENERY"] = os.pathsep.join(fgscenery)
|
||||
env["FG_ROOT"] = fgdata
|
||||
pipe = subprocess.Popen(args=[fgelev, "--expire", "1"], env=env, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
pipe.stdout.flush()
|
||||
pipe.stdout.readline()
|
||||
pipe.stdin.flush()
|
||||
pipe.stdin.flush()
|
||||
return pipe
|
||||
|
||||
|
||||
@@ -5,8 +5,6 @@ import os
|
||||
import sys
|
||||
|
||||
HOME = os.environ.get("HOME", os.path.expanduser("~"))
|
||||
SCRIPTS = ["process-shapefiles.py", "process-elevations.py"]
|
||||
MODULE = "tgtools"
|
||||
__version__ = (1, 0, 0)
|
||||
__versionstr__ = ".".join(map(str, __version__))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user