Using the following commands to convert a raster to an mbtiles file using gdal and then creating the ZXY schema. The zoom levels it creates are 2,3,4,5 but I need to be able to specify which zoom levels it creates, specifically zoom levels 9 through 12 for my leaflet map.

gdal_translate -of mbtiles temp.tif temp.mbtiles
gdaladdo -r nearest temp.mbtiles
mb-util --image_format=png temp.mbtiles ./temptiles

I've also tried setting zoom level like this, but then that does not produce any zoom levels, when extracted to the ZXY format via mbutil.

gdaladdo -r bilinear -oo "ZOOM_LEVEL=9" temp.mbtiles

Background info on the temp.tif original file:

Size is 1799, 1059
Origin = (-2699020.142521930392832,1588193.847443336388096)
Pixel Size = (3000.,-3000.)
Corner Coordinates:
Upper Left  (-2699020.143, 1588193.847) (134d 7'17.14"W, 47d50'44.64"N)
Lower Left  (-2699020.143,-1588806.153) (122d43'44.80"W, 21d 7'19.89"N)
Upper Right ( 2697979.857, 1588193.847) ( 60d53'28.48"W, 47d50'57.51"N)
Lower Right ( 2697979.857,-1588806.153) ( 72d16'48.48"W, 21d 7'28.62"N)
Center      (    -520.143,    -306.153) ( 97d30'21.52"W, 38d29'50.09"N)
Band 1 Block=1799x1 Type=Float64, ColorInterp=Gray
  Description = 2[m] HTGL="Specified height level above ground"
  Overviews: 900x530, 450x265, 225x133, 113x67, 57x34
  • 3
    As you can see from the documentation gdal.org/drivers/raster/mbtiles.html the MBTiles raster driver does not support the selection of zoom levels. Driver creates the highest zoom level so that the pixel size is about the same than the native resolution of the source raster. You should configure your client to overzoom the last available level. Adding new zoom levels by splitting the pixels would not improve the image quality but each new level would just make the MBTiles file about 4 times bigger.
    – user30184
    Commented Feb 16, 2021 at 20:14

1 Answer 1


As already mentioned in a comment, the GDAL MBTiles driver does not directly allow specifying which zoom levels are created. It creates at the highest zoom level matching the resolution of your input raster only, and then gdaladdo will generate lower zoom levels but not higher ones.

Your resolution of 3000m/pixel is in between zoom levels 5 and 6, if your input raster is in EPSG:3857 already. This comes from https://wiki.openstreetmap.org/wiki/Zoom_levels, where the "m / pixel (equator)" number given is the resolution needed. If you are in a different CRS, gdal_translate will project to 3857 as part of the conversion process. Note that scale in EPSG:3857 is off by cos(latitude) from true scale, so in this case the match to the "m / pixel (equator)" number will be off by the same amount.

Also as mentioned in the comment, if you truly have no further information at finer resolution, client-side overzoom should be used instead. Note that zoom level 12 is 2^(12-5)=128 times zoomed in versus level 5, so a 256x256 pixel tile will only have 4 pixels of real information on it. So I'm not sure users will find it useful to zoom in this much.

Alternatively, if your input tif raster is something you are generating yourself, to get zoom level 12 tiles in the MBTiles you need to create it with a resolution finer than 38 metres per pixel (in EPSG:3857).

Finally, if you truly need fine control over what gets put into an MBTiles file at each zoom level, you can use SQLite to pack it together from different sources. See GDAL create mbtiles with differing image by zoom level for an example in a slightly different context.

Editing to add: I'm noticing your latitude range over the extent is quite large (21 to 47 degrees). The scale mismatch between EPSG:3857 and ground scale therefore varies from a factor of 0.93 to 0.68. If you are not in EPSG:3857 already, and will be tweaking your input raster rather than using the client-side overzoom solution, I would at least for debugging purposes reproject manually to EPSG:3857 first, so that you get the resolution and zoom levels right.

  • Fantastic information - exactly what I needed. Thank you!
    – Ashley A.
    Commented Feb 17, 2021 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.