I am using gdal.Translate() of Python instead of command line gdal_translate. Most of the options in GDAL. Translate are the same with gdal_translate and I could find them easily in gdal.TranslateOptions but I am struggling on how to input the WMS XML (https://gdal.org/drivers/raster/wms.html) in the function.

Normally in command line I would do something like this:

gdal_translate -of PNG -outsize 512 512 frmt_wms_openstreetmap_tms.xml openstreetmap.png

Does someone know how to do the same in gdal.Translate()?


1 Answer 1


I figured it out finally!!! For me it worked like this: First I opened the xml file as googlemaps_xml=gdal.Open('C:/notebooks_scripts/frmt_wms_googlemaps_satellite_tms.xml') and set the output dataset name as my_image = 'my_image.jpg' Then I used the xml as the srcDS (see for more info on the parameteres osgeo.gdal-module.html#TranslateOptions) and added all the other parameters I needed.

gdal.Translate(my_image, frmt_wms_googlemaps_satellite_tms, format='JPEG', width=512, height=512, projWin=[ulx, uly, lrx, lry], 

*ul => Upper Left, lr => Lower right

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.