3

I have the following gdal_retile command I am trying to run, but it errors on the --optfile:

gdal_retile.py -v -r bilinear -levels 8 -ps 512 512 -co "tiled=YES" -targetDir pyramid --optfile files.txt

   Unrecognised command option: -
   Usage: gdal_retile.py
        [-v] [-co NAME=VALUE]* [-of out_format]
        [-ps pixelWidth pixelHeight]
        [-ot  {Byte/Int16/UInt16/UInt32/Int32/Float32/Float64/
               CInt16/CInt32/CFloat32/CFloat64}]
        [ -tileIndex tileIndexName [-tileIndexField fieldName]]
        [ -csv fileName [-csvDelim delimiter]]
        [-s_srs srs_def]  [-pyramidOnly] -levels numberoflevels
        [-r {near/bilinear/cubic/cubicspline/lanczos}]
        [-useDirForEachRow]
        -targetDir TileDirectory input_files

Any idea why this does not work?

2
  • does it work without the optfile part?
    – underdark
    Commented Nov 6, 2012 at 20:01
  • Can you show the contents of your files.txt? When using --optfile, the text file should contain the absolute path names.
    – dmci
    Commented Nov 7, 2012 at 8:47

2 Answers 2

5

One alternative that may work for you would be to first create a virtual raster and then run gdal_retile.py

gdalbuildvrt -te xmin_vrt ymin_vrt xmax_vrt ymax_vrt -srcnodata "0 0 0" your.vrt ./path/*.tif

gdal_retile.py -v -r bilinear -levels 8 -ps 512 512 -co "tiled=YES" -targetDir pyramid -co "COMPRESS=LZW" -targetDir pyramid ./path/your.vrt

1
  • creative workaround! I like it. It won't generate pyramids for each input image though, just on the vrt, so may not work for some. See my answer for another alternative. Commented Nov 9, 2012 at 5:22
3

from my testing: Unrecognised command option: - is because a filename in files.txt has a dash in it. Enclose the names in quotes ("this-is-an-image.tif") and it will work fine.

Unfortunately the gdal_retile will not operate on multiple files ticket seems to be true; perhaps give it a bump. Here is a Windows cmd line snippet to work around that:

for %a in (*.tif) do gdal_retile "%a" -targetDir pyramids

to use in batch file double up the percents, e.g. %%a

In Linux or Mac bash shell subst a and $a for % and separate phrases with ; (courtesy of @decoder247):

for a in (*.tif); do gdal_retile $a -targetDir pyramids; done
2
  • 1
    Great solution, thanks for this. %a does not seem to work for me though in bash, what worked was: for a in (*.tif); do gdal_retile $a -targetDir pyramids; done
    – decodering
    Commented Feb 11, 2021 at 8:13
  • thanks @decoder247 for the bash expression. folded into the answer. Commented Feb 12, 2021 at 15:47

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.