• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

P3D v2 Converting Airport BGL's to XML

Messages
61
Country
turkey
Hi,

There is a topic in wiki about FSX bgl file formats.
http://www.fsdeveloper.com/wiki/index.php?title=BGL_file_format_(FSX_airport)

But there is no sample. I am targeting a BGL to XML converter using this information but I am not familiar with C++ and don't understand how to use these offsets. I am using C#. I kindly ask for some help. Can someone please lead me or give an example how to do it? If possible I prefer examples for C# .

Thanks in Advance,
Ahmet
 
Do you have any experience in reading binary files?

How much information do you want to extract?

Is it a straight decompile followed by outputting XML such as Bgl2Xml or is there something else involved?
 
Hello Jon,

I don't have any experience in binary files.
I want to extract information such as airport name, country, code, coordinates, parking positions and runway numbers. I will use these information to let user modify flight files where one can change the location and parking position prior to flight. So one can prepare the flight. Same as the FSX menu itself.

Thanks in advance
Ahmet
 
OK - well the information on the Wiki is probably not enough to do what you need. This file was written by Winfried Orthmann in 2006 and provides a lot more detail on the format

http://www.mediafire.com/view/r721247gwineyxs/FSX File structure (Winfried).pdf

Remember that we have no access to this format other than by reverse engineering the binary file (not so easy!). The format is proprietary and the copyright lies with MS I think. So far they never stopped us working on decoding the files. However if Lockheed Martin choose to change, extend or add to the format then they may not be so obliging.

As far as coding this is concerned then you will need to do a number of things

  • Check the file is a valid type
  • Extract the Sections
  • For each section read the objects and extract the data
  • If you want it to XML then you will need to convert the data you extracted into valid XML or into a text file or whatever

The simplest way to treat the binary is to put it into something like a byte array.

Here is a small example of code to handle an airport Comm. The first method is actually creating XML and the second is extracting the data from a chunk of binary file in a byte array.


Code:
    public override string Code(FSVersion compileVersion, FileType fileType)
        {
            if (skipCompile && !FSEnvironment.GenerateXmlForInfo)
            {
                return string.Empty;
            }

            var code = new XmlCode(false);
            if (skipCompile)
            {
                code.Include("<!-- STOCK DISPLAY ITEM NOT BEING COMPILED -->" + Environment.NewLine);
            }

            code.OpenElement("Com");
            code.Attribute("frequency", frequency, "000.0000", false);
            code.Attribute("type", comType.ToString(), false);
            code.CloseElement("name", FSUtil.CleanInvalidCharacters(comName).ToUpper());
            return code.Output;
        }


        public override void Decompile(byte[] rawData)
        {
            base.Decompile(rawData);
            int subRecordSize = BitConverter.ToInt32(rawData, 2);
            comType = (ComType)BitConverter.ToInt16(rawData, 6);

            frequency = FSConvert.BglFreqToDecimal(BitConverter.ToInt32(rawData, 8));

            // Some Com records do not have a name and are only 12 bytes long
            if (subRecordSize > 12)
            {
                comName = FSConvert.Bytes2String(rawData, 12, subRecordSize - 12);
            }

            name = "COM " + comType + " " + frequency.ToString("###.000");
        }

Of course this comes out of my decompiler and there are a lot of static methods and other routines that do work so it is just an example ;)
 
Hello Jon,

I am crushed and smashed but I finally managed to decompile the BGL files, (my first experience with the binary files by the way) my bones are aching after 20 days of hard work (decompiled only what I need, the Header, Airports partially and Region Names not %100 of course but I got the idea) however I got a question.
The region names section construct a table of their own and the airport section is another table. There is no unique primary keys to combine these two tables but only airport names and ICAO codes which are string values (not a good candidate for a primary key value) Am I missing something or I should use either one of these string values?

Thank you again for helping me by providing the file.

Best Regards,
Ahmet
 
I am pleased you got there. It can seem very daunting at times. I am not sure what you are trying to do with a key. Are you looking to create one for you records or are you looking for a key already in the file?

Sent from my Sony Xperia with Tapatalk
 
I have the airport data in one hand, and regions on the other. From the regions data I can filter countries, cities, airports etc. When I make my selection of an airport lets say LTAU Erkilet AB then using this information I want to find it in the airport data and access the airports details, like runways, starts, parkings, taxiways etc. The only key I can use is the ICAO code or the Airport name which will match in both tables.

So what I am asking is "how do we access the airport data from regional names list? or vice versa" Where is the relation combining these two separate sections (Only the ICAO/Airport Name or something else)?
 
Ah - OK I need to look at that. I seem to recall that it not built into the Bgl file but perhaps I am wrong. There are a number of things that are not linked in the Bgl file. Taxisigns and ILS are a couple. I have to do a bunch of post processing to link things up.

EDIT
I may still not be clear as to your goal, but there is a bgl section of name records that has tables of regions, airports and so on. I use that to post process the region ID into the airport record. ADE for example has a collection of name records that is created from that section in the Bgl file. So a search of that collection with say the ICAO will return the region of the airport. At the same time a search on say country will generate a list of airports assigned that country.

If you look at the Open Airport Dialog in ADE you will see a tree (region is not there but country and state are) This tree is generated from the name records
 
Last edited:
Yes I know your tree (regions seems always to be empty). That is what I exactly looking for. I have the region names, section names, sub sections and airport data. But the only thing I can find in the region names list which combines to the airport data is the icao code or the airport name. But there can be some other reference that directly points the two tables to each other. Maybe there is no reference and the only way is to use either the name of the airport or the ICAO code. I can not be sure as I am not experienced enough with the file but you already solved that. :)

Also I could not find how to match region names as which airport is in which city and city in country .... The lists seem to be unrelated. I have list of countries, airport names, icao codes, all separate and independently.
 
Last edited:
If you want to email me - jon AT scruffyduck DOT co DOT uk then perhaps we can work on some code together and get it to work for you. The link is through name records but I need to go back into some rather messy code to be sure I am telling you the correct things.
 
I solved the second problem. I simply didn't realize the structure of the ICAO table in regions section at first place but then suddenly it occured to me:). I realized that ICAO table include the ID's to reach other data such as airports, cities etc.

But first question still remains. I don't know what code to send the codes are all meshed up to each other. there is no significant part that I want to ask for in my code. But I can send you the whole project if you like. But as you sad earlier you had to recall what you did yourself it would be too messy with my whole project.

At the end I got some data tables like airport, names

AIRPORT
-----------
airportName
ICAO
lat,
lon,
magvar,
trafficscalar
....

NAMES
-------------
ICAO
RegionName
CountryName
StateName
CityName
AirportName

the only relation I can find between these two tables binding each other is the ICAO code.
 
Last edited:
Hi Folks

Ahmet -
Sorry I hadn't spotted this thread.

Save yourself some work,
by downloading Jim Keir's excellent Mission Editor for P3D

First time you run it,
it'll generate a large XML file containing all the data you need.
You can then use XSL to display/format/extract whatever you need.

The file is named - AirportDefs.xml

EDITED to give correct file location.

To find that file, in the Mission Editor
CLICK -> MENU -> EDIT -> PREFERENCES
A tabbed dialog box opens.
CLICK -> PATHS
The path you require is in the second box, titled -
- Template files, Recipes and other appication files........

HTH
ATB
Paul
 
Last edited:
Back
Top