File Format

To properly navigate within an open map file, it is essential to know where you are. With this in mind, I will show you how to properly walk through an entire FCW file and identify all the entities with it.

To start, you have already seen the file information and the header. The file information does not follow the rules that every other entity within the file follows, but it suffices to know that it is 128 bytes long.

Starting with the 129th byte and the next three bytes, we have a ‘WORD’. If you remember, the file format is described in assembly language and uses such strange terms as ‘SBYTE’, ‘DWORD’ and ‘REAL4’. These are the variable types in assembly just like ‘String’, ‘Long’, and ‘Single’ are used in Visual Basic.

Here is a list of assembly variable types and there length:

  • ‘BYTE’ = A single byte
  • ‘SBYTE’ = A variable length string. Usually followed by a length.
  • ‘WORD’ = Two bytes starting with the least significant.
  • ‘DWORD’ = Four bytes starting with the least significant.
  • ‘REAL4’ = Four bytes that holds a floating point number.

Starting with the Header, all entities start with the same six bytes in this order:

ERLen	dword	sizeof(HDR)	;actual length (bytes in use) 
EType	byte	ET_IB		;entity type code 
IType	byte	IB_HDR		;info block type 

If the entity type (Etype) is zero, then the info block type (Itype) value defines what type of non-drawn entity it is. Here is a list of the non-drawn entity types:

  • 0 = "Header"
  • 1 = Old and unused
  • 2 = "Views"
  • 3 = "Layers"
  • 4 = "Grids"
  • 5 = "Printer Settings"
  • 6 = "Line Styles"
  • 7 = "Fill Styles"
  • 8 = "Named Views"
  • 9 = "Color Map Data"
  • 16 = "Dimension Styles"
  • 17 = "Fonts"

So, to walk through a map file, you start at byte 129 and read in the first four bytes to find the length of the next entity. Add that length to the pointer that points to the first byte in the entity and you are now at the first byte of the next entity.

If that was all there was to it, then walking through the file format would be a breeze. Unfortunately this is not the case. We also have to deal with something called sublists. Sublists are lists of entities like lines and points etc. that are not part of the main map but instead belong to either a group, a multipoly or a symbol. So if you find an entity that has a sublist, the entity is immediately followed by its sublist.

Once you have found the first byte of what could be the next entity, you need to check the next five bytes for the tale-tell signal that starts a sublist: 5 0 0 0 0. If you find a sublist then you need to walk through it as well by adding five to your pointer and going from there.

Likewise, at the end of a sublist, you encounter the tale-tell signal: 5 0 0 0 1. Add five again to your pointer and continue.

In the example program, you will see how I manage the navigation of a map file. I also read in and display the entity type lines. You should be able to take this framework and add to it so that you have a fully functioning map viewer.


Read Previous Lesson


Download the Visual Basic program and code for "Binary.exe".