< OSM Map On Magellan < Format

OSM Map On Magellan/Format/layer

Layer

The layer files contain the map object data, as there are point, polylines and polygons. Each layer subdivides into several levels of cell. The first level contains only one big cell filling the whole layer. The next level and every second level following, the cell width and height is devided by half. In the levels inbetween the cells have the same widht and height like in the level before, but the cells are shifted half a cell width to the left and down.

Cells off different levels
Level 2Level 3Level 4

Coordinates in the layer file are negative in direction of west and north (The world is standing upside down)

There are two different versions of Header known, that both work. The rest of the file is identical. Both header are 128 bytes long. The rest of the layer file is reserved for geographical data.

Version 1

bytes type description
Bytes 0 - 3 char[] String = "MHGO"
Bytes 4 - 7 int Category (two possible values NORMAL_LAYER = 0, ARTIFICIAL_LAYER = 1)
Bytes 8 - 9 short FileIdentifier = 0xc000
Bytes 10 - 13 float Longitude Left
Bytes 14 - 17 float Longitude Right
Bytes 18 - 21 float Latitude Bottom
Bytes 22 - 25 float Latitude Top
Bytes 26 - 27 short Number of Levels (0 when layer is empty)
Bytes 28 - 31 int Number of Objects inside the layer
Bytes 32 - 39 double Scale Factor Longitude (Typically 9.0e-6)
Bytes 40 - 47 double Scale Factor Latitude (Typically 9.0e-6)
Bytes 48 - 51 float Origin Longitude (Typically 0.0)
Bytes 52 - 55 float Origin Latitude (Typically 0.0)
Bytes 56 - 59 int Left
Bytes 60 - 63 int Bottom
Bytes 64 - 67 int Right
Bytes 68 - 71 int Top
Byte 72 byte Layer Type (POINT = 0x0B, POLYLINE = 0x0D, AREA = 0x0C, LABELS = 0x0F, POI = 0x10)
Byte 73 byte 0x00
Bytes 74 - 77 int Size in bytes of largest cell
Bytes 78 - 81 int First Cell Id
Bytes 82 - 85 int Last Cell Id
Bytes 86 - 127 byte[] Filled with 0x00

Version 2

bytes type description
Bytes 0 - 3 char[] String = "MHGO"
Bytes 4 - 7 int Magic 0x80
Bytes 8 - 15 double Scale Factor Longitude (Typically 9.0e-6)
Bytes 16 - 23 double Scale Factor Latitude (Typically 9.0e-6)
Bytes 24 - 27 float Origin Longitude (Typically 0.0)
Bytes 28 - 31 float Origin Latitude (Typically 0.0)
Bytes 32 - 35 int Left
Bytes 36 - 39 int Bottom
Bytes 40 - 43 int Right
Bytes 44 - 47 int Top
Bytes 48 - 51 float Longitude Left
Bytes 52 - 55 float Longitude Right
Bytes 56 - 59 float Latitude Bottom
Bytes 60 - 63 float Latitude Top
Bytes 64 - 47 int Number of Objects inside the layer
Bytes 68 - 71 int Size in bytes of largest cell
Bytes 72 - 75 int First Cell Id
Bytes 76 - 79 int Last Cell Id
Bytes 80 - 81 short Number of Levels (0 when layer is empty)
Bytes 82 - 83 short FileIdentifier = 0xc000
Byte 84 byte Layer Type (POINT = 0x0B, POLYLINE = 0x0D, AREA = 0x0C, LABELS = 0x0F, POI = 0x10)
Byte 85 byte 0x00
Bytes 86 - 89 int Category (two possible values NORMAL_LAYER = 0, ARTIFICIAL_LAYER = 1)
Bytes 90 - 127 byte[] Filled with 0x00

Cell Data

The Graphic data starts at byte 512 of the file. It is organized in cells as described above. When a cell is empty/without elements it is not listed in the following section at all. Each Cell starts with a short containing the number of elements within the cell.

bytes type description
Bytes 0 - 1 short Number of Elements in the cell
Bytes 2 - 3 short 0x00 (Maybe the value above is an int and this belongs to it)
Bytes 4 - (n - 1) byte[] Polyline, Point or Polyarea data
Bytes n byte optional alignment byte

Each element within a cell has a common prefix of maximum 19 bytes describing its bounding box.

bytes type description
Bytes 0 - 1 short Length of element in bytes
Bytes 2 byte Bounding box parameter descriptor
Bytes 3 - nothing, byte, short or int X-Offset
nothing, byte, short or int Y-Offset
nothing, byte, short or int Width
nothing, byte, short or int Height
byte[] Graphic data

The parameter descriptor is set up like this:

Bounding Box Parameter Descriptor
Bit 7Bit 6Bit 5Bit 4Bit 3Bit 2Bit 1Bit 0
Height Data Type Width Data Type Y-Offset Data Type X-Offset Data Type

where

  • 3 = nothing ( value = 0)
  • 2 = byte
  • 1 = short
  • 0 = integer

(Note: for some reason the "length of element in bytes" is calculated by Length = 18 + Length of "Graphic data")

Polyline

All coordinates within a Polyline Graphic are relative to its bounding box described before. The map differentiates between following types of Polylines:

TypeCriteriaextra Size
7firstPoint.x == topRight.x,firstPoint.y == bottomLeft.y, lastPoint.x == bottomLeft.x, lastPoint.y == topRight.y0
6firstPoint.x == bottomLeft.x, firstPoint.y == topRight.y, lastPoint.x == topRight.x, lastPoint.y == bottomLeft.y0
5firstPoint == topRight, lastPoint == bottomLeft0
4irstPoint == bottomLeft, lastPoint == topRight0
3firstPoint == bottomLeft2
2firstPoint.x - bottomLeft.x <= 255, firstPoint.y - bottomLeft.y <= 2554
1firstPoint.x - bottomLeft.x <= 65535, firstPoint.y - bottomLeft.y <= 655356
0all the rest10

The size of the polyline stream is calculated by:

Size = (extra Size) + (Number of Points - 2) * 2 + 4

When a text is associated to the polyline the size increases by 2.

Lets assume the polyline in the following table is of polytype 1 with four points for the following table

bytes type description
Bytes 0 byte textOffset = 0xff when no text is associated with this polyline, otherwise text offset within row of aux table
Bytes 1 byte object type or layer this polyline belongs to
Bytes 2 - 3 short polyType << 13 + number of points
Bytes 4 - 5 short x offset of first point from bottom left corner of bounding box.
Bytes 6 - 7 short y offset of first point from bottom left corner of bounding box.
Bytes 8 byte x offset second point in relation to first
Bytes 9 byte y offset second point in relation to first
Bytes 10 byte x offset third point in relation to second
Bytes 11 byte y offset third point in relation to second
Bytes 12 byte x offset 4th point in relation to third This point would miss in case of polytype 4-7
Bytes 13 byte y offset 4th point in relation to third. This point would miss in case of polytype 4-7
Bytes 14 short (optional, only when textOffset != 0xff), line within aux table

Example

Here is an example for a layer file containing a single line with three points, it is generated out of this example osm file:

<?xml version="1.0" encoding="UTF-8"?>
<osm version="0.6" generator="CGImap 0.0.2">
 <node id="1112" visible="true" version="1" changeset="1" timestamp="2014-11-29T17:32:22Z" user="benno234" uid="1234" lat="49.34013" lon="7.60557"/>
 <node id="1113" visible="true" version="1" changeset="1" timestamp="2014-11-29T17:32:23Z" user="benno234" uid="1234" lat="49.34138" lon="7.60557"/>
 <node id="1114" visible="true" version="1" changeset="1" timestamp="2014-11-29T17:32:24Z" user="benno234" uid="1234" lat="49.34138" lon="7.60819">
	 <tag k="created_by" v="fantasy"/>
 </node>
 <way id="2011" visible="true" version="1" changeset="1" timestamp="2014-11-29T17:32:25Z" user="benno234" uid="1234">
  <nd ref="1112"/>
  <nd ref="1113"/>
  <nd ref="1114"/>
  <tag k="highway" v="motorway"/>
  <tag k="name" v="My Way"/>
  <tag k="postal_code" v="12345"/>
  <tag k="source" v="fantasy"/>
 </way>
</osm>

Here are the used parameters from the layer header:

  • bb left  : 777781
  • bb right  : 888885
  • bb top  : -5444447
  • bb bottom  : -5555551
  • scalelat  : 9.0E-6
  • scalelon  : 9.0E-6
  • ref lon  : 0.0
  • ref lat  : 0.0
  • ko left  : 7.000029
  • ko right  : 7.999965
  • ko top  : -49.000023
  • ko bottom  : -49.999958
  • firstCell  : 654
  • lastCell  : 654
  • nbr of Lev : 4
  • nbr of Obj : 1
  • fileIdent  : 0xc000
  • category  : 0
  • layerType  : 13
0x4D0x480x470x4F0x000x000x000x000x000xC00x3D0x000xE00x400xB70xFF0xFF0x400xF50xFF0x470xC20x060x000x440xC20x040x000x010x000x000x00
0x3F0xAB0xCC0x940xD60xDF0xE20x3E0x3F0xAB0xCC0x940xD60xDF0xE20x3E0x000x000x000x000x000x000x000x000x350xDE0x0B0x000xA10x3A0xAB0xFF
0x350x900x0D0x000xA10xEC0xAC0xFF0x0D0x000x1C0x000x000x000x8E0x020x000x000x8E0x020x000x000x000x000x000x000x000x000x000x000x000x00
0x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x00
0x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x00
0x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x00
0x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x00
0x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x00
0x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x00
0x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x00
0x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x00
0x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x00
0x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x00
0x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x00
0x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x00
0x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x00
0x010x000x000x000x200x000x950x220x050x080x010x230x010x8B0x000x000x060xE00x9F0x010x9F0x000x9F0xFF0x000x460x010x00

PolyArea

A polyarea within the map is the pendant to a multipolygon in the osm data. It can contain several outer area where the inner area are substracted from.

The bounding box is stored like at polyline. Here is how the graphic data is represented:

bytes type description
Bytes 0 byte textOffset = 0xff when no text is associated with this polyline, otherwise text offset within row of aux table
Bytes 1 byte object type or layer this polyarea belongs to
Bytes 2 - 3 short Number of Points of all Sub Areas
Bytes 4 - (Number of SubAreas * 2 - 1) short[] Info for Sub Area
byte[] Sub Area data
byte 0xff = No countour data present
byte 0x00 = Alignement
short (optional, only when textOffset != 0xff), line within aux table


It is a little bit tricky to build the info for the sub areas.

Index of Sub areaCalculation of info
0Sub outer Poly Area Type << 13 + number of Outer Sub Area + Number of Inner Sub Area
1Sub outer Poly Area Type << 13 + amount of points before (Sub Area 0) + 1
2Sub outer Poly Area Type << 13 + amount of points before (Sub Area 0, 1) + 2
...
nSub inner Poly Area Type << 13 + amount of points before ((Sub Area 0, 1, ...,(n - 1)) + n
n + 1Sub inner Poly Trea type << 13 + amount of points before ((Sub Area 0, 1, ..., n) + n + 1
...

Sub Area

Similar to the polyline there are several possible polyarea types, but only two of them are relevant:

TypeCriteriaextra Size
4firstPoint.x - bottomLeft.x <= 255, firstPoint.y - bottomLeft.y <= 2552
2firstPoint.x - bottomLeft.x <= 65535, firstPoint.y - bottomLeft.y <= 655354


Lets assume the Sub Poly Area in the following table is of polytype 2 with four points for the following table

bytes type description
Bytes 0 - 1 short x offset of first point from bottom left corner of bounding box.
Bytes 2 - 3 short y offset of first point from bottom left corner of bounding box.
Bytes 4 byte x offset second point in relation to first
Bytes 5 byte y offset second point in relation to first
Bytes 6 byte x offset third point in relation to second
Bytes 7 byte y offset third point in relation to second
Bytes 8 byte x offset 4th point in relation to third
Bytes 9 byte y offset 4th point in relation to third

The Areas will automatically be closed. It is not needed to list the first point at the end of the list of points again, to close it.

Example

Here is a simple example with a multipolygon having one inner and one outer area:

<?xml version="1.0" encoding="UTF-8"?>
<osm version="0.6" generator="CGImap 0.0.2">
 <node id="1112" visible="true" version="1" changeset="1" timestamp="2014-11-29T17:32:22Z" user="benno234" uid="1234" lat="49.34299" lon="7.60286"/>
 <node id="1113" visible="true" version="1" changeset="1" timestamp="2014-11-29T17:32:22Z" user="benno234" uid="1234" lat="49.34299" lon="7.61354"/>
 <node id="1114" visible="true" version="1" changeset="1" timestamp="2014-11-29T17:32:22Z" user="benno234" uid="1234" lat="49.33621" lon="7.61354"/>
 <node id="1115" visible="true" version="1" changeset="1" timestamp="2014-11-29T17:32:22Z" user="benno234" uid="1234" lat="49.33621" lon="7.60286"/>
 <node id="1122" visible="true" version="1" changeset="1" timestamp="2014-11-29T17:32:22Z" user="benno234" uid="1234" lat="49.34013" lon="7.60557"/>
 <node id="1123" visible="true" version="1" changeset="1" timestamp="2014-11-29T17:32:22Z" user="benno234" uid="1234" lat="49.34013" lon="7.60957"/>
 <node id="1124" visible="true" version="1" changeset="1" timestamp="2014-11-29T17:32:22Z" user="benno234" uid="1234" lat="49.33737" lon="7.60957"/>
 <node id="1125" visible="true" version="1" changeset="1" timestamp="2014-11-29T17:32:22Z" user="benno234" uid="1234" lat="49.33737" lon="7.60557"/>
 <way id="2011" visible="true" version="1" changeset="1" timestamp="2014-11-29T17:32:25Z" user="benno234" uid="1234">
  <nd ref="1112"/>
  <nd ref="1113"/>
  <nd ref="1114"/>
  <nd ref="1115"/>
  <nd ref="1112"/>
 </way>
 <way id="2021" visible="true" version="1" changeset="1" timestamp="2014-11-29T17:32:25Z" user="benno234" uid="1234">
  <nd ref="1122"/>
  <nd ref="1123"/>
  <nd ref="1124"/>
  <nd ref="1125"/>
  <nd ref="1122"/>
 </way>
 <relation id="3031" visible="true" version="1" changeset="1" timestamp="2014-11-29T17:32:25Z" user="benno234" uid="1234">
  <member type="way" ref="2011" role="outer"/>
  <member type="way" ref="2021" role="inner"/>
  <tag k="natural" v="scrub"/>
  <tag k="type" v="multipolygon"/>
 </relation> 
</osm>

Here is the layer definition:

  • bb left  : 777781
  • bb right  : 888885
  • bb top  : -5444447
  • bb bottom  : -5555551
  • scalelat  : 9.0E-6
  • scalelon  : 9.0E-6
  • ref lon  : 0.0
  • ref lat  : 0.0
  • ko left  : 7.000029
  • ko right  : 7.999965
  • ko top  : -49.000023
  • ko bottom  : -49.999958
  • firstCell  : 654
  • lastCell  : 654
  • nbr of Lev : 4
  • nbr of Obj : 1
  • fileIdent  : 0xc000
  • category  : 0
  • layerType  : 12

And here is the dump of the whole layer file:

0x4D0x480x470x4F0x000x000x000x000x000xC00x3D0x000xE00x400xB70xFF0xFF0x400xF50xFF0x470xC20x060x000x440xC20x040x000x010x000x000x00
0x3F0xAB0xCC0x940xD60xDF0xE20x3E0x3F0xAB0xCC0x940xD60xDF0xE20x3E0x000x000x000x000x000x000x000x000x350xDE0x0B0x000xA10x3A0xAB0xFF
0x350x900x0D0x000xA10xEC0xAC0xFF0x0C0x000x7A0x000x000x000x8E0x020x000x000x8E0x020x000x000x000x000x000x000x000x000x000x000x000x00
0x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x00
0x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x00
0x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x00
0x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x00
0x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x00
0x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x00
0x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x00
0x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x00
0x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x00
0x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x00
0x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x00
0x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x00
0x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x00
0x010x000x000x000x7E0x000x590xF50x030x560xA30x040xF20x020xFF0x000x300x000x020x800x220x400x000x000x000x7E0x000x7E0x000x7D0x000x7E
0x000x7D0x000x7D0x770x010x760x000x770x000x770x000x770x000x760x000x770x000x770x000x760x000x770xFF0x000x830x000x830x000x820x000x83
0x000x820x000x820x890x010x8A0x000x890x000x890x000x8A0x000x890x000x890x000x890x000x8A0x000x890xFF0x2D0x010x3D0x010x6F0x010x700x00
0x6F0x000x6F0xFF0x000x670x000x670x000x650x910x010x910x000x900x000x910xFF0x000x9B0x000x990x000x990xFF0x00
This article is issued from Openstreetmap. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.