Parsing Open Source maps from garmin (*.img extension)

Hello yesterday i try to parse Open Source *.img map files from Garmin.
I found some information but i cant read all of data.
Documentation is here:
http://wiki.openstreetmap.org/wiki/OSM_Map_On_Garmin/IMG_File_Format
Here is sample code in C++ (but it can be only run in linux)
http://sourceforge.net/projects/garmin-img/

When i try to use documentation from wiki i have problem with reading subfiles like "TRE" files.
Can somebody help me with find more information? or maybe someone can compile this code in linux? Please help.
l3m0nAsked:
Who is Participating?
 
BobcsiConnect With a Mentor Commented:
ReadInt32 is a function, what read integer (4 byte) from current file position;
and ReadInt16 read a word (2byte)

TIMGSubFileType is an own class for store the read data.

I have many class and source code for process img file, so i can send my files, if you give an email address or something...
0
 
BobcsiCommented:
A few days ago I made a Garmin IMG parsing program in Delphi.
What is the exact problem?
0
 
BobcsiCommented:
I attached a good specification
imgformat.pdf
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
l3m0nAuthor Commented:
i was using delphi too, but i get problem with reading:
1. File type of subfile (TRE) i need to get: "GARMIN TRE" but i got "GARMIN"
Can You paste some part of code?
0
 
BobcsiCommented:
Are you parsing the FAT table?
procedure TGarminIMGFile.ParseFAT;
var
  I: integer;
  endOfParts: integer;
  FATStart: integer;
  firstByte: byte;
  FATLength: integer;
  nBlock: integer;
  FileName, FileExt, FullFileName: string;
  FileType: TIMGSubFileType;
  FileSize, PartNumber: integer;
  SubFile: TIMGSubFile;
  iCount: integer;
  LastBlock: integer;
begin
  F.Seek($01FE);
  endOfParts := F.ReadUInt16;
  if (endOfParts <> $AA55) then
    Exception.Create('Bad partition table end!');

  FATStart := $0200;
  while True do
  begin
    F.Seek(FATStart);
    firstByte := F.ReadByte;
    if firstByte = 1 then
      break
    else
      Inc(FATStart, FAT_BLOCK_SIZE);
  end;

  F.Seek(FATStart + $0C);
  FATLength := F.ReadInt32 - FATStart;
  if FATLength < 0 then
    Exception.Create('Invalid FAT length: ' + IntToStr(FATLength));

  Inc(FATStart, FAT_BLOCK_SIZE);


  F.Seek(FATStart);
  nBlock := FATLength div FAT_BLOCK_SIZE;

  for I := 0 to nBlock - 1 do
  begin
    F.Seek(FATStart + I * FAT_BLOCK_SIZE);
    firstByte := F.ReadByte;
    if firstByte = $01 then
    begin
      FileName := F.ReadString(8);
      FileExt := F.ReadString(3);
      FileType := GetSubFileType(FileExt);
      FullFileName := FileName + '.' + FileExt;
      FileSize := F.ReadInt32;
      PartNumber := F.ReadUInt16;

      Log(Format('FAT block at 0x%s:', [IntToHex(FATStart + I * FAT_BLOCK_SIZE, 4)]));
      Log(Format('  FileName: %s, FileSize: %d, PartNumber: %d', [FullFileName, FileSize, PartNumber]));

Open in new window


Here i got example:
42100010.TRE
42100010.RGN
42100010.LBL....etc
0
 
l3m0nAuthor Commented:
i dont understand this code:
FileSize := F.ReadInt32;
      PartNumber := F.ReadUInt16;

Open in new window


and this type:

  FileType: TIMGSubFileType;

Open in new window

0
 
l3m0nAuthor Commented:
Can You paste something else?
0
 
l3m0nAuthor Commented:
my email is: l3moniak2@gmail.com
Very thanks for help.
0
 
l3m0nAuthor Commented:
Could you send me it please?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.