1

I have a MapInfo TAB file which looks like this:

!table
!version 300
!charset WindowsLatin1

Definition Table
  File "hp.tif"
  Type "RASTER"
  (400000,1300000) (0,0) Label "TL",
  (500000,1300000) (10000,0) Label "TR",
  (500000,1200000) (10000,10000) Label "BR",
  (400000,1200000) (0,10000) Label "BL"
  CoordSys Earth Projection 8, 79, "m", -2, 49, 0.9996012717, 400000, -100000
  Units "m"

I also have an image file for the referenced area. I'm trying to convert this to an mbtiles file which is almost working but it's slightly out of alignment.

I'm obtaining the bounding box from this file which is 400000, 1200000, 500000, 1300000 which I'm then converting to latitude / longtiude which is -2.0018997431234, 60.670742105011, -0.17172476489587, 61.580961113449.

I'm then using the following code to convert this to an MBTiles grid using zoom 12:

$x = (int)floor((($longitude + 180) / 360) * pow(2, $zoom))
$y = pow(2, $zoom) - (int)floor((1 - log(tan(deg2rad($latitude)) + 1 / cos(deg2rad($latitude))) / pi()) / 2 * pow(2, $zoom)) - 1;

This produces a grid of 2025 - 2046 and 2921 - 2943.

So far so good. Next, I scale the associated image to 256px * tiles X x 256px * tiles Y and export 256x256 tiles mapped to the grid tiles/columns.

This produces an mbtiles file which works but is slightly out of alignment with the the real map.

I have attempted to export the same files using MapTiler Desktop and this produces an mbtiles file with the same grid of 2025 - 2046 and 2921 - 2943 but it aligns perfectly. I can't for the life of me figure out why.

What is the -100000 in the CoordSys Earth Projection line for? MapTiler shows the geographical location as 400000 10 0 1300000 0 -10. I'm wondering if the -10 is an offset or something that I need to take into account.

Ian Turton
  • 10,018
  • 1
  • 28
  • 47
Dan
  • 115
  • 1
  • 8

0 Answers0