Notes on the MapInfo® Native table format(MAP格式說明)

Notes on the MapInfo® Native table format

by AnssiJoutsiniemi and Robert Edwards

March 2000


DISCLAIMER

The information provided in this document is not guaranteed to be accurate.The authors assume no responsibility for any trouble you may experience as aresult of using this information. Use at your own risk.

In the spirit of the Open SourceInitiative, this document may be freely distributed. You may makechanges to the original and redistribute, but all copies must retain theorignal title, authors' names, and disclaimer.

If you do make additions or corrections, the author would appreciatereceiving an E-mail copy of your updated document or a URL to its location.

MapInfo is a registered trademark of MapInfo Corporation.

DOCUMENTATION CONVENTIONS

In this brief introduction all offsets are relative to the beginning ofeach block. Values preceded by "&H" are hexadecimal.
Naming convention is invented by the author, since no documentation on thenative MapInfo® file format is currently available.

In this documentation notations are marked as follows:
[?] talented guess
[??] not so good guess
[!] value that seems to be a constant


General Notes on MapInfo® Tables

MapInfo® Native Table consists of files with followingsuffixes:

.TAB:

table structure in ASCII format (required)

.DAT:

table date storage in binary format (required)

.MAP:

storage of map objects in binary format (optional)

.ID:

links to the .map file (optional, but required if .map file exists)

NOT described in this document:

.IND:

data of indexed fields in binary format (optional)

 

The structure of MapInfo® .dat file is virtually identical todBase IV data format. The MapInfo® .id file data is stored in 32 bitIntegers, each value points to an object in the Object Definition Blocks (seebelow) because the record order in .id file is same as in .dat file (i.e.RowID) including deleted record which have a value of &H0.

MapInfo® .map file is organized in blocks of &H200 bytes.(Beginning with Version 500 the Header Block is extended by &H200 bytes.)Each block is identified by first byte. The six block types are:

HEADER BLOCK(BlockID 0)

Generalinformation of table coordinate system and internal structure

INDEX BLOCK (BlockID 1)

Index tolocate map objects on Object Definition Blocks

OBJECT DEFINITION BLOCK(BlockID 2)

Generalinformation on map objects

COORDINATE DEFINITION BLOCK(BlockID 3)

Coordinatestorage block

DELETED BLOCK (BlockID 4)

Re-usableblock

RESOURCE BLOCK (BlockID 5)

List of pen,brush, font and symbol resources of table

The byte order is little-endian (from least significant byte to mostsignificant byte).

Map objects can be accessed in either of two ways. One is through theoffset in .id file which is a means of accessing the object informationassociated with an attribute. The other is what I have used in my Recover.mbxwhich loops through the Index Block to gain information on all ObjectDefinition Blocks. This is useful for a more sophisticated use when objects areselected according to their MBR (Minimum Bounding Rectangle).

Robert Edwards pointed out that the coordinates and distances in an objectdefinition are defined using either 16 bit integers (MI:SmallInt) or 32 bitintegers (MI:Integers). Inspection of the object code numbering schemeindicates that there is the possiblity of another set of object definition,perhaps based on 64 bit coordinates, but there is no evidence that such afeature has been implemented.

According to Edwards, short coordinate precision is used if all thecoordinates and distances for an object can be expressed as differences lessthan +-2^15. Short coordinate values are added to base coordinate value (basecoordinates are located either in the base of the Object Definition Block or inthe object itself) and this sum is converted to floating point coordinatesusing the X/Y offsets and X/Y scales in Header Block.

Data stored in Coordinate Definition Blocks contains the actual coordinatedata and header information of each section of holy or multisectioned polygon.So the data of one map object consists of numbers of Section headers, which isfollowed by coordinate values of all object sections.

Note also: Object Definition Block (Block type code 2) is called ObjectDefinition Block in Open Source Software. Maybe one day all this stuff is puttogether, but for know it is far more important that you play with it make itright.

LIST OF KNOWN BLOCKS AND BLOCK OFFSETS:

HEADER BLOCK (BlockType 0)

 

offset      length      count       description

--------------------------------------------------------------

 

&H0         1           1           HeaderBlock identifier (Value: &H0) [!]

 

&H1         1           1           HeaderBlock header

:

:                                                Unknown(For length of header data offset see &H163)

:

&H33/&H2D/&H27/&H1F

:

:                                                (Value&H0 [!])

:

&HFF

 

&H100       4           1           MagicNumber (&H28757B2 i.e.42424242) [?]

&H104       2           1           MapFile Version (not equal to table version)

&H106       2           1           Unknownvalue: &H200 [!], BlockSize[??]

&H108       8           1           CoordSysToDistUnits:Miles/LatDegree for Lat/Long maps

                                                 1.0  for all others [!]

&H110       4           4           Coordinatesof Minimum Bounding Rectangle (MBR)

&H120       4           4           Coordinatesof Default View of table

&H130       4           1           Offsetof Object Definition Index (see also &H15F)

&H134       4           1           Offsetof the beginning of Deleted Block sequence

&H138       4           1           Offsetof Resources Block

&H13C       4           1           Numberof Symbol elements

&H140       4           1           Numberof Line elements

&H144       4           1           Numberof Region elements

&H148       4           1           Numberof Text elements

&H14C       4           1           MaxCoordBufSize

&H14E       14          1           14Unknown bytes (Probably reserved and set to zero)

&H15E       1           1           MapFile Distance Units

                                                 Fordetailed information on distance unit values see:

                                                 MapInfoProgramDirectory/Ut/Reproject/MapInfoUnits.db

 

&H15F       1           1           Typeof Element Indexing data (see also &H130)

                                                 0= NoData

                                                 1= Object Definition Block (NoIndex block)

                                                 2= Index Block

&H160       1           1           CoordPrecision          Value:6 for Lat/Long maps

                                                             Value:8for Cartesian maps

                                                             Value:1for Projected maps

&H161       1           1           CoordOriginCode         Value:2 for Lat/Long maps

                                                             Value:1for Cartesian and Projected maps

&H162       1           1           ReflectAxisCode         Value:1 for Lat/Long maps

                                                             Value:0for Cartesian and Projected maps

&H163       1           1           ObjLenArraySize         (at start of this block)

&H164       1           1           Numberof pen resources

&H165       1           1           Numberof brush resources

&H166       1           1           Numberof symbol resources

&H167       1           1           Numberof text resources

&H168       2           1           Numberof Resource Blocks

&H169       3           1           Unknown(probablyreserved and set to zero)

&H16D       1           1           Projectiontype

                                                 Fordetailed information on internal projection values see:

                                                 MapInfoProgramDirectory$>/Ut/Reproject/MapInfoProj.db

 

&H16E       1           1           Datum(See also &H1C0, &H1C8, &H1D0)

                                                 (Notalways equal to value in MapInfow.prj)

 

                                                 Fordetailed information on internal datum values see:

                                                 <MapInfoProgramDirectory$>/Ut/Reproject/MapinfoDatums.db

 

&H16F       1           1           Unitsof coordinate system

                                                 (Valuesequal to &H15E)

&H170       8           4           XScale,YScale, XOffset, YOffset

&H190       8           1           Projectionparameter 1.

&H198       8           1           Projectionparameter 2.

&H1A0       8           1           Projectionparameter 3.

&H1A8       8           1           Projectionparameter 4.

&H1B0       8           1           Projectionparameter 5.

&H1B8       8           1           Projectionparameter 6.

&H1C0       8           1           Datumshift X

&H1C8       8           1           Datumshift Y

&H1D0       8           1           Datumshift Z

&H1D8       8           5           Datumparameters

.

.

.

&H1FF                               

 

 

 

Version 500 extension (see &H104)

--------------------------------------------------------------

 

&H200       1           1           Value&H1 if in use

&H201       1           1           Affineunit name

&H208       8           6           Affineparameters A, B, C, D, E, F

                                                 (seeAppendix H)

 

&H238

:                                    ProbablyNot In Use (and not padded w/ zeros)

&H3FF

INDEX BLOCK (BlockType 1)

Index Block header (length: &H4)

---------------------------------------------------------------

&H0         1           1           IndexBlock identifier (Value: &H1) [!]

&H1         1           1           Link

&H2         1           2           Numberof Index data blocks

 

Index data (length: &H14)

---------------------------------------------------------------

&H0         4           4           ObjectDefinition Block MBR (XMin, YMin, XMax, YMax)

&H10        4           1           ObjectDefinition Block offset

Object Definition Block (BlockType 2)

    ObjectDefinition Block header (length: &H14)

---------------------------------------------------------------

&H0     1       1          ObjectDefinition Block identifier (Value: &H2) [!]

&H1     1       1          Linkto next Object Definition Block

&H2     2       1          BytesTo Follow (length of ODB data)

&H4     4       2          Basecoordinate values for short object types

 

Object Definition data items, which are identified by acode in the first byte, are

arrayed in an Object Definition Block after the header.The items in an Object

Definition Block reference coordinate and sectiondefinitions in 

an associated Coordinate Definition Block (or Blocks).For details about

object types see Edwards' notes.

 

---------------------------------------------------------------

ShortPoint [ID 1] (length: &HA):        [?]

&H0     1       1      Identifier (Value: &H1) [!]

&H1     4       1      RowID - Validity: (+0 = Valid; +&H40000000 = Deleted)      

&H5     2       2      Coordinate value

&H9     1       1      Symbol type number from Resource Block

 

LongPoint [ID 2] (length: &HE):

&H0     1       1      Identifier (Value: &H2) [!]

&H1     4       1      RowID - Validity: (+0 = Valid; +&H40000000 = Deleted)      

&H5     4       2      Coordinate value

&HD     1       1      Symbol type number from Resource Block

 

ShortLine [ID 4] (length: &HE):

&H0     1       1      Identifier (Value: &H4) [!]

&H1     4       1      RowID - Validity: (+0 = Valid; +&H40000000 = Deleted)      

&H5     4       2      Coordinate value

&HD     1       1      Line type number from Resource Block

 

LongLine [ID 5] (length: &H16):

&H0     1       1      Identifier (Value: &H5) [!]

&H1     4       1      RowID - Validity: (+0 = Valid; +&H40000000 = Deleted)      

&H5     4       4      MBR

&H15        1           1       Line type number from Resource Block

 

ShortPolyline [ID 7] (length: &H1A):

&H0     1       1      Identifier (Value: &H7) [!]

&H1     4       1      RowID - Validity: (+0 = Valid; +&H40000000 = Deleted)      

&H5     4       1      Offset of coordinate data in Coordinate Definition Block

&H9     4       1      Bytes to read for coordinates from Coordinate Definition Block [?]

&HD     2       2      Label location coordinates

&H11        2           4           MBR    

&H19    1       1      Line type number from Resource Block

 

LongPolyline [ID 8] (length: &H26):

&H0     1       1      Identifier (Value: &H8) [!]

&H1     4       1      RowID - Validity: (+0 = Valid; +&H40000000 = Deleted)      

&H5     4       1      Offset of coordinate data in Coordinate Definition Block

&H9     4       1      Bytes to read for coordinates from Coordinate Definition Block [?]

&HD         4       2      Label location coordinates

&H15        4           4           MBR    

&H25    1       1      Line type number from Resource Block

 

ShortArc [ID 10] (length: &H16):

&H0     1       1      Identifier (Value: &HA) [!]

&H1     4       1      RowID - Validity: (+0 = Valid; +&H40000000 = Deleted)      

&H5     4       2      MBR of defining ellipse

&HD         4           2           MBRof the arc

&H15    1       1      Line type number from Resource Block

 

LongArc [ID 11] (length: &H26):

&H0     1       1      Identifier (Value: &HB) [!]

&H1     4       1      RowID - Validity: (+0 = Valid; +&H40000000 = Deleted)      

&H5     4       4      MBR of defining ellipse

&15         4           4           MBRof the arc

&H25    1       1      Line type number from Resource Block

 

ShortRegion [ID 13] (length: &H25):

&H0     1       1      Identifier (Value: &HD) [!]

&H1     4       1      RowID - Validity: (+0 = Valid; +&H40000000 = Deleted)      

&H5     4       1      Offset of coordinate data in Coordinate Definition Block

&H9     4       1      Bytes to read for coordinatesfrom Coordinate Definition Block [??]

&HD     2       1      Section count

&HF     4       2      Label X,Y

&H13    4       4      MBR

&H23    1       1      Line type number from Resource Block

&H24    1       1      Brush type number from Resource Block

 

LongRegion [ID 14] (length: &H29):

&H0     1       1      Identifier (Value: &HE) [!]

&H1     4       1      RowID - Validity: (+0 = Valid; +&H40000000 = Deleted)      

&H5     4       1      Offset of coordinate data in Coordinate Definition Block

&H9     4       1      Bytes to read for coordinates from Coordinate Definition Block [??]

&HD     2       1      Section count

&HF     4       2      Label X,Y

&H17        4       4      MBR

&H27    1       1      Line type number from Resource Block

&H28    1       1      Brush type number from Resource Block

 

ShortText [ID 16] (length: &H27)

&H0     1       1      Identifier (Value: &H10) [!]

&H1     4       1      RowID - Validity: (+0 = Valid; +&H40000000 = Deleted)       

&H5     4       1      Offset of text body in Coordinate Definition Block

&H9     2       1      Number of characters in text body

&HB     2       1      Justification spacing arrowtype:

                                flag 2^1 -centered text

                                flag 2^2 - rightaligned text

                                flag 2^3 - linespacing 1.5

                                flag 2^4 - linespacing 2.0

                                flag 2^5 -label line: simple

                                flag 2^6 - label line:arrow

&HD     2       1      Text rotation angle (0.1 degrees)

&HF     1       1      FontStyle #1:

                                flag 2^0 - boldtext

                                flag 2^1 -italic text

                                flag 2^2 -underlined text

                                flag 2^3 -overlined text

                                flag 2^4 -unknown

                                flag 2^5 -shadowed text

&H10    1       1      FontStyle #2:

                                flag 2^0 - boxbackground

                                flag 2^1 - halobackground

                                flag 2^2 - AllCaps

                                flag 2^3 -Expanded

&H11    3       1      Foreground color

&H14    3       1      Background color

&H17    2       2      Arrow endpoint coordinates

&H1B    2       1          Height

&H1D        1           1           Fontname index

&H1E    2       4      MBR

&H26    1       1      Pen type from Resource Block

 

LongText [ID 17] (length: &H32)

&H0     1       1      Identifier (Value: &H11) [!]

&H1     4       1      RowID - Validity: (+0 = Valid; +&H40000000 = Deleted)      

&H5     4       1      Offset of text body in Coordinate Definition Block

&H9     2       1      Number of characters in textbody

&HC     2       1      Justification spacing arrowtype:

                                flag 2^1 -centered text

                                flag 2^2 -right aligned text

                                flag 2^3 - linespacing 1.5

                                flag 2^4 - linespacing 2.0

                                flag 2^5 -label line: simple

                                flag 2^6 -label line: arrow

&HD     2       1      Text rotation angle (0.1 degrees)

&HF     1       1      FontStyle #1:

                                flag 2^0 - boldtext

                                flag 2^1 -italic text

                                flag 2^2 -underlined text

                                flag 2^3 -overlined text

                                flag 2^4 -unknown

                                flag 2^5 -shadowed text

&H10    1       1      FontStyle #2:

                                flag 2^0 - boxbackground

                                flag 2^1 - halo background

                                flag 2^2 - AllCaps

                                flag 2^3 -Expanded

&H11    3       1      Foreground color

&H14    3       1      Background color

&H17    4       2      Arrow endpoint coordinates

&H1F    1       4          Height

&H20        1           1           Fontname index

&H30    4       4      MBR

&H31    1       1      Pen type from Resource Block

 

ShortRectangle [ID 19] (length: &HF):

&H0     1       1      Identifier (Value: &H10) [!]

&H1     4       1      RowID - Validity: (+0 = Valid;+&H40000000 = Deleted)      

&H5     2       4      MBR

&HD         1       1      Line type number in Resource Block

&HE         1       1      Brush type number in Resource Block

 

LongRectangle [ID 20] (length: &H17):

&H0     1       1      Identifier (Value: &H17) [!]

&H1     4       1      RowID - Validity: (+0 = Valid; +&H40000000 = Deleted)      

&H5     4       4      MBR

&H15    1       1      Line type number from Resource Block

&H16    1       1      Brush type number from Resource Block

 

ShortRoundRectangle [ID 22] (length: &H13):

&H0     1       1      Identifier (Value: &H16) [!]

&H1     4       1      RowID - Validity: (+0 = Valid; +&H40000000 = Deleted)      

&H5     2       1      XRadius

&H7     2       1      YRadius

&H9     2       4      MBR

&H11    1       1      Line type number from Resource Block

&H12    1       1      Brush type number from Resource Block

 

LongRoundRectangle [ID 23] (length: &H1F):

&H0     1       1      Identifier (Value: &H16) [!]

&H1     4       1      RowID - Validity: (+0 = Valid; +&H40000000 = Deleted)      

&H5     4       1      XRadius

&H9     4       1      YRadius

&HD     4       4      MBR

&H1D    1       1      Line type number from Resource Block

&H1E    1       1      Brush type number from Resource Block

 

ShortEllipse [ID 25] (length: &HF):

&H0     1       1      Identifier (Value: &H1A) [!]

&H1     4       1      RowID - Validity: (+0 = Valid; +&H40000000 = Deleted)      

&H5     2       4      MBR

&HD         1       1      Line type number from Resource Block

&HE         1       1      Brush type number from Resource Block

 

LongEllipse [ID 26] (length: &H17):

&H0     1       1      Identifier (Value: &H1A) [!]

&H1     4       1      RowID - Validity: (+0 = Valid; +&H40000000 = Deleted)      

&H5     4       4      MBR

&H15    1       1      Line type number from Resource Block

&H16    1       1      Brush type number from Resource Block

Coordinate Definition Block (BlockType 3)

Coordinate Definition Block header (length: &H8)

---------------------------------------------------------------

&H0         2           1           CoordinateDefinition Block identifier (Value: &H3) [!]

&H2         2           1           BytesTo Follow

&H4         4           1           Offsetto Coordinates

 

Short Poly Section header (length: &H10)

---------------------------------------------------------------

&H0         2           1           Numberof coordinates

&H2         2           1           Numberof holes

&H4         2           4           SectionMBR coordinates

&H4         4           1           Offsetto coordinates

 

Long Poly Section header (length: &H18)

---------------------------------------------------------------

&H0         2           1           Numberof coordinates

&H2         2           1           Numberof holes

&H4         4           4           SectionMBR coordinates

&H4         4           1           Offsetto coordinates

 

DELETED BLOCK (BlockType 4) [?]

Deleted Block header (length: &H8)

---------------------------------------------------------------

&H0         1           1           DeletedBlock identifier (Value: &H4) [!]

&H1         1           1           Unknown

&H2         2           1           BytesTo Follow

&H4         4           1           Offsetof next Deleted block

RESOURCE BLOCK (BlockType 5)

Resource Block header (length: &H8)

---------------------------------------------------------------

&H0         1           1           ResourceBlock identifier (Value: &H5) [!]

&H1         1           1           Unknown

&H2         2           1           BytesTo Follow

&H4         4           1           Offsetof next Deleted block

 

Resource types identified by the first byte:

---------------------------------------------------------------

 

ID 1 Pen resource (length:&HB)

&H0         1           1           Resourceidentifier (Value: &H1) [!]

&H1         4           1           Numberof elements using this resource

&H5         1           1           Lineweight (pixels)

&H6         1           1           Linestyle

&H7         1           1           Lineweight (points)

&H8         3           1           Linecolor

 

ID 2 Brush resource (length:&HD)

&H0         1           1           Resourceidentifier (Value: &H2) [!]

&H1         4           1           Numberof elements using this resource

&H5         1           1           Brushstyle

&H6         1           1           Unknown

&H7         3           1           Foregroundcolor

&HA         3           1           Backgroundcolor

 

ID 3 Font resource (length:&H25)

&H0         1           1           Resourceidentifier (Value: &H3) [!]

&H1         4           1           Numberof elements using this resource

&H5         32          1           Nameof a font

 

ID 4 Symbol resource (length:&HD)

&H0         1           1           Resourceidentifier (Value: &H4) [!]

&H1         4           1           Numberof elements using this resource

&H5         1           1           Unknown

&H6         1           1           Unknown

&H7         1           1           Unknown

&H8         1           1           Unknown

&H9         4           1           Unknown


RELATED LINKS

MapInfo TAB file "open source" documentation by Robert Edwards
[http://members.aol.com/MapToolsCompany/tabdef.txt]

Open Source C++ library to read and write MapInfo by Daniel Morissette
[http://pages.infinit.net/danmo/e00/index-mitab.html]

Recover.mbx by author
[http://www.directionsmag.com/tools/default.asp?a=file&id=163]

(end)

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章