1

I do:

import os
from gdal import *

filename = 'c:/rast.jpg'
outputTif = 'c:/rastOut.tif'
os.system('gdal_translate filename outputTif')

but it returns "1".

gdal_translate doesn't save the image to disk. Is any additional parameter needed?

2
  • 1
    Are you sure you didn't mean something like os.system('gdal_translate ' + filename + ' ' + outputTif)? You are using literal 'filename' and 'outputTif', not the values of those variables. – BradHards Apr 6 '13 at 8:51
  • 1
    'it' returned 1 because os.system() encounter an error. If the command would be succefully completed you'd get a '0' – nickves Apr 7 '13 at 1:38
2

You forgot to describe GTiff driver and you do use string instead variable. Code below should work.

import os
from gdal import *

filename = 'c:/rast.jpg'
outputTif = 'c:/rastOut.tif'
os.system('gdal_translate -of GTiff %s %s'%(filename, outputTif))
1
  • 2
    Geotiff is the default output type. It doesn't need to be specified. The rest of your answer is correct though. The problem is the OPs use of literal strings instead of the variables. – user2856 Apr 6 '13 at 10:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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