The BSB file format
A nautical chart set in BSB format consists of several files: main .BSB file and one or more .KAP files. A main BSB file contains chart set meta-data information (chart description, function, enumeration of .KAP files. Note that NOAA BSB charts are meant to be exact equivalent of paper charts, so they contain the same number of sub-charts (paper pages). The .BSB file is unusual in that it contains both ASCII text and binary data concatenated together and structured as follows:
- Text header in DOS text format (CR-LF line-endings) terminated by <Control-Z><NUL>
- Binary section consisting of:
- One or more rows of run-length compressed raster data
- An index table consisting of 32-bit integers storing file offsets to each image row
Text Header
Although described as proprietary by NOAA, much of the information in the ASCII text header is self explanatory. Each line begins with a 3 character token followed by a slash "/". The remainder of the line depends upon the token, but in general consists of a list of comma separated values. If the list of values is too long for 80 columns, the values for the token are continued on the next line by prefixing the new line with 4 spaces. Comments are indicated with a leading "!".
! An example BSB text header
VER/3.0
BSB/NA=Australia 3000000
NU=,RA=625,480,DU=50
KNP/SC=3000000,GD=,PR=LAMBERT CONFORMAL CONIC,PP=145.0
PI=0.0,SP=Unknown,0,SK=0.0
UN=METRES,SD=,DX=6000.0,DY=6000.0
OST/1
IFM/3
RGB/1,199,231,252
RGB/2,174,234,84
RGB/3,255,254,206
RGB/4,226,65,6
DTM/0.0,0.0
The text header is terminated with a <Control-Z><NUL> sequence (ASCII characters 26 and 0).
Each line starts with a tag terminated by a '/'. The tags are usually 3 letters. The lines are terminated with the NL character. However, logical lines can continue when next line starts with spaces.
Tags:
- VER - Version number of BSB format e.g. 1, 2.0, 3.0, 3.07, 4.0
- BSB (or NOS for older GEO/NOS or GEO/NO1 files)
- RA=width,height - width and height of raster image data in pixels
- NA=Name given to the BSB chart (can represent more than one .KAP)
- NU=Number of chart (especially when more than one chart is grouped or tiled together)
- DU=Drawing Units in pixels/inch (same as DPI resolution) e.g. 50, 150, 175, 254, 300
- OST - Offset STrip image lines (number of image rows per entry in the index table) e.g. 1
- IFM - Depth of the colormap (bits per pixel). BSB supports 1 through 7 (2 through 127 max colors).
- RGB - Color definitions for the raster colormap of the form index,red,green,blue (index starts at 0, index 0 is not used in BSB). Note, there are more than one coloring schemes for different lighting conditions: DAY, DSK (dusk), NGT (night), GRY (gray), PRC (?), PRG (?).
- KNP
- SC=Scale e.g. 25000
- GD=Geodetic Datum e.g. NAD83, WGS84
- PR=Projection e.g. LAMBERT CONFORMAL CONIC, MERCATOR
- PP=Projection Parameter (value depends upon Projection) e.g. 135.0
- PI=? e.g. 0.0, 0.033333, 0.083333, 2.0
- SP=?
- SK=Skew angle? e.g. 0.0
- TA=? e.g. 90
- UN=Units (for DX, DY and others) e.g. METRES, FATHOMS
- SD=Sounding Datum e.g. MEAN LOWER LOW WATER, HHWLT
- DX=distance (approx.) covered by one pixel in X direction
- DY=distance (approx.) covered by one pixel in Y direction
- KNQ
- P1=...,P2=...
- P3=...,P4=...
- P5=...,P6=...
- CED - ? (appears to be optional for many applications)
- REF - Registration reference points (at least 3 points). The form is index, x raster coord, y raster coord, latitude, longitude
- PLY - Chart area (border) definition. List of points in clockwise order. Form is index, lattitude, longitude.
- WPX,WPY World-to-Pixel X/Y geotransformation to convert World coordinates (lat/lon) to accordingly X or Y of the raster. See explanation of geotransform below.
- PWX,PWY Pixel-to-World X/Y geotransformation to convert chart pixel coordinates coordinates (X/Y) to accordingly longitude or latitude of the raster. See explanation of geotransform below.
- ERR Exact meaning unknown - always thesame number of entries as REF points and always with 4 numbers. Possibly an error data for geotransformation of REF points.
- DTM - ? (appears to be optional for many applications)
Geotransformation
The WPX,WPY,PWX,PWY tags define coeffitients of a polynomial used to convert x,y of chart to latitude/longitude and vice versa. The tags specify order of the polynomial (first number) and then list corresponding coefitients. The polynomial has a general form of :
coeff[0] + coeff[1]*lon + coeff[2]*lat +
coeff[3]*lon*lon +
coeff[4]*lon*lat +
coeff[5]*lat*lat +
coeff[6]*lon*lon*lon +
coeff[7]*lon*lon*lat +
coeff[8]*lon*lat*lat +
coeff[9]*lat*lat*lat +
coeff[10]*lat*lat*lat*lat +
coeff[11]*lat*lat*lat*lat*lat
where:
- coeff is the list of coeffitiens as read from appropriate tag (not specified coordinates are zero)
- lon/lat are input coordinates (can be really lon/lat or x/y of raster)
- returns transformed coordinate according to supplied coeffs
Note: the same polynomial, just with different coeffitients (as read from tags) is used for all transformations. See bsb_LLtoXY/bsb_XYtoLL functions for use example.
Binary Section
The first byte after the <Control-Z><NUL> sequence is a single byte storing the depth of the image, duplicating the information from the IFM token.
Next are one or more rows of run-length encoded raster data terminated by <NUL> characters. Each row, when decompressed, represents one horizontal line of the image.
Rows start with one or more bytes representing the row number. The storage of the row number finishes when the byte is less than 128. Row numbering starts at 1 rather than 0.
The next byte will indicate the color of a pixel using a colormap index. The nature of the bitstream packing limits the color depth to 7 bits. Therefore bytes of value greater than 127 as used to indicate that the next byte stores the 'run' length in addition to storing the colormap index.
Authors/Contributors
The libbsb library and this web page was written by Stuart Cunningham with GIS related advice from Anuradha Suraparaju. Additional improvements made by Michal Krombholz. The big thanks go to Tom Gray for researching polynomial form of geotransfomration. Feedback is welcome.
Copyright (©) 2000-2007 Stuart Cunningham.