ludomotico wrote in Thu Mar 27, 2014 10:57 am:The script to recalculate elevations in the .stg files, similar to what the database does.
- Code: Select all
#!/usr/bin/python
# recalculates all elevations in a .stg file
# Reads the .stg file from standard input, writes to standard output
# Usage: cat 11223344.stg | python recalculate_elevation.py $FG_SCENERY > 11223344.stg.new
import sys
import subprocess
# if an argument exists, use as the scenerydir. If not, use my directories
scenerydir='/home/juanvi/FlightGear/IBE/IBE:/home/juanvi/.fgfs/TerraSync'
if len(sys.argv) == 2:
scenerydir = sys.argv[1]
# Open communication to fgelev
elev = subprocess.Popen(['fgelev', '--fg-scenery', scenerydir], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
# Information about an object
class Position():
lat = ''
lng = ''
type = ''
ele = ''
offset = 0.0
repos = True
roll = '0.0'
pitch = '0.0'
# if this is set, the next object has an abolute elevation that shouldn't be calculated
noreposNext = False
# the offset of the next object
offsetNext = 0.0
# the identifier of the next object
id = 1
for l in sys.stdin.readlines():
try:
# if the line is an OBJECT or a commented OBJECT...
if l.startswith('OBJECT') | l.startswith('#OBJECT'):
# read the line
items = l.strip().split()
o = Position()
# two types of lines: those that include pitch and rolling and those that don't
if len(items) == 6:
o.type, o.model, o.lng, o.lat, o.ele, o.hdg = items
else:
o.type, o.model, o.lng, o.lat, o.ele, o.hdg, o.roll, o.pitch = items
# calculate elevation, if noreposNext is not set
if noreposNext:
noreposNext = False
o.ele = float(o.ele)
else:
elev.stdin.write('%s %s %s\n' % (str(id), o.lng, o.lat))
outs = elev.stdout.readline()
o.ele = float(outs.strip().split()[1])
id += 1
# use offset
o.offset = offsetNext
offsetNext = 0.0
# print the line
print '%s %s %s %s %f %s %s %s' % (o.type, o.model, o.lng, o.lat, o.ele + o.offset, o.hdg, o.roll, o.pitch)
elif l.startswith('# norepos'):
# if this line is found, the next object won't be recalculated
noreposNext = True
print l.strip()
elif l.startswith('# offset'):
# if this line is found, the next object will have this offset
offsetNext = float(l.strip().split()[2])
print l.strip()
else:
# any other line: just copy
print l.strip()
except:
sys.stderr.write('Error while processing line: %s' % l)
use: save this script as recalculate_elevation.py. It gets the original .stg from the standard input and writes the new .stg file to the standard output. It accepts one parameter, FG_SCENERY path. The script needs the tool fgelev in the PATH. Warning: calculating elevations can take several minutes!
Example:
cat 12345.stg | python recalculate_elevation.py /home/juanvi/myscenery > 12345.stg.new
The lines in .stg.new are the same lines than the input .stg file, with their elevations recalculated to match the current terrain.
You can select an offset (same meaning than in the database) by using a line "# offset XXX" just before the object. You can use "# norepos" to keep the elevation as is, without any modification. Other lines (blank lines, comments) are copied. For example, if you have this input file:
- Code: Select all
OBJECT_STATIC MontjuicTower.xml 2.15084043 41.36426412 81.809000 0.0 0.0 -0.0
# offset 115
OBJECT_SHARED Models/Effects/strobe10000.xml 2.15083450 41.36420342 195.999000 0.0 0.0 -0.0
OBJECT_SHARED Models/Effects/strobe10000.xml 2.15070534 41.36409007 164.134000 0.0 0.0 -0.0
OBJECT_SHARED Models/Sport/GenericStadium.xml 2.15615977 41.36485939 104.634000 92.8 0.0 -0.0
# offset -70
OBJECT_SHARED Models/Industrial/GenericStorageTank40m.xml 2.06089291 41.29939284 -66.409000 0.0 0.0 -0.0
# norepos
OBJECT_SHARED Models/Airport/helipad_circle.xml 2.18302637 41.36420015 6.826900 0.0 0.0 -0.0
1.- all objects will recalculate their elevation except the last one (helipad_circle)
2.- only the first strobe1000 will use an offset of 115 meters
3.- GenericStorageTank40m will use an offset of -70 meters
Users browsing this forum: No registered users and 7 guests