0

Continue from this link, for my situation, the only way to generate .tif to .mbtiles is gdal_translate in QGIS.

This is the .json after using gdal_translate

Setting: GDAL > Raster conversion > translate(convert format)

{
  "tiles": [
    "http://localhost:8009/data/openmaptiles/{z}/{x}/{y}.png"
  ],
  "name": "something8",
  "format": "png",
  "basename": "something8.mbtiles",
  "id": "something8",
  "type": "overlay",
  "description": "something8",
  "version": "1.1",
  "bounds": [
    101.03159452420243,
    3.9388754188813304,
    101.04662092965613,
    3.9534099669676817
  ],
  "minzoom": 21,
  "maxzoom": 21,
  "center": [
    101.03910772692927,
    3.9461426929245063,
    21
  ],
  "tilejson": "2.0.0"
}

And this is the what I need:

{
  "tiles": [
    "http://localhost:8009/data/openmaptiles/{z}/{x}/{y}.png"
  ],
  "name": "something",
  "format": "png",
  "basename": "something.mbtiles",
  "id": "something",
  "type": "overlay",
  "description": "something",
  "version": "1.1",
  "minzoom": 8,
  "maxzoom": 25,
  "bounds": [
    101.02890014648438,
    3.936870437606864,
    101.05138778686523,
    3.9575921925703916
  ],
  "center": [
    101.0401439666748,
    3.9472313150886276,
    16
  ],
  "tilejson": "2.0.0"
}

As you can see the above .json minzoom and maxzoom is fixed at 21, and the below are 8-25. How to set the zoom level from 14-20?

Any idea?

2 Answers 2

0

By the documentation https://gdal.org/drivers/raster/mbtiles.html the driver allows only small adjustment to the base zoom level

ZOOM_LEVEL_STRATEGY=AUTO/LOWER/UPPER. Strategy to determine zoom level. LOWER will select the zoom level immediately below the theoretical computed non-integral zoom level, leading to subsampling. On the contrary, UPPER will select the immediately above zoom level, leading to oversampling. Defaults to AUTO which selects the closest zoom level.

Oversampling more that to UPPER is unreasonable, it would just split pixels and explode the disk space.

How to add lower zoom levels is documented in https://gdal.org/drivers/raster/mbtiles.html#overviews-raster

Overviews (raster)

gdaladdo / BuildOverviews() can be used to compute overviews. Only power-of-two overview factors (2,4,8,16,…) are supported.

If more overview levels are specified than available, the extra ones are silently ignored.

So, for adding zoom levels 14-20 use gdaladdo and see if it is willing to create all the zoom levels that you ask.

gdaladdo my_mbtiles.mbtiles 2 4 8 16 32 64 128
0

gdal_translate allows setting the target raster resolution in georeferenced units per pixel using the -tr option. That can effectively set maxzoom. For example, if the georeferenced units are meters and the desired maximum resolution is 1.0 meters per pixel, one can use e.g.:

gdal_translate -tr 1.0 1.0 -projwin 480000 6600000 481000 6599000 -projwin_srs EPSG:3857 -co TILE_FORMAT=PNG -co TYPE=baselayer -of MBTILES frmt_wms_openstreetmap_tms.xml my_tiles.mbtiles

to download a piece of OpenStreetMap to mbtiles. The source dataset XML configuration file is frmt_wms_openstreetmap_tms.xml:

<GDAL_WMS>
    <Service name="TMS">
        <ServerUrl>https://tile.openstreetmap.org/${z}/${x}/${y}.png</ServerUrl>
    </Service>
    <DataWindow>
        <UpperLeftX>-20037508.34</UpperLeftX>
        <UpperLeftY>20037508.34</UpperLeftY>
        <LowerRightX>20037508.34</LowerRightX>
        <LowerRightY>-20037508.34</LowerRightY>
        <TileLevel>19</TileLevel>
        <TileCountX>1</TileCountX>
        <TileCountY>1</TileCountY>
        <YOrigin>top</YOrigin>
    </DataWindow>
    <Projection>EPSG:3857</Projection>
    <BlockSizeX>256</BlockSizeX>
    <BlockSizeY>256</BlockSizeY>
    <BandsCount>3</BandsCount>
    <!--
    <UserAgent>Please add a specific user agent text, to avoid the default one being used, and potentially blocked by OSM servers in case a too big usage of it would be seen</UserAgent>
    -->
    <Cache />
</GDAL_WMS>

When reading TMS (XYZ tile) maps, the <TileLevel>19</TileLevel> setting also sets the maximum allowed zoom level directly for the source dataset and can be used instead of the -tr option. See https://gdal.org/drivers/raster/wms.html#tms for the relevant documentation.

As @user30184 answered, to set the minzoom limit, one needs to add lower zoom levels (overview images) to the produced mbtiles file using gdaladdo. Assuming your maxzoom is 20, add six lower zoom levels (14-19) using:

gdaladdo my_mbtiles.mbtiles 2 4 8 16 32 64

Your Answer

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

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