I am trying to get the same result from these two functions presented in QGIS 3.16. The first one is "Generate XYZ Tiles (Directory)" that it is embedded in QGIS, while the second one is the GDAL function "Gdal2Tiles".

The first works as it should, it generates a folder structure that my TileServer can read, while the latter produces something different, which my TileServer then represents me with overlapping images and other graphical problems. The problem with the first function is that for large images (about 60GB), it crashes. While GDAL also works well with large images.

Gdal2Tiles has 3 "Tile cutting profile": Raster, Mercator, Geodetic. Geodetic is the one that comes closest to the structure I need, even if it always has some graphic errors.


For example, using "Gdal2Tiles" I obtain a folder structure of 7/76/83.png, using the code below:

python3 -m gdal2tiles -p geodetic -z 0-10 -w openlayers -r average -s EPSG:3857 --xyz -a 0.0 -n C:/image.tif C:\gdal-xyz-geodetic

While in "Generate XYZ Tiles (Directory)" I obtain 7/76/50.png

You can download my TIFF for a test here.

1 Answer 1


By default, "Generate XYZ Tiles (Directory)" uses XYZ tile scheme whereas "gdal2Tiles" uses TMS tile scheme.

The difference is XYZ convention starts tile numbering with coordinates 0, 0 from the top left corner whereas TMS convention starts it with the bottom left corner.

You may encounters other issues related to projections, tiling grid, dpi or tile size but you will need at least to use one scheme or another. To do so, you need:

  • to tick the checkbox "Use inverted tile Y axis (TMS convention)" in "Generate XYZ Tiles (Directory)" algorithm


  • cute & paste command in "GDAL/OGR console call" of "gdal2tiles" algorithm and add an --xyz option (see gdal2tiles.py doc) and run it from command line (did not see how it was possible to add --xyz option within QGIS GUI !?)

In first case, all your generated tiles will use TMS generated tiles whereas in second case, they will all be XYZ based.

In fact, I lied a bit to simplify. It's also possible to consume mixed TMS and XYZ data sources but it would depend of clients consumption (the type of desktop GIS or webmapping library) but it would be "another story".


I'm able to perfectly overlay them with the following recipe.

The PyQGIS line is the equivalent of the GUI "Generate XYZ Tiles (Directory)" call I've made

# Generate XYZ tiles (Directory) algorithm
# My project is using EPSG 3857 and I've only ticked your sample image.tif 
processing.run("qgis:tilesxyzdirectory", {'EXTENT':'4022887.805000000,4048078.334600000,4192152.672100000,4217453.156000000 [EPSG:3857]','ZOOM_MIN':0,'ZOOM_MAX':13,'DPI':96,'BACKGROUND_COLOR':QColor(0, 0, 0, 0),'TILE_FORMAT':0,'QUALITY':75,'METATILESIZE':4,'TILE_WIDTH':256,'TILE_HEIGHT':256,'TMS_CONVENTION':False,'OUTPUT_DIRECTORY':'/tmp/xyz-qgis','OUTPUT_HTML':'TEMPORARY_OUTPUT'})

Run from command line as option --xyz not available within QGIS

# Gdal2tiles from QGIS + additional --processes=4 --xyz
gdal2tiles.py -p mercator -z 0-13 -w all --processes=4 --xyz -r average -a 0.0 /home/thomasg/Téléchargements/image.tif /tmp/gdal2tiles

See demo at https://labs.webgeodatavore.com/partage/demo-xyz-qgis-vs-gdal2tiles/openlayers.html (tick/untick the overlays in right button)

  • Thank you for your answer, I forgot to specify that I was already using the -xyz command... I added a new part in the question
    – Koba
    Jul 9, 2021 at 7:39
  • 1
    Edited with test on your data and working
    – ThomasG77
    Jul 9, 2021 at 8:58
  • Amazing, this is now working! Thank you very much! So, the lacking part was the "Tile cutting profile: Mercator"?
    – Koba
    Jul 9, 2021 at 9:24
  • Could it be that the mercator "Tile cutting profile" is the most complex? I'm trying to get the 60GB TIFF (EPSG:4326) to process and it takes 1 hour to make 5 tiles...
    – Koba
    Jul 9, 2021 at 12:42
  • You may try to transform your Geotiff to a COG (cogeo.org). It may speed up things because of pyramids. PS: only a guess here, untested on my side.
    – ThomasG77
    Jul 9, 2021 at 13:02

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.