Convert KAP to CAL Files

piclayerKAP files (sometimes also referred to as BSB files) are raster images which contains a header with geographic information. Those files are typically used for raster navigational charts.

Josm is a powerful editor for Openstreetmap data. There is a plugin called the Piclayer plugin (see also here) which allows to load any image into Josm as background and to distort it to fit to the geographic coordinate system. This information may then be saved to a CAL file.

The CAL file contains the center point of the image (the origin) in some weird coordinate system, the scale which is the length of 100 pixels in the same coordinate system, and a three-dimensional transformation matrice. The center may be any point on the world (I guess that the current center of the Josm window is used while loading the image the first time) and the transformation matrice is used to transform the image from this origin to the real position.

With this information we can directly load a picture to the real origin and scale without using the transformation matrice, i.e. we do not need to know how it works in detail.

I worked several hours to find out how the coordinate system of Piclayer works. I got some hints on its Wiki page but the documentation is a little bit unclear and incomplete. Furthermore the author seems to be disappeared two years ago, also the source code is not documented well.

However, here is basic transformation formula:

// l ... longitude of point in degrees
// b ... latitude of point in degrees
U = 60 * 1855.35;
DEG = 180 / PI;
x = l * U;
y = ln(tan((PI / 4) * (b / 90 + 1))) * U * DEG;

I wrote a Perl script1 which reads the KAP header from stdin and outputs the CAL information to stdout. Look at the code, there are some limitations at the moment.

Have fun using it and don’t hesitate to contact me 🙂

1 comment

  1. I updated the y formula because the radians-to-degrees multiplication was missing.

Comments have been disabled.