1

I would like to create a bunch of mbtiles. The code runs and creates the file, but it is "empty", have minimal size (16kb).

import os
import processing
from qgis.core import QgsRasterLayer

raster = QgsRasterLayer("D:/Users/lnemeth/App_MbTiles/7478.tiff", 'layer')
param_dict = {
            "INPUT": raster,
            "EXTENT": raster,
            "ZOOM_MIN":10,
            "ZOOM_MAX":18,
            "OUTPUT_FILE":'D:/Users/lnemeth/App_MbTiles/try.mbtiles'
            }

processing.run("qgis:tilesxyzmbtiles", param_dict)

EDIT: It is a raster in EPSG:31466, I realised the problem is that the layer extent returns a <QgsRectangle: 0 0, 0 0> and I don't know why. If i try manually or use the exact coordinates it works.

EDIT2: I finally calculated the extent (still dont know what was the problem, at some point it just worked), now the console says the extent is invalid if i convert it to string, if i leave it like that then the same problem happens (minimal file size, no data content).

4
  • 1
    Check the return value of processing.run(). And are you sure you can simply pass the raster layer as extent? Commented Jun 27, 2023 at 13:18
  • @bugmenot123 I tried using the current extent, even calculate with a separate line of the code and it returns <QgsRectangle: 0 0, 0 0>, it might be the problem but I don't know why is it like this. If i do manually and use the correct values of an extent it works but as i put into the a script with the same parameters it only works when I specify the coordinates, otherwise the extent just returns those 4 zeroes. Commented Jun 27, 2023 at 14:00
  • 1
    If you create a new QGIS project, use a OSM background and load your raster file, does it display at the correct location? Commented Jun 27, 2023 at 14:19
  • 1
    @bugmenot123 Yes it does. Commented Jun 27, 2023 at 14:22

1 Answer 1

0

I solved by changing the raster layer's loading method to iface.addRasterLayer(), now it creates the correct, not empty mbtiles.

Also I later encountered another bug, but it was solved by using older QGIS version (3.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.