Board index FlightGear Development Scenery

Elevation probe

Questions and discussion about enhancing and populating the FlightGear world.

Re: Elevation probe

Postby dom_vc10 » Fri Nov 12, 2021 9:17 pm

in this case it would be better to parse the STG files I make instead of me creating a separate list. So I should look at regex, right?
dom_vc10
 
Posts: 339
Joined: Mon Jul 27, 2020 8:33 am
Location: CZ - LKTB
Version: nightly
OS: Linux Mint 20.2

Re: Elevation probe

Postby wkitty42 » Fri Nov 12, 2021 10:48 pm

i was only going by what was posted... there were only three values to be input and some additional ones to be output on a line containing the input values... at least that's how i read the OP's post(s)... how that input file is being created i have no idea...
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 9146
Joined: Fri Feb 20, 2015 4:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 20.04

Re: Elevation probe

Postby dom_vc10 » Sat Nov 13, 2021 1:03 am

no worries. You gave me some very good input. I was not super descriptive with the exact data I have and exactly how I want to handle. I have 3 scenery conversions on the go and have had to create a way to go through each step so my head is really full of trying to figure out where to go. So my apologies for a not so clear request. I thought I had cracked the automated conversion three times then found small issues until i finally settled with the correct script so my posts probably reflect that.
dom_vc10
 
Posts: 339
Joined: Mon Jul 27, 2020 8:33 am
Location: CZ - LKTB
Version: nightly
OS: Linux Mint 20.2

Re: Elevation probe

Postby Hooray » Mon Nov 15, 2021 5:49 pm

note that for frequent/heavy queries, you might want to consider forking or piping - if modifiying the C++ is an option, another idea would be using a thread pool.
but for starters, forking should work best since it would not require any changes
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: Elevation probe

Postby dom_vc10 » Wed Dec 01, 2021 8:47 pm

Seems when i was searching previously I had overlooked this post by udomotico. This seems pretty good!

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
dom_vc10
 
Posts: 339
Joined: Mon Jul 27, 2020 8:33 am
Location: CZ - LKTB
Version: nightly
OS: Linux Mint 20.2

Re: Elevation probe

Postby dom_vc10 » Wed Dec 01, 2021 9:33 pm

or for some quick checks you can use this direct in the terminal..

fgelev --fg-scenery PATH TO FG SCENERY
1 16.681503681 49.149569409
2 16.681414511 49.149576562

First number is an identifier you can use whatever for that. FGelev will then ouput like this..
1: 230.270
2: 230.274

I just tried that with a list of almost 800 and it only took a few seconds.
dom_vc10
 
Posts: 339
Joined: Mon Jul 27, 2020 8:33 am
Location: CZ - LKTB
Version: nightly
OS: Linux Mint 20.2

Previous

Return to Scenery

Who is online

Users browsing this forum: No registered users and 7 guests