Sign in to follow this  
Guest Testili

Reading data from .bgl

Recommended Posts

Hi folks,I'm a real newbie when it comes to .bgl. For bad luck it's the only way for me, to obtain airport informations, like lat/lon of runways (or is there another?). (the new simconnect facilities feature doesn't give access to runway lat/lon too, for bad luck). My application must work for every airport, and using external tools like SDE is no solution, too. As I said: the only way is to use the .bgl files that ship with fsx.So, my C# application will have to read the APX*.bgl file to scan for that runway information. Exactly that is the problem: The .bgl looks like cryptic to me and I have no clue, how to make it in any way readable with C#. I can imagine, that there would be some way to decrypt the .bgl to somewhat more readable. Is here anyone, who could point me to the right direction?Thanx very much,Sincerely,Chris.

Share this post


Link to post
Share on other sites
Help AVSIM continue to serve you!
Please donate today!

>I can imagine, that there would be some way to decrypt the>.bgl to somewhat more readable. >>Is here anyone, who could point me to the right direction?There are quite a lot of programming data and utilities around which will help. Just a quick Google gets me this linkhttp://www.jordomedia.com/RSS/l_op=viewrss/lid=12479.htmlwhich seems to be a collection of excellent pointers.RegardsPete

Share this post


Link to post
Share on other sites

Thank you guys,so far, I know both sites already. The point is: there are tools offered, which I cant use for my purposes. Of course I can read a .bgl with SDE or something. But I need to hardcode the reading of runway lat lon into my program. So these tools dont help me.The bgl PDF i know too. It might be helpful, but Im too newbie to understand, how it could help me with my coding problem.So, my problem remains: I need to access the runway information, which settles inside the .bgl, via c#. I dont know, how to decrypt the bgl, to find the information.Can you help on?Sincerely,Chris.

Share this post


Link to post
Share on other sites

>so far, I know both sites already. The point is: there are>tools offered, which I cant use for my purposes. Of course I>can read a .bgl with SDE or something. But I need to hardcode>the reading of runway lat lon into my program. So these tools>dont help me.Check further. Some of the tools come with source code which have data format declarations. Some even give you the references to semi-professional documentation of the BGLs themselves. I know this because I have followed these routes myself.>The bgl PDF i know too. It might be helpful, but Im too newbie>to understand, how it could help me with my coding problem.I'm not sure what "BGL PDF" you refer to, but if it is the definition of the BGL formats then you won't get any better help. If you know the format of the BGLs and you know how to find them all (follow all the "enabled" layers in the SCENERY.CFG file) what else could you possibly need to know to get to work?>So, my problem remains: I need to access the runway>information, which settles inside the .bgl, via c#. I dont>know, how to decrypt the bgl, to find the information.Have you not found anything in any of those links? Are you sure? I really don't think you are looking hard enough. Try also http://www.scenery.org/design_utilities_d.htm. Winifried Orthmann's BGL analyse package includes a good document. I based my MakeRunways utility on that. The differences to FSx aren't great either.RegardsPete

Share this post


Link to post
Share on other sites

>So, my problem remains: I need to access the runway>information, which settles inside the .bgl, via c#. I dont>know, how to decrypt the bgl, to find the information.I've just checked. In one link here you could get Mr. Orthmann's detailed format of FSX BGLs, and in the links I provided you could certainly also get his earlier FS2004 data. They are not that far apart in fact.Both detail the precise format of the BGL files, within which is the data you require. So when you say "I dont know, how to decrypt the bgl, to find the information", you do not actually need to decypt anything, as Mr. Orthmann has so kindly done it for you already!I can vouch for his work as i have used it successfully.I can assure you you won't get anything better. Short of someone writing your code for you, that is it!If you want a ready-made data base in easy-to-read format, you are free to use my MakeRunways utility. The current version (4.10) is available on my Support Forum over on SimMarket (see either of the Downloads announcements), and the ZIP now includes information on the CSV file formats.RegardsPete

Share this post


Link to post
Share on other sites

Thank you, Pete, for your effort. It would be easier for you to say "let this newbie go, he's too stupid" ^^ I appreciate your help very much.I understand your point, indeed I spent more than a day reading about BGL.My problem is so far more basic: It is a coding problem more likely than a "BGL-understanding-one". I see i.ex. Offset adresses and so on in this PDF you mentioned. I also manage to open the bgl in a hex editor and find some of the things mentioned in the PDF. So far, when it comes to the programmatic view, how do I read in the BGL file with .NET, how do I decode it? I see, that many programs use the the ChilkatDotNet dll for decoding i.ex ... I wonder, is the BGL stuff encoded in a binary format or something else, ...So, I would look for a hint, how to decode the stuff I read from a bgl i.ex. with a streamreader-function, in some format where I can look for the offsets and stuff mentioned in the PDF.Well .... perhaps this is too basic to ask here. It would be enough, if you say, that if I read out the bgl into a hex-format, that I then could get the informations like runway lat lon. Issit like that? Should I decode the bgl to a hex-format?Sincerely,Chris.

Share this post


Link to post
Share on other sites

Hi ChrisAll you have to do is to open a FileStream and read it with a BinaryReader. That together with the PDF-file should make it fairly easy to read all the values you want.Klas

Share this post


Link to post
Share on other sites

You say:>I also manage to open the bgl in a hex editor and>find some of the things mentioned in the PDF.and then later:>I wonder, is the BGL stuff encoded in a>binary format or something else, ...but surely your first discovery answers your second? Yes. binary. Mr. Orthmann's guides clearly lay out the bits and bytes and how to find them within the binary file.>how do I read in the BGL file>with .NETI am sure that the facility to open and read files in binary format is present in every possible language you may find in .NET or in any other compiler package for that matter. It is the same as reading any other type of file except you open the file as a binary file, not text, and read it in either in chunks (or your chosen size) instead of 'lines', or better, get its size, allocate enough memory for the whole file, and load it all at once. > how do I decode it? Using Mr. Orthmann's documentation. That is exactly what it is for. Do it by hand first using your hex editor. When you see how to find data by hand, program it that way.>I see, that many programs use the the ChilkatDotNet dll for>decoding i.ex ... Never heard of that. Sorry.>Well .... perhaps this is too basic to ask here. It would be>enough, if you say, that if I read out the bgl into a>hex-formatYou don't want to convert a binary file to hex ("hex" is a character-based representation using 0-9 and A-F characters). You just read the file as a plain binary file. No conversion at all. Read it all to a character or, better, BYTE array of sufficient size. (BYTE is merely unsigned char).Then offset 0 in the file is byte[0] in that array, offset 356 is byte [356], etc. A 32-bit integer at offset 64 is at bytes[64] to [67] inclusive. But you should be defining structures to match Mr. Orthmann's data formats and mapping those to the binary data array appropriately. (Note that those <> parentheses were meant to be square brackets but this web program seems to convert them).All this is really a bit advanced as a training program for a new programmer. You've actually got to scan thousands of BGLs to find the ones you want in the first place in any case.If your object is simply to find information about specific airports I would recommend you look at my MakeRunways program. It is free for use as you wish.Pete

Share this post


Link to post
Share on other sites

Thanx alot.I think I get the clue of it now due to your tips. Have a nice day,sincerely,Chris.

Share this post


Link to post
Share on other sites

>Check further. Some of the tools come with source code which>have data format declarations. Some even give you the>references to semi-professional documentation of the BGLs>themselves.Just being curious, is there any other and/or better than Winfried Orthmann's documentation available anywhere? The only thing that had helped me in the past (was it FS8 or FS9... can't quite remember) was the source code of Traffic Tools by Lee Swordy (ttoolssource30.zip IIRC) which contained a tool to read all airports, including some very helpful and complete data definitions within the code. For FSX though all I currently have is that PDF mentioned above. That alone being more than helpful, of course. Just curious if there is something else out there.Thanks,Etienne

Share this post


Link to post
Share on other sites

>For FSX though all I>currently have is that PDF mentioned above. That alone being>more than helpful, of course. Just curious if there is>something else out there.I doubt there's much else for FSX yet, but the airport data formats are not all that different to those for FS9, and I think some folks have posted source of BGL analysers for FS9. You'll need to search. Didn't one of those links in this thread take you close to something suitable?Personally I always find trying to decode someone else's code more confusing that writing my own from scratch. Pete

Share this post


Link to post
Share on other sites

I didn't find something else, too.I wonder, where the author found all these informations for the pdf. Must be a smart head ^^Pete, I agree partially, so far, without a point to start it's #### difficult. But you guys gave me that point, I guess. Still fighting with the bits and bytes, but well, I will succeed :( Tx ~Sincerely, Chris.

Share this post


Link to post
Share on other sites

>I didn't find something else, too.You will have to learn to use search engines like Google. I found this in about 5 minutes of following links and narrowing down searches:http://www.fs2000.org/last/news.asp?id=8022The BGLXML zip includes the program and the sources, for FS2004 of course.>I wonder, where the author found all these informations for>the pdf. Must be a smart head ^^It takes a lot of hacking. It's a process similar to debugging, which you will also have to learn to be a programmer! ;-)RegardsPete

Share this post


Link to post
Share on other sites

Hi Chris,I confirm that the FSX_File_Structure.PDF written by Winfried Orthmann (follow the above link given by Etienne) is the best documentation I have found about BGL.I wrote a set of procedures to extract airport data in a Delphi program, It works well.Good luckA+Jacky :-)

Share this post


Link to post
Share on other sites

Hi Jacky,that sounds cool. I assume, that Delphi source is copyright, correct? In case it's not: soccy @ fsxtools.de So far, I would not give out my sources and I really 100% understand, if you don't. You spent much time for coding that, I'm sure.That bgl pdf is really well done. I'm still more likely fighting with getting a C# reader to work, that matches that pdf. The C# coding is not the problem, too, more like to work with the datas Im reading.My proggy can read it out like that (all from Kavieng Airport APX*.bgl, beginning always at offset 0):a) (Normal Byte Array):1 2 146 25 56 0 0 0 0 97 70 168 182 189 198 1 3 24 5 8 5 0 0 0 10 148 9 0 10 148 9 0 11 148 9 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 0 0 1 0 0 0 1 0 0 0 156 0 0 0 16 0 0 0 44 0 0 0 1 0 0 0 1 0 0 0 172 0 ...So far, that doesnt match too much of the PDF structure, does it? Or I didnt get the clue yet.:( (Strings)8...That doesnt help anything^^c) (Bits)00000001000000101001001000011001001110000000000000000000000000000000000001100001010001101010100010110110101111011100011000000001000000110001100000000101000010000000010100000000000000000000000000001010100101000000100100000000000010101001010000001001000000000000101110010100000010010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001100000000000000000000000000000001000000000000000000000000000000010000000000000000000000001001110000000000000000000000000000010000000000000000000000000000001011000 ...Doesnt look helpful too :(d)(Hex) 0102921938000000006146A8B6BDC60103180508050000000A9409000A9409000B94090000000000000000000000000000000000000000000300000001000000010000009C000000100000002C0000000100000001000000AC00000010000000220000000100000002000000BC000000200000002A0000000400000001000000DC00000010000000270000000300000001000000EC000000100000000A94090001000 ...Well ... hmm ... I don't know, if thats helpful.Well, all in all, I still don't have really found the way to interprete the things. But I think I need to spend some more time with this stuff, I'm simply completely new to this.Thanx for all your support & help,Greetings,Chris.

Share this post


Link to post
Share on other sites

>>My proggy can read it out like that (all from Kavieng Airport>APX*.bgl, beginning always at offset 0):Shame you don't give the filename, as I couild have checked further, but comparing a typical APX*.BGL in a Hex Editor with your decimal (ugh) rendition, just the 1st 16 bytes:01 02 92 19 38 00 00 00 70 D1 22 CD B1 BD C6 01compared to yours (converting your decimal bytes to a hex representation):01 02 92 19 38 00 00 00 00 61 46 A8 B6 BD C6 01looks pretty likely to be right to me. Looking at the PDF for interpretation:Offset 0, length 2: you have 01 02"New BGL ID" = 0x0201. Correct. (remember Lo-Hi order on all Intel processors).Offset 2, length 2: you have 92 19"probably version": 0x1992. Correct.Offset 4, length 4: you have 38 00 00 00"size of header" = 0x00000038. Correct.and so on.I don't understand why you think you read it wrong. You are just not interpreting it according to the PDF!Define some structures, use the correct sizes and types. It'll all come much more easily. If you don't understand that much programming you do really need to read up more first.RegardsPete

Share this post


Link to post
Share on other sites

Hi ChrisAs I wrote in another post earlier, it's pretty easy (well, at least I think so) to read the data from the file using a System.IO.FileStream and a System.IO.BinaryReader. Following the PDF-file, it really shouldn't be much of a problem to get the information you want. The FileStream has methods for going to the offset you want, and the BinaryReader has methods for reading the kind of values that should be in that position. In case you don't know, a WORD is the same as an UInt16 (ushort) in C#, and a DWORD is the same as an UInt32 (uint). Other than that, I think all types are called the same in the BGL documentation and in C#. I wrote a small program to try it out, and here's the beginning, if that's any help to you. Pretty much what I do is I check the first three values to see that they match what's specified in the PDF-file, and then move the stream position to the next interesting value, which is the number of section pointers, located at offset 20, after which I read the value.

private FileStream fs;private BinaryReader br;(...)this.fs = new FileStream(this.openFileDialog1.FileName, fileMode.Open);this.br = new BinaryReader(fs);(...)if (br.ReadUInt16() != 0x0201)   MessageBox.Show("Error (new bgl ID)");if (br.ReadUInt16() != 0x1992)   MessageBox.Show("Error (version)");if (br.ReadUInt32() != 0x0038)   MessageBox.Show("Error (headersize)");fs.Seek(20, SeekOrigin.Begin);uint numberOfSectionPointers = br.ReadUInt32();...

I hope this helps you,Klas

Share this post


Link to post
Share on other sites

Wahhh, I used an old version of Orthmanns PDF. The new one is clearer.One last newbie-question: What does that "0x" mean, thats always shown there, i.ex. 0x03c? I.ex. he's once giving the offset like "0,2,4,...", next time it's "0x00, 0x04, ..."Or in the lat/lon calculation he's also using a 0x... value.(I know, that this must be a really basic question - anyways, "don't ask, stay stupid" ^^)Also I did not understand, Pete, why u said "dont convert to hex". Would it be easier to use plain byte reading? Isn't Orthmann's doc some way referring to a hex-visualisation, too?Thank you once more, you guys are good teachers, explaining really step by step. Really appreciated!Sincerely,Chris.

Share this post


Link to post
Share on other sites

Klas,that is really a big help. It's a good way to learn from some working code. Thank you really very much,Chris.

Share this post


Link to post
Share on other sites

0x just means that the number is in hexadecimal form (base 16) instead of the regular decimal form (base 10). You can use that way of writing when writing your code too, so you don't have to convert anything. E.g.,int number = 0x1F;is the same asint number = 31;Klas

Share this post


Link to post
Share on other sites

>Also I did not understand, Pete, why u said "dont convert to>hex".That was some way back, wasn't it? I can't even find it. But going on memory, you were talking about a hex representation in character format, using characters '0'-'9' and 'A'-'F'. You don't particularly want to convert anything in the BGL into any particular numerical form, it IS in the form it should be in already! i.e Binary. You don't "convert" the binary value 0x1992 to the character "0x1992" except to print it or show it for humans to read -- your program is surely meant to understand and use the values as they are, i.e. in binary. Whether you want to write them down or print them out in hex, binary, octal, decimal or whatever is irrelevant.RegardsPete

Share this post


Link to post
Share on other sites

Hey Klas, Pete,thank you very much once more. I really start to understand that stuff, wow^^ As soon as I have the time to code the runway lat/lon proggy I will show you the result, so that you see, how far your patient explanations brought me.I really need to say, that thanks to you dudes this forum is a really great resource. If I get asked by MS to propose a MVP, you're my choice^^Thank you very very much,sincerely,Chris.

Share this post


Link to post
Share on other sites

Hi again,I had a little bit of time and made big steps forwards understanding (and successfully reading) .bgl files. Actually I reached my original goal to read out lat and lon of runways. But I also need to read out the ICAO ...So, my new problem: Calculating ICAO.I don't understand Orthmann's description there.Let's take Kavieng Airport again.ICAO for Kavieng is AYKV.Following Orthmanns description:A = 12, Y = 36, K = 22, V = 33So my calculation: (((12*38 + 36) * 38 + 22) * 38 + 33) * 38 = 27030046 ( = 19c721E)27030046 * 32 (= 0x20) = 864961472 = 33 8E 43 C0 So far, the .bgl contains at ICAO position: a1 52 5b 01 :) *gg*Now beat me, I know that I do something incredibly wrong here ... Also I would like to go the other way around, like going from a1 52 5b 01 to the ICAO, since normally I do not know that its AYKV.Has someone experience how to calculate that special format?Regards,Chris.

Share this post


Link to post
Share on other sites

Hi Jacky,you solved that in a smart way (you actually seem to be that way hehe). It's incredible, but it's working! It also included the answer to my question, that I need to calculate things other way around if I go from encoded ICAO to string one.Well, what can I say, once more you made my day :)Found ICAO:ada95 Decoded: 33 --> VFound ICAO:491e Decoded: 22 --> KFound ICAO:1ec Decoded: 36 --> YFound ICAO:c Decoded: 12 --> AIcao = AYKVThanx alot!!Cheers,Chris.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this