Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am trying to call gdal_retile from my Python code like this:

import gdal_retile 

and in main:

gdal_retile.main("-v -r bilinear -levels 4 -ps 2048 2048 -co \"tiled=YES\" -targetDir pyramid --optfile files.txt")

but I get this error in my Debug Probe window:

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 what I am doing wrong?

share|improve this question
    
what happens if you try it without the --optfile setting? I've seen a number of threads describing issues with _retile and --optfile. –  elrobis Dec 4 '12 at 13:06
    
same issue.. so I dont think it's the "--optfile" –  Katie E. Dec 4 '12 at 13:48
    
It seems to compain at the first - no matter what option it is. Anyone know why it would do this? –  Katie E. Dec 4 '12 at 15:25
    
If you execute your gdal_retile instruction in a terminal does it behave the same way? That is, running this in a cmd: gdal_retile.py -v -r bilinear -levels 4 -ps 2048 2048 -co "tiled=YES" -targetDir pyramid --optfile files.txt –  elrobis Dec 4 '12 at 15:30
    
nope, it works fine in my DOS window –  Katie E. Dec 4 '12 at 15:55
show 1 more comment

2 Answers

I am not certain, but I am guessing gdal_retile.main() wants a list of arguments, not a string. A small example to show what may be happening:

>>> def test(args):
for i in args:
    print i
>>> a = 'a string of arguments'
>>> b = ['a', 'list', 'of', 'arguments']
>>> test(a)
a

s
t
r
i
n
g

o
f

a
r
g
u
m
e
n
t
s
>>> test(b)
a
list
of
arguments

If a string is passed, each character would be considered an argument. Try:

gdal_retile.main(['-v', '-r', 'bilinear', '-levels', '4', '-ps', '2048', '2048', '-co', '\"tiled=YES\"', '-targetDir', 'pyramid', '--optfile', 'files.txt'])

Like I said, I am just guessing.

share|improve this answer
add comment

Maybe it will work like this. When I want to call ogr2ogr from inside a Python script, I use the os.system() function to execute my ogr2ogr instruction---oftentimes in a loop. But I wonder if this would also work on another .py script. I don't 'see why not (just make sure it can qualify your file paths).


import os

cmd = 'gdal_retile.py -v -r bilinear -levels 4 -ps 2048 2048 -co "tiled=YES" -targetDir pyramid --optfile files.txt'

os.system(cmd)
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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