Content of the .kap header and bsb file
zstadler edited this page Jan 16, 2012
·
24 revisions
##Comments to a header that is close to what will actually be used.
!This chart originates from !http://www.nauticalcharts.noaa.gov/mcd/OnLineViewer.html !DO NOT USE FOR NAVIGATION !"Use official, full scale nautical charts for real-world navigation. !These are available from authorized nautical chart sales agents. !Screen captures of the charts available here do NOT fulfill chart !carriage requirements for regulated commercial vessels under !Titles 33 and 46 of the Code of Federal Regulations." !This chart is released by the OpenCPN.info - NGA chart project. VER/2.0 BSB/NA= [1] NU=[2],RA=[3],[4],DU=72 KNP/SC=[5],GD=[6],PR=[7] PP=[8],PI=UNKNOWN,SP=UNKNOWN,SK=[9],TA=[10] UN=[11],SD=[12],DX=000,DY=000[13] CED/SE=[14],RE=[15],ED=[16] OST/1 REF/1,[17] REF/2, REF/3, REF/4, PLY/1,[18] PLY/2, PLY/3, PLY/4, DTM/0.00,0.00 [19] CPH/0.0 [20]
- Name of chart from the chart. Warning: do not use commas ",".
- Chart number. Plan A on 23456 should be named 23456_A
- Size of picture Pixel x coordinate
- Size of picture Pixel y coordinate
- Scale of the chart from the chart.
- Geodetic datum, for example WGS84, from the chart. I not defined on the chart write "UNKNOWN" No guesswork, it is either stated, or said to be a local datum that cannot be related to WGS84. Charts released earlier than 1990 (?) and conforming to World Geodetic System should be WGS72, unless stated otherwise. The difference between WGS 84 and WGS 72 is minor.
- Projection, almost always MERCATOR, a few charts are TRANSVERSE MERCATOR. We should not bother with other projections, GNOMONIC small scale great circle charts etc. If we come across large scale plans with GNOMONIC projection this should be used, say 1:50,000 or larger. High latitude "Lambert Conformal Conic Projection" should be skipped, for now. OpenCPN only handles Mercator and Transversal Mercator. I don't think that we will see any Polyconic charts.
- For Mercator charts this is the latitude where the scale is valid. If available on the chart, use that value. If it is not available on the chart use the average value of the latitude of the upper and lower edge, to the nearest 1/10 of a degree. For Transverse Mercator charts use the average longitude of the eastern and western edge. Treat a possible large scale gnomonic as a Mercator chart.
- SK is the skew angle of charts that are not "North Up". For North Up the value is 0.0
- TA is he text angle, more or less always 90.0
- Unit for soundings from the chart, mostly METERS
- Datum for soundings from the chart, for ex MLWS, LAT
- x and y resolution, meters per pixel. Not necessary for us to compute. OpenCPN handles this.
- Chart edition date copied from the chart,inf in SW corner, except, there must be no commas.
- Our release edition.
- Our release date.
- Georeferencing, standard case - simple 4 corner chart, use the 4 corners, starting in the SW corner proceeding clockwise. Format: x pix,y pix, lat, long. Lat & long i decimal degrees, to 8 decimals, where N lat and E long are positive. One reason to use all 4 corners is to catch skewed and warped charts, and calculate SK (8a)
- Standard case, just copy the lat & long from the REFs.
- Corrections in seconds of arc to bring the chart to WGS84. This is generally given on the chart(if they exist), in a format where the corrections are in minutes of arc for plotting a WGS84 position on the chart. This correction must be transformed to seconds of arc and the signs reversed (we are doing the reverse to the case stated on the charts). These values are sometimes difficult to find on the chart.
- If a chart spans the 180th meridian = > CPH/180.0, else => CPH/0.0. So CPH/ is 0.0 for most charts. Note that OpenCPN handles transiting the 180:th meridian while a few other plotters don't.
IFM is not used as tif2bsb and imgkap calculates this value and ads it to the header on the final kap, together with other values such as RGB.
###This is one of the simpler bsb/kap file combinations, one kap and one bsb file. Maybe not the greatest example since it uses NAD27 instead of WGS84.
Some programs are a bit picky about the content of the bsb and kap files.
Try to document the different tags.
Content of 3001.bsb:
!Copyright 1996, NDI. All Rights Reserved
CHT/NA=VANCOUVER ISLAND JUAN DE FUCA STRAIT TO ,NU=3001 CHF (12,112₪)
(12,112₪)/GENERAL
CED/SE=3001, RE= 300101, ED=01/30/96
VER/1.1
CHK/1,300101
CGD/UNKNOWN
ORG/Nautical Data International Inc., 1 Military Rd., P.O. Box 127, Station C S
t. John's, NF, A1C 5H5, on behalf of: Canadian Hydrographic Service, 615 Bo
oth St., Room 237, Ottawa, Ontario, K1A 0E6
K01/NA=VANCOUVER ISLAND JUAN DE FUCA STRAIT TO ,NU=3001,TY=BASE,FN=300101.kap
Content of 300101.kap, just the start of the header:
!Copyright 1996, NDI. All Rights Reserved
BSB/NA=VANCOUVER ISLAND JUAN DE FUCA STRAIT TO ,NU=300101,RA=11007,7671,DU=254
KNP/SC=525000,GD=NAD27,PR=MERCATOR
PP=49.80000,PI= 0.50000,SP=UNKNOWN,0,SK= 0.00
UN=FATHOMS AND FEET,SD=LNT,DX=52.50,DY=52.50
CED/SE=3001,RE= 300101,ED=01/30/96
VER/1.1
OST/1
IFM/4
REF/1,229,7299,47.9831639,-130.1180083
REF/2,10848,7298,47.9831639,-122.3346750
REF/3,10847,255,51.3331639,-122.3346750
more REFs, PLYs....
The libbsb project explains some of the tokens.
http://libbsb.sourceforge.net/bsb_file_format.html
For simplicity, here is a local copy of above:
The BSB file format A BSB image file has a .KAP extension and can be optionally accompanied by a .BSB file which stores further cartographic data and relates multiple .KAPs together. It 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 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 One more commented header example: The text header is terminated with a sequence (ASCII characters 26 and 0). I have derived the following meanings for tokens: One more commented header example: 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 - Entries in the raster colormap of the form index,red,green,blue (index 0 is not used in BSB) 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) PLY - Border polygon of the map within the raster image, given in chart datum lat/long DTM - Datum's northing and easting in floating point seconds (appears to be optional for many charts) Binary Section The first byte after the 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 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. Author The libbsb library and this web page was written by Stuart Cunningham with GIS related advice from Anuradha Suraparaju. Feedback is welcome. Copyright (©) 2000, 2004, Stuart Cunningham.