I am trying to generate tiles from an OpenStreetMap area with some CAD generated assets superimposed. I am using Generate XYZ tiles.

Can anyone see from the output below why the math domain error might be being generated?

I am quite new to QGIS and this is the first time I have tried to generate tiles in any GIS.

QGIS version: 3.22.1-Białowieża
QGIS code revision: 663dcf8fb9
Qt version: 5.15.2
Python version: 3.9.5
GDAL version: 3.3.2
GEOS version: 3.9.1-CAPI-1.14.2
PROJ version: Rel. 8.1.1, September 1st, 2021
PDAL version: 2.3.0 (git-version: Release)

Algorithm started at: 2021-12-07T15:41:32
Algorithm 'Generate XYZ tiles (Directory)' starting…
Input parameters:
{ 'BACKGROUND_COLOR' : QColor(21, 105, 30, 0), 'DPI' : 96, 'EXTENT' : '506152.007303635,506840.800587922,157942.918894197,158412.463830712 [EPSG:4326]', 'METATILESIZE' : 4, 'OUTPUT_DIRECTORY' : 'TEMPORARY_OUTPUT', 'OUTPUT_HTML' : 'TEMPORARY_OUTPUT', 'QUALITY' : 75, 'TILE_FORMAT' : 0, 'TILE_HEIGHT' : 256, 'TILE_WIDTH' : 256, 'TMS_CONVENTION' : False, 'ZOOM_MAX' : 4, 'ZOOM_MIN' : 0 }

Traceback (most recent call last):
File "/Applications/QGIS.app/Contents/MacOS/../Resources/python/plugins/processing/algs/qgis/TilesXYZ.py", line 578, in processAlgorithm
self.generate(writer, parameters, context, feedback)
File "/Applications/QGIS.app/Contents/MacOS/../Resources/python/plugins/processing/algs/qgis/TilesXYZ.py", line 290, in generate
metatiles = get_metatiles(self.wgs_extent, zoom, self.metatilesize)
File "/Applications/QGIS.app/Contents/MacOS/../Resources/python/plugins/processing/algs/qgis/TilesXYZ.py", line 124, in get_metatiles
right_tile, bottom_tile = deg2num(south_edge, east_edge, zoom)
File "/Applications/QGIS.app/Contents/MacOS/../Resources/python/plugins/processing/algs/qgis/TilesXYZ.py", line 72, in deg2num
ytile = int((1.0 - math.log(math.tan(lat_rad) + (1 / math.cos(lat_rad))) / math.pi) / 2.0 * n)
ValueError: math domain error

Execution failed after 0.01 seconds

Loading resulting layers Algorithm 'Generate XYZ tiles (Directory)' finished HTML output has been generated by this algorithm. Open the results dialog to check it.

  • Welcome to Geographic Information Systems! Welcome to GIS SE! We're a little different from other sites; this isn't a discussion forum but a Q&A site. Your questions should as much as possible describe not just what you want to do, but precisely what you have tried and where you are stuck trying that. Please check out our short tour for more about how the site works
    – Ian Turton
    Dec 7, 2021 at 15:55
  • 3
    It looks like your projection is wrong, probably 3857 instead of 4326
    – Ian Turton
    Dec 7, 2021 at 15:57
  • 1
    Oh, I owe you several beers :) Sorted - very many thanks.
    – P. Krause
    Dec 7, 2021 at 19:02

1 Answer 1


Ian Turton's suggestion cleared the issue:

It looks like your projection is wrong, probably 3857 instead of 4326

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.