0

I am using the gdal_retile.py script, but this question can translate to other gdal processes. I am wondering if there is a work around to where a user could select a list of drivers, to save as different formats (other than running the function twice). This example gives the expected error. Could this be added future feature or is there a reason why this should not be done?

def retile(ortho, out_path, height, width, overlap):
    tiler = gdal_retile
    tiler.TileHeight = height
    tiler.TileWidth = width
    tiler.overlap = overlap
    tiler.TargetDir = out_path
    tiler.Names = [ortho]
    tiler.Format = ['JPEG', 'GeoTIFF']  
    return tiler.main()
TypeError: in method 'GetDriverByName', argument 1 of type 'char const *'

1 Answer 1

1

That is not supported as you can see by having a look at the "Synopsis" part of the documentation of each GDAL tool. For example https://gdal.org/programs/gdal_translate.html

gdal_translate [--help-general]
    [-ot {Byte/Int16/UInt16/UInt32/Int32/UInt64/Int64/Float32/Float64/
            CInt16/CInt32/CFloat32/CFloat64}] [-strict]
    [-if format]* [-of format]
    [-b band]* [-mask band] [-expand {gray|rgb|rgba}]
    [-outsize xsize[%]|0 ysize[%]|0] [-tr xres yres]
    [-r {nearest,bilinear,cubic,cubicspline,lanczos,average,rms,mode}]
    [-unscale] [-scale[_bn] [src_min src_max [dst_min dst_max]]]* [-exponent[_bn] exp_val]*
    [-srcwin xoff yoff xsize ysize] [-epo] [-eco]
    [-projwin ulx uly lrx lry] [-projwin_srs srs_def]
    [-a_srs srs_def] [-a_coord_epoch <epoch>]
    [-a_ullr ulx uly lrx lry] [-a_nodata value]
    [-a_scale value] [-a_offset value]
    [-nogcp] [-gcp pixel line easting northing [elevation]]*
    |-colorinterp{_bn} {red|green|blue|alpha|gray|undefined}]
    |-colorinterp {red|green|blue|alpha|gray|undefined},...]
    [-mo "META-TAG=VALUE"]* [-q] [-sds]
    [-co "NAME=VALUE"]* [-stats] [-norat] [-noxmp]
    [-oo NAME=VALUE]*
    src_dataset dst_dataset

If several outputs were supported the synopsis would show dst_dataset*

I do not see especially good reasons to add such feature. The other command options have often connection to outputformat so user should be able to give different options for each output format "for JPEG use compression use QUALITY=85, for PNG use ZLEVEL=8". I think that would be at least as complicated for users as to run the command twice. In most cases GDAL would still need to run the process two times so there would be no savings in processing time.

If the data source is slow or hard to process it could make sense to cache the data into some speedy format and use that for the subsequent processes. However, users can do that themselves relatively easy for example by reading data from a slow WFS service into a GeoPackage file and by using the local .gpkg file for next conversions

For more complicated ETL processes with several outputs I would have a look at dedicated tools like the Graphical modeler in QGIS.

1
  • Appreciate the explanation and additional information. Makes sense regarding "different options for each output format". I had a feeling it probably wouldn't make much sense, but wanted to consult with some more experienced users.
    – Binx
    Jun 15, 2022 at 19:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.