Hi fellow wiki editors!

To help newly registered users get more familiar with the wiki (and maybe older users too) there is now a {{Welcome to the wiki}} template. Have a look at it and feel free to add it to new users discussion pages (and perhaps your own).

I have tried to keep the template short, but meaningful. /Johan G

User:Laserman/gpx2stg.py

From FlightGear wiki
Jump to: navigation, search

gpx2stg.py

precise way to place shared objects in the Fg Scenery by using the OpenStreetMap Editor "JOSM"

example gpx file exported from JOSM:

 1 <?xml version='1.0' encoding='UTF-8'?>
 2 <gpx version="1.1" creator="JOSM GPX export" xmlns="http://www.topografix.com/GPX/1/1"
 3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 4     xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
 5   <metadata>
 6     <bounds minlat="51.6847476" minlon="7.09489" maxlat="51.6870975" maxlon="7.1052296"/>
 7   </metadata>
 8   <wpt lat="51.68474756644179" lon="7.103785297249551">
 9   </wpt>
10   <wpt lat="51.68667857011125" lon="7.097848901875471">
11   </wpt>
12   <wpt lat="51.68709745361677" lon="7.094889961003022">
13   </wpt>
14   <wpt lat="51.68668414010407" lon="7.097757201021684">
15   </wpt>
16   <wpt lat="51.686192807753315" lon="7.105229579867249">
17   </wpt>
18 </gpx>


convert to stg format:

./gpx2stg.py -i gasometer.gpx  -m Models/Industrial/Gasometer.xml -e 100 > 3072872.stg
#!/usr/bin/python

# gpx2stg.py by d-laser
#
# reads a .gpx file of points that i export from JOSM
# writes stg formated to stdout
#

import sys, getopt
import xml.etree.ElementTree as ET

helptext = 'gpx2stg.py -i <inputfile> -m <path to shared model> -e <elevation>'

def main(argv):
    model = "Models/Industrial/GenericStorageTank15m.ac"
    elev  = 50
    heading = 0
    inputfile = "kugeln.gpx" 
    outputfile=''
    
    try:
        opts, args = getopt.getopt(argv,"hi:m:e:")
    except getopt.GetoptError:
        print helptext
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print helptext
            sys.exit()
        elif opt == "-i":
            inputfile = arg
        elif opt == "-m":
            model = arg
        elif opt == "-e":
            elev = arg
    #print 'Input file is ', inputfile
    #print 'Output file is ', outputfile
    #print 'Number of arguments:', len(sys.argv), 'arguments.'
    #print 'Argument List:', str(sys.argv)

    tree = ET.parse(inputfile)
    root = tree.getroot()

    for child in root:
        point = child.attrib
        if point:
            print "OBJECT_SHARED", model, point['lon'],point['lat'], elev, heading 
        
if __name__ == "__main__":
   main(sys.argv[1:])