Board index FlightGear Development

SimBrief flightplan converter 2

FlightGear is opensource, so you can be the developer. In the need for help on anything? We are here to help you.
Forum rules
Core development is discussed on the official FlightGear-Devel development mailing list.

Bugs can be reported in the bug tracker.

SimBrief flightplan converter 2

Postby powoflight » Tue Oct 09, 2018 12:39 pm

I asked bob by PM to send me the converter file. But no sucess.
See
viewtopic.php?f=18&t=34396#p333355

So I write a converter for python 2.7
It is based on a pythonfile , somewhere in this forum but cant remeber where it is.


1) Generate a flightplan file with Simbrief and download it with X-Plane 9/10 . fms

2) Start the python 27 like me in a batchfile
python Route_XP2FG_test.py LOWW-EDDM.fms > LOWW-EDDM_test.XML

Code: Select all
# xplane fms format 8,9,10
#1 - Airport ICAO
#28 - Lat/Lon Position

import sys
infile = open(sys.argv[1], 'r')
# airport = sys.argv[2]
found = False
import re
   
pattern1 = re.compile(r"^1\s*([\-0-9\A-Za-z]*)\s*([\-0-9]*)\s*([\-0-9\.]*)\s*(.*)$")
pattern11 = re.compile(r"^11\s*([\-0-9\A-Za-z]*)\s*([\-0-9]*)\s*([\-0-9\.]*)\s*(.*)$")
pattern3 = re.compile(r"^3\s*([\-0-9\A-Za-z]*)\s*([\-0-9]*)\s*([\-0-9\.]*)\s*(.*)$")
pattern28 = re.compile(r"^28\s*([\-0-9\.\+\_]*)\s*([\-0-9]*)\s*([\-0-9\.]*)\s*(.*)$")

Airport_Depature = 0
Airport_Arrival = 0

for line in infile:
            line = line.strip()
            # 1 for airports, 16 for seaports
            if line.startswith("1 "):
                    # if " %s "%airport in line:
                    #print(line)
                    Airport_Depature = pattern1.match(line)
                    #print(Airport_Depature.group(1))
                    #print(Airport_Depature.group(2))
                    #print(Airport_Depature.group(3))
                    #print(Airport_Depature.group(4))
                    #print("")
                   
                    found = True
                    break

if not found:
            print("Airport not found")
            sys.exit(1)

    # Here, we are at the airport
                                                                                                                                                               
parkings = []                                                                                                                                                   
for line in infile:                                                                                                                                             
            line = line.strip()                                                                                                                                     
            # If the airport description ends, break   
           
            #print(line)                                                                                                           
            if line.startswith("1 "):   
                    Airport_Arrival = pattern1.match(line)
                    #print(Airport_Arrival.group(1))                                                                                                                           
                    break                                                                                                                                           
                                                                                                                                                               
            WP1 = -555                                                                                                                                             
            FEET2 = -555
            LAT3 = 0
            AIRNAV = 0
            result = pattern11.match(line)
           
            # Math line 11 - Fix
            if result:
                    WP1 = (result.group(1))
                    FEET2 = (result.group(2))
                    LAT3 = (result.group(3))
                    LONG4 = (result.group(4))
                    AIRNAV = 11
                                               
            # Match line
            else:
                    result = pattern3.match(line)
                    if result:
                            WP1 = (result.group(1))
                            FEET2 = (result.group(2))
                            LAT3 = (result.group(3))
                            LONG4 = (result.group(4))
                            AIRNAV = 3
                   
                    # 28 Waypoints TOC TOD       
                    result = pattern28.match(line)
                    if result:       
                            WP1 = (result.group(1))
                            FEET2 = (result.group(2))
                            LAT3 = (result.group(3))
                            LONG4 = (result.group(4))
                            AIRNAV = 28                           
                           
            # If found, convert values
            if WP1 != -555:
                    parkings.append((WP1, FEET2, LAT3, LONG4, AIRNAV ), )

infile.close()

print('<?xml version="1.0"?>\n\n<PropertyList>\n  <version type="int">2</version>')
print('  <departure>')
print('    <airport type="string">' + Airport_Depature.group(1) + '</airport>')
print('  </departure>')
print('  <destination>')
print('    <airport type="string">' + Airport_Arrival.group(1) + '</airport>')
print('  </destination>')
print('  <route>')

# Airport Depature
i = 0
print('    <wp n="%d">'%i)
print('      <type type="string">navaid</type>')
print('      <departure type="bool">true</departure>')
print('      <ident type="string">' + Airport_Depature.group(1) + '</ident>')
print('      <lon type="double">' + Airport_Depature.group(4) + '</lon>')
print('      <lat type="double">' + Airport_Depature.group(3) + '</lat>')
print('    </wp>')

i = 1
for p in parkings:

            #print('        <Zaehler="%d" type="gate" WP1="%s" FEET2="%s" LAT3="%s" LONG4="%s" />'%(i, p[0], p[1], p[2], p[3]))
            #print('----AIRNAV:', p[4]  )
            if (p[4]== 28):
               #print('----AIRNAV ist Waypoint:', p[4]  )
               print('    <wp n="%d">'%i)
               print('      <type type="string">navaid</type>')
               print('      <alt-restrict type="string">at</alt-restrict>')
               print('      <altitude-ft type="double">' + p[1] + '</altitude-ft>')
               print('      <ident type="string">WP_pow</ident>')
               print('      <lon type="double">' + p[3] + '</lon>')
               print('      <lat type="double">' + p[2] + '</lat>')
               print('    </wp>')               
         
            else:           
                #print('----AIRNAV ist anders:', p[4]  )           
                print('    <wp n="%d">'%i)
                print('      <type type="string">navaid</type>')
                print('      <alt-restrict type="string">at</alt-restrict>')
                print('      <altitude-ft type="double">' + p[1] + '</altitude-ft>')
                print('      <ident type="string">' + p[0] + '</ident>')
                print('      <lon type="double">' + p[3] + '</lon>')
                print('      <lat type="double">' + p[2] + '</lat>')
               
                print('    </wp>')
            i = i + 1
           
# Airport approach
print('    <wp n="%d">'%i)
print('      <type type="string">navaid</type>')
print('      <approach type="bool">true</approach>')
print('      <ident type="string">' + Airport_Arrival.group(1) + '</ident>')
print('      <lon type="double">' + Airport_Arrival.group(4) + '</lon>')
print('      <lat type="double">' + Airport_Arrival.group(3) + '</lat>')
print('    </wp>')
print("  </route>")
print("</PropertyList>")


TOC and TOD is written as WP_pow

A short converted flightplanfile for FG
Code: Select all
<?xml version="1.0"?>

<PropertyList>
  <version type="int">2</version>
  <departure>
    <airport type="string">LOWW</airport>
  </departure>
  <destination>
    <airport type="string">EDDM</airport>
  </destination>
  <route>
    <wp n="0">
      <type type="string">navaid</type>
      <departure type="bool">true</departure>
      <ident type="string">LOWW</ident>
      <lon type="double">16.569722</lon>
      <lat type="double">48.110278</lat>
    </wp>
    <wp n="1">
      <type type="string">navaid</type>
      <alt-restrict type="string">at</alt-restrict>
      <altitude-ft type="double">25500</altitude-ft>
      <ident type="string">SITNI</ident>
      <lon type="double">14.834614</lon>
      <lat type="double">48.054228</lat>
    </wp>
    <wp n="2">
      <type type="string">navaid</type>
      <alt-restrict type="string">at</alt-restrict>
      <altitude-ft type="double">26000</altitude-ft>
      <ident type="string">WP_pow</ident>
      <lon type="double">14.759868</lon>
      <lat type="double">48.054873</lat>
    </wp>
    <wp n="3">
      <type type="string">navaid</type>
      <alt-restrict type="string">at</alt-restrict>
      <altitude-ft type="double">26000</altitude-ft>
      <ident type="string">BAGSI</ident>
      <lon type="double">14.289717</lon>
      <lat type="double">48.057819</lat>
    </wp>
    <wp n="4">
      <type type="string">navaid</type>
      <alt-restrict type="string">at</alt-restrict>
      <altitude-ft type="double">26000</altitude-ft>
      <ident type="string">MATIG</ident>
      <lon type="double">13.541494</lon>
      <lat type="double">48.058592</lat>
    </wp>
    <wp n="5">
      <type type="string">navaid</type>
      <alt-restrict type="string">at</alt-restrict>
      <altitude-ft type="double">26000</altitude-ft>
      <ident type="string">WP_pow</ident>
      <lon type="double">13.342766</lon>
      <lat type="double">48.069327</lat>
    </wp>
    <wp n="6">
      <type type="string">navaid</type>
      <alt-restrict type="string">at</alt-restrict>
      <altitude-ft type="double">19300</altitude-ft>
      <ident type="string">AMADI</ident>
      <lon type="double">12.913792</lon>
      <lat type="double">48.091317</lat>
    </wp>
    <wp n="7">
      <type type="string">navaid</type>
      <alt-restrict type="string">at</alt-restrict>
      <altitude-ft type="double">10200</altitude-ft>
      <ident type="string">NAPSA</ident>
      <lon type="double">12.345556</lon>
      <lat type="double">48.144167</lat>
    </wp>
    <wp n="8">
      <type type="string">navaid</type>
      <approach type="bool">true</approach>
      <ident type="string">EDDM</ident>
      <lon type="double">11.786086</lon>
      <lat type="double">48.353783</lat>
    </wp>
  </route>
</PropertyList>


Hope it helps.
powoflight
 
Posts: 212
Joined: Fri Mar 25, 2016 11:04 am
Location: LOWW
Callsign: OE-POW
Version: 2020.4
OS: win7 Ubuntu 18.04

Return to Development

Who is online

Users browsing this forum: No registered users and 13 guests