2

As an example I have a BSB file from NOAA which is a navigational map. The map has a SRS of WGS84 and a Mercator projection.

I initially translate the file from BSB format to GTiff format using the following command:

 gdal_translate -of GTiff 18554_1.kap noaa.tif

I can view this GTiff file using Paint Shop Pro quite fine. I then translate the file from GTiff format to VRT format using the following command:

 gdal_translate -of vrt –expand rgba noaa.tif noaa.vrt

I then try to generate a tile matrix set using the following command:

 gdal2tiles.py noaa.vrt tiles_folder

Where the map tiles are located in tiles_folder. If I try to open the openmaps.html or google.html, the map zoom in and out looks good. However, on tiles generator like MBTiles, I see tiles swap. See the image below. I am pulling my hair off to get the tiles to line up. I am guessing it is projection error. I am not understanding those projection types. It would great someone can explain it while finding the error. I am planning to use on a tiling maps/charts app like this. By the way, on GDAL how do I specify the BSB (reference) file that is associated with KAP (data) file? I have seen cases where only one BSB file referred by multiple KAP files.

Gdal2tiles swapped tiles

user914425
  • 16,303
  • 4
  • 30
  • 41

1 Answers1

4

There is no problem with the map projection, but the tiles are cut according the TMS notation (with tile [0,0] in the bottom left) in GDAL2Tiles. Some tools expect the Google XYZ notation (with tile [0,0] in the upper left corner). The tiles are otherwise equal, they have just flipped Y coordinate in the file name.

Have a look at this:

Google XYZ vs TMS - the flipped Y coordinates in map tiles

I prepared a website which shows visually the difference and also explains the problem. Have a look at:

http://www.maptiler.org/google-maps-coordinates-tile-bounds-projection/

There is also a source code for how the tiles and all coordinates are calculated. It is part of the GDAL2Tiles which you mentioned above - which is a code I created some years back.

Your second question is was about MBTiles. The mbutil utility has a parameter "--scheme tms" which allows to create the MBTiles file from tiles rendered with gdal2tiles.py.

GDAL reads just the KAP file, where each represents a map in the sheet (in case there are insets).

BTW Do you know that there is http://www.maptiler.com/ which solves the problems mentioned above directly? You can just drag&drop into the GUI or pass on the command line the KAP file as it is and choose whether you want tiles in directory or MBTiles and it will directly render the output. The tiles are directly optimised as well, there is support for rendering multiple input files into a single layer and rendering is of magnitude faster then with GDAL2Tiles.

MapTiler
  • 1,754
  • 14
  • 22