[TUTORIAL]How to Connect Flightgear to VATSIM | WINDOWS,LINUX,MAC

How to make pilots finding airports ...
User avatar
SHM
Posts: 1960
Joined: Mon Sep 14, 2015 3:32 pm
Location: India

Re: [TUTORIAL]How to Connect Flightgear to VATSIM | WINDOWS,LINUX,MAC

Postby SHM » Wed Aug 23, 2017 3:35 pm

New online map for VATSIM

http://accumap-project.com/
FG Pilot (2011-2018)
Prepar3d (2015 - 2023)
MSFS2020 (2020 - )
Image

User avatar
SHM
Posts: 1960
Joined: Mon Sep 14, 2015 3:32 pm
Location: India

Re: [TUTORIAL]How to Connect Flightgear to VATSIM | WINDOWS,LINUX,MAC

Postby SHM » Mon Feb 19, 2018 11:30 am

Navigraph Level-D format procedures to flightgear

  • Download the Level-D formatted files from the Navigraph.
  • Run the executable file. When prompted, choose to extract the data files in a directory on your Desktop (or in another easily accessible place).
  • Open that directory, you will find many XML files , rename the ones you need to ICAO.procedures.xml (where ICAO is the ICAO code of the airport the XML file refers to): move the ones you need from them to $FG_SCENERY/Airports/I/C/A/ICAO.procedures.xml (replace I, C, A and ICAO with the corresponding letters of the ICAO code). (Example: put EDDF.procedures.xml in $FG_SCENERY/Airports/E/D/D/EDDF.procedures.xml).

The third point can be automated to install many procedure files at once:

Skip to the third point for now, first and second needs some editing.

  • If you have Ruby installed on your computer, you can use this http://files.goneabitbursar.com/fg/install-navdat.rb

    Code: Select all

    #!/usr/bin/ruby

    require 'fileutils' #I know, no underscore is not ruby-like
    include FileUtils

    absDest = Dir.pwd + "/" + ARGV[1]
    Dir.chdir ARGV[0]

    Dir['*.xml'].each do |proc|
        a = proc[0, 1]
        b = proc[1, 1]
        c = proc[2, 1]
       
        path = "#{absDest}/Airports/#{a}/#{b}/#{c}/#{proc[0..3]}.procedures.xml"
       
        puts "would copy from #{proc} to #{path}"
        if not File.exists?(File.dirname path)
            puts "Will mkdir_p #{File.dirname path}"
           FileUtils.mkdir_p  File.dirname path
        end
       
       FileUtils.cp proc, path
    end


  • Another possibility, using Python 3, is this extract-navdata.py script ( http://frougon.net/python_dumping_ground/short_scripts/extract-navdata.py ), which can install the files from a directory or directly from a tarball. Run extract-navdata.py --help or python3 extract-navdata.py --help for instructions. You may need to use py -3 instead of python3 on Windows,

    Code: Select all

    #! /usr/bin/env python3
    # -*- coding: utf-8 -*-

    # extract-navdata.py --- Create directory hierarchy and copy procedure files
    #                        for the FlightGear flight simulator
    # Copyright (c) 2015, Florent Rougon
    # All rights reserved.
    #
    # Redistribution and use in source and binary forms, with or without
    # modification, are permitted provided that the following conditions are met:
    #
    # 1. Redistributions of source code must retain the above copyright notice,
    #    this list of conditions and the following disclaimer.
    # 2. Redistributions in binary form must reproduce the above copyright notice,
    #    this list of conditions and the following disclaimer in the documentation
    #    and/or other materials provided with the distribution.
    #
    # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    # POSSIBILITY OF SUCH DAMAGE.
    #
    # The views and conclusions contained in the software and documentation are
    # those of the authors and should not be interpreted as representing official
    # policies, either expressed or implied, of the extract-navdata.py project.

    import sys
    import os
    import re
    import shutil
    import argparse
    import locale
    import tarfile
    import collections

    progname = os.path.basename(sys.argv[0])
    progversion = "0.2"
    version_blurb = """Written by Florent Rougon.

    Copyright (c) 2015  Florent Rougon
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."""


    def errExit(msg):
        print("{0}: {1}".format(progname, msg))
        sys.exit(1)

    def info(msg):
        print("{0}: {1}".format(progname, msg))

    def warning(msg):
        print("{0}: warning: {1}".format(progname, msg))


    def processCommandLine():
        params = argparse.Namespace()

        parser = argparse.ArgumentParser(
            usage="""\
    %(prog)s [OPTION ...] INPUT ODIR
    Create directory hierarchy and copy navigation procedure files for FlightGear.\
    """,
            description="""\
    INPUT can be a directory or tarball containing navigation procedure files.
    Each such file must have a name of the form ICAO.procedures.xml and is copied
    (extracted) by this script as ODIR/Airports/I/C/A/ICAO.procedures.xml.
    Directories are created as necessary.

    ODIR can then be used as an element of FG_SCENERY.

    If INPUT is a directory, the input procedure files must be in that
    directory. Otherwise, INPUT is assumed to be a tarball and the procedure files
    are looked for in all directories of the archive.

    The supported tarball formats are those handled by the Python tarfile module:

      https://docs.python.org/3/library/tarfile.html#module-tarfile

    At the time of this writing, these are: tar, tar.gz, tar.bz2 and tar.xz.

    The home page for this script is:

      http://people.via.ecp.fr/~flo/

    (more precisely,
    <http://people.via.ecp.fr/~flo/python_dumping_ground/short_scripts/>).""",
            formatter_class=argparse.RawDescriptionHelpFormatter,
            # I want --help but not -h (it might be useful for something else)
            add_help=False)

        parser.add_argument('input', metavar='INPUT', help="""\
          input directory or tarball""")
        parser.add_argument('odir', metavar='ODIR', help="""output directory""")
        parser.add_argument('--help', action="help",
                            help="display this message and exit")
        # The version text is not wrapped when using
        # formatter_class=argparse.RawDescriptionHelpFormatter
        parser.add_argument('--version', action='version',
                            version="{name} {version}\n{blurb}".format(
                name=progname, version=progversion, blurb=version_blurb))

        params = parser.parse_args(namespace=params)
        return params


    # Regexp for the procedure file names
    procFileCre = re.compile(r"(?P<ICAO>[A-Z0-9]{4})\.procedures\.xml$")

    def directoryForNavfile(baseDir, name):
        """Return the directory where a procedure file should be written.

        name --- basename of the procedure file (first 4 chars form the ICAO
                 of the corresponding airport)

        """
        return os.path.join(baseDir, "Airports", *name[:3])


    class DirectoryReader:
        def __init__(self, inputDir):
            self.inputDir = inputDir

        def __enter__(self):
            return self

        def __exit__(self, *exc):
            return False

        def copyNavdata(self, outputBaseDir):
            for entry in os.listdir(self.inputDir):
                mo = procFileCre.match(entry)
                ifile = os.path.join(self.inputDir, entry)

                if mo and os.path.isfile(ifile):
                    odir = directoryForNavfile(outputBaseDir, entry)
                    os.makedirs(odir, exist_ok=True)
                    shutil.copyfile(ifile, os.path.join(odir, entry))


    class TarfileReader:
        def __init__(self, filepath):
            self.archiveFile = filepath
            self.tarfile = tarfile.open(filepath, "r", encoding="utf-8")
            self.sanityChecks()

        def __enter__(self):
            self.tarfile.__enter__()
            return self

        def __exit__(self, *exc):
            return self.tarfile.__exit__(*exc) # close the TarFile instance

        def sanityChecks(self):
            for memberName in self.tarfile.getnames():
                if memberName.startswith(os.sep) or \
                        memberName.startswith(os.pardir):
                    errExit("in {!r}, archive member {!r} starting with "
                            "{!r} or {!r}. Huh?! Aborting.".format(
                            self.archiveFile, memberName, os.sep, os.pardir))

        def copyNavdata(self, baseDir):
            """Extract procedure files from a tarball.

            The files will be extracted into subdirectories of 'baseDir'.
            Archives with a non-flat structure are supported.

            """
            # For each airport, we'll remember the directories (hopefully only one)
            # in which we found a procedure file for this airport.
            dirsForICAO = collections.defaultdict(set)

            for member in self.tarfile:
                bn = os.path.basename(member.name)
                mo = procFileCre.match(bn)

                # Only extract regular files that have a suitable base name
                if mo and member.isreg():
                    dirsForICAO[mo.group("ICAO")].add(os.path.dirname(member.name))
                    odir = directoryForNavfile(baseDir, bn)
                    os.makedirs(odir, exist_ok=True)
                    # TarFile.extract() would extract the dirname of archive
                    # members, if any.
                    with open(os.path.join(odir, bn), "wb") as f:
                        shutil.copyfileobj(self.tarfile.extractfile(member), f)

            for icao, directories in dirsForICAO.items():
                if len(directories) > 1:
                    dirS = "\n  ".join(( repr(d) for d in directories ))
                    warning("found procedure files for airport {} in "
                            "{} different directories of the archive:\n\n  {}\n\n"
                            "The resulting file will be undefined.\n".format(
                            icao, len(directories), dirS))

    def main():
        locale.setlocale(locale.LC_ALL, '')

        if sys.hexversion < 0x030200F0:
            errExit("this script requires Python 3.2 or later, aborting.")

        params = processCommandLine()

        # Extract from a directory or tarball?
        if os.path.isdir(params.input):
            reader = DirectoryReader(params.input)
        else:
            info("assuming {!r} is a tarball".format(params.input))
            reader = TarfileReader(params.input)

        info("installing procedure files into {!r}...".format(params.odir))
        with reader as r:
            r.copyNavdata(params.odir)
        info("done")

        sys.exit(0)

    if __name__ == "__main__": main()

  • You could also use a small bash-script to do the work for you. Bash is a shell, native on Linux, also exists on Macs and Windows. Copy the following code into a new file, name it "convert.sh". Put it into the lowest directory, where all the xml-files are stored. (.../Level-D Simulations/navdata/)
    #!/bin/bash

    Code: Select all

    for file in *.xml
      do
        FILENAME=$( echo $file | sed s/.xml// )
        DIR=$( echo "$FILENAME" | sed s/[A-Z0-9]\$// )
        ONE=$( echo "$DIR" | sed s/[A-Z0-9]\$// | sed s/[A-Z0-9]\$// )
        TWO=$( echo "$DIR" | sed s/[A-Z0-9]// | sed s/[A-Z0-9]\$// )
        THREE=$( echo "$DIR" | sed s/[A-Z0-9]// | sed s/[A-Z0-9]// )
        #echo "$file => $DIR => $ONE / $TWO / $THREE / $file"
        mkdir -pv "../Airports/$ONE/$TWO/$THREE"
        cp -v $file "../Airports/$ONE/$TWO/$THREE/$FILENAME.procedures.xml"
      done

    • Now it's time to fire up a terminal and navigate to the files: cd /path/to/Level-D Simulations/navdata
    • To make the script executable type: chmod +x convert.sh
    • Now you're ready to run the script! ./convert.sh

Source;
FG-wiki
Credits to respective authors.
Last edited by SHM on Mon Feb 19, 2018 11:57 pm, edited 3 times in total.
FG Pilot (2011-2018)
Prepar3d (2015 - 2023)
MSFS2020 (2020 - )
Image

User avatar
IAHM-COL
Posts: 6455
Joined: Sat Sep 12, 2015 3:43 pm
Location: Homey, NV (KXTA) - U.S.A
Contact:

Re: [TUTORIAL]How to Connect Flightgear to VATSIM | WINDOWS,LINUX,MAC

Postby IAHM-COL » Mon Feb 19, 2018 6:04 pm

Nice info.

Thanks SM.
https://raw.githubusercontent.com/IAHM-COL/gpg-pubkey/master/pubkey.asc

R.M.S.
If we gave everybody in the World free software today, but we failed to teach them about the four freedoms, five years from now, would they still have it?

User avatar
N3266G
Posts: 252
Joined: Sun Sep 13, 2015 12:20 am
Location: Some Alternate Universe.
Contact:

Re: [TUTORIAL]How to Connect Flightgear to VATSIM | WINDOWS,LINUX,MAC

Postby N3266G » Mon Feb 19, 2018 6:10 pm

Looks like someone's interest just got peeked.
Image Image

User avatar
Wecsje
Posts: 167
Joined: Wed Aug 16, 2017 4:25 pm
Location: The Closet, Under the Stairs, the Netherlands

Re: [TUTORIAL]How to Connect Flightgear to VATSIM | WINDOWS,LINUX,MAC

Postby Wecsje » Mon Feb 19, 2018 6:37 pm

This guide is why to overcomplicated, first, the navdata doesn't come as ICAO.procedures.xml, but as just ICAO.xml.

The easiest way to convert this, is to use this bash script (usable on all platforms):

Code: Select all

#!/bin/bash

for file in *.xml
  do
    FILENAME=$( echo $file | sed s/.xml// )
    DIR=$( echo "$FILENAME" | sed s/[A-Z0-9]$// )
    ONE=$( echo "$DIR" | sed s/[A-Z0-9]$// | sed s/[A-Z0-9]$// )
    TWO=$( echo "$DIR" | sed s/[A-Z0-9]// | sed s/[A-Z0-9]$// )
    THREE=$( echo "$DIR" | sed s/[A-Z0-9]// | sed s/[A-Z0-9]// )
    #echo "$file => $DIR => $ONE / $TWO / $THREE / $file"
    mkdir -pv "../Airports/$ONE/$TWO/$THREE"
    cp -v $file "../Airports/$ONE/$TWO/$THREE/$FILENAME.procedures.xml"
  done


Save this as a .sh script, and give it a name like "sorting".

Move the sorting.sh script into the navdata directory (where all the ICAO.xml files are).

From the navdata folder, remove all files that are not ICAO.xml (sort by type, and they should come up at the top).

Then, open terminal on mac or linux, or open Bash on Ubuntu on Windows for windows.

CD to the navdata directory, and execute the shell script: ./sorting.sh

Wait (this may take a few minutes).

You will see when it is done when it doesn't create more lines in the terminal window.

Outside of the navdata folder, a new folder called airports will be created, simply create a folder called procedures, move the airports folder into it, go to the FG launcher, select the "procedures" folder as additional scenery location, and make sure it is at the top of the list. Voila.

I'm working on a complete and simple tutorial about everything people need to do to connect to VATSIM with FG and get the most out of it.

Regards,

Charlie

PS: BIG credit to Pinto for helping me with this months ago :D
Twitch Streams: https://www.twitch.tv/wecsjelive
Contact methods: Discord (Wecsje#6351), FlightSims United discord (https://discord.me/flightsimsunited), Steam (Wecsje)
Track me on VATSIM: https://vatstats.net/pilots/1397313

Octal450
Posts: 2184
Joined: Sun Oct 18, 2015 2:47 am

Re: [TUTORIAL]How to Connect Flightgear to VATSIM | WINDOWS,LINUX,MAC

Postby Octal450 » Mon Feb 19, 2018 11:24 pm

The loadmanager program planned for the IDG Airbus' and MD-1X will also include an automatic of this via the click of one button Windows. Possibly Linux and OS X if I can figure that out.

Wecsje/PINTO's bash script is the easiest in my opinion for now.

Kind Regards,
Josh

User avatar
SHM
Posts: 1960
Joined: Mon Sep 14, 2015 3:32 pm
Location: India

Re: [TUTORIAL]How to Connect Flightgear to VATSIM | WINDOWS,LINUX,MAC

Postby SHM » Mon Feb 19, 2018 11:27 pm

Why can't people read before commenting :roll:
What does the third point in my post say :|

It was taken straight from the wiki, so I corrected some small errors, but the scripts were there all along. So, you've the choice to use ruby/python/bash whichever you prefer.

I'm working on a complete and simple tutorial about everything people need to do to connect to VATSIM with FG and get the most out of it.

Great to hear that you've stopped whining and decided to do something useful for once. :D

PS: BIG credit to Pinto for helping me with this months ago

This has been on the wiki years ago, so you know where it came along from in the first place.

Chris blues added it on Sept 29, 2015
http://wiki.flightgear.org/Special:MobileDiff/87495
FG Pilot (2011-2018)
Prepar3d (2015 - 2023)
MSFS2020 (2020 - )
Image

User avatar
Wecsje
Posts: 167
Joined: Wed Aug 16, 2017 4:25 pm
Location: The Closet, Under the Stairs, the Netherlands

Re: [TUTORIAL]How to Connect Flightgear to VATSIM | WINDOWS,LINUX,MAC

Postby Wecsje » Mon Feb 19, 2018 11:53 pm

@SHM

Your post was way too complicated, and big credits to pinto because he helped me with this.

And whining? You better stop being a complete asshole and grow up for once (and this is the only thing I will say to you).

Regards,

Charlie
Twitch Streams: https://www.twitch.tv/wecsjelive
Contact methods: Discord (Wecsje#6351), FlightSims United discord (https://discord.me/flightsimsunited), Steam (Wecsje)
Track me on VATSIM: https://vatstats.net/pilots/1397313

User avatar
SHM
Posts: 1960
Joined: Mon Sep 14, 2015 3:32 pm
Location: India

Re: [TUTORIAL]How to Connect Flightgear to VATSIM | WINDOWS,LINUX,MAC

Postby SHM » Mon Feb 19, 2018 11:58 pm

Wecsje wrote:Your post was way too complicated, and big credits to pinto because he helped me with this.


Why cant you read my post before commnenting, so again read what I said earlier
SHM wrote:
Wecsje wrote:PS: BIG credit to Pinto for helping me with this months ago

This has been on the wiki years ago, so you know where it came along from in the first place.

Chris blues added it on Sept 29, 2015
http://wiki.flightgear.org/Special:MobileDiff/87495


Also the post I put had three options for ruby /python/ bash. And it explained to people what it does. I don't want people to do anything on their pc without knowing what it does


And whining? You better stop being a complete asshole and grow up for once (and this is the only thing I will say to you).

I'm traveling now, I'll get back to you later
Last edited by SHM on Tue Feb 20, 2018 12:14 am, edited 1 time in total.

User avatar
SHM
Posts: 1960
Joined: Mon Sep 14, 2015 3:32 pm
Location: India

Re: [TUTORIAL]How to Connect Flightgear to VATSIM | WINDOWS,LINUX,MAC

Postby SHM » Tue Feb 20, 2018 12:07 am

Run a diff command if you don't believe :lol:
FG Pilot (2011-2018)
Prepar3d (2015 - 2023)
MSFS2020 (2020 - )
Image


Return to “ATCing”

Who is online

Users browsing this forum: No registered users and 7 guests