I am trying to do the following but it is falling over i.e. (has no error message and doesnt start the tiling process). I think the parsing of the zoom level argument is falling over. I havent been able to parse the zoom level

NB. the vrtName variable contains the zoomLevel as string "0-5", "5-10", or "10-18" which was taken from the vrt names 0-5.vrt, 5-10.vrt and 10-18.vrt

data = vrtName.split("-")

minZoomLevel = data[0]

maxZoomLevel = data[1]

print("gdal2tiles tiling process started.....")

os.system('python "C:\Program Files\GDAL\gdal2tiles.py" -p geodetic -z ' + str(minZoomLevel) + '-' + str(maxZoomLevel) + ' C:/Marine/mosaic_tif/' + vrtName + '.tif ' + outputFolder + clientName + str(n)) n = n + 1

Is it possible to change the zoom level parameter dynamically in a gdal2tiles call within python?

1 Answer 1


It seems to me that os.system can't parse your -z parameter because when summing all the string you give to console I get (placing 6 to minZoomLevel and 10 to maxZoomLevel):

os.system('python "C:\Program Files\GDAL\gdal2tiles.py" -p geodetic -z 6-10 C:/Marine/mosaic_tif/name.tif ' + outputFolder + clientName + str(n))

but the correct is -z "6-10".

As for me, for tiling I use python library gdal2tiles - this is very convenient and understandable! You can pass parameters as a dict or directly in function calling

  • Hi Jane, you're an absolute LEGEND! You saved my bacon! That has worked i.e. putting the zoom level within "" such as zoomLevel = repr(vrtName) and then adding to os.system('python "C:\Program Files\GDAL\gdal2tiles.py" -p geodetic -z ' + zoomLevel + ' C:/Marine/mosaic_tif/name.tif ' + outputFolder + clientName + str(n)). Just wondering how to know how zoom levels to specify are determined? Is there a rule of thumb to know what zoom level is best to use? I am new to working with raster data. Grateful for any useful links. Best Regards Dave
    – daveb
    Commented Oct 17, 2018 at 16:37
  • I used the first approach as my GDAL is a mess. I am working on Windows 10 and tried to call "from geo import gda"l within python to then use gdal2tiles within python itself rather than have to use the gdal2tiles called through os.system but was not able to resolve my OSGeo4W and python installation issues. Dave
    – daveb
    Commented Oct 17, 2018 at 16:43
  • Hi @daveb!) See here wiki.openstreetmap.org/wiki/Zoom_levels for ~ ratio between level and scale. For me this link wiki.openstreetmap.org/wiki/Slippy_map_tilenames was very useful for understanding tiles and tiling
    – Jane
    Commented Oct 18, 2018 at 7:04
  • I also had many issues while installing gdal inside python. Eventually I have succesfully installed library pygdal, that satisfies my gdal version - and now I am able to call gdal2tiles.generate_tiles(input_tif, destination, **options)
    – Jane
    Commented Oct 18, 2018 at 7:19
  • Thanks for the links Jane! Much appreciated.I was wondering if a zoom level is not specified if gdal2tiles works out the optimal zoom level to use?. Also I am unsure why/when to use a zoom level of say 5 over 0-5 or 1-5 or 10-18 or 18. Very confused. What does these instances mean? With regards to the marine charts geotiff data I have they are at various map scales. Do you know if it is feasible to combine TMS data resources folders of map tiff tiled with 0-5 zoom with other TMS data resources that were created from tiling a different map tif that used 5-10 zoom? Is this at all feasible? Dave
    – daveb
    Commented Oct 18, 2018 at 14:04

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.