I am trying to get started with GDAL on a windows machine using Python2.7. I have tried commands such as:

gdalinfo RasterFileName.TIF and gdal_translate.py -projwin ulx uly lrx lry -of GTiff input.TIF output.TIF

and they run without producing any results. What am I missing that makes these not to work.

For example, I am doing the gdal_translate as follows:

    import os
    infile = path+'InFileName.TIF'
    outfile = path+'OUTFileName.TIF'
    string ='gdal_translate -projwin %.0f %.0f %.0f %.0f -of GTiff %s %s' %(ulx,uly,lrx,lry,infile,outfile)

Many thanks

  • Do these run without wrapping them in a python script? What is the output of gdalinfo <some raster> via the command line? – Jay Laura Oct 28 '13 at 17:57
  • Do you want to use GDAL in Python or just in the command line? For GDAL in Python try import gdal gdal.VersionInfo() in Python. For GDAL in the command line try gdalinfo --version in the command line. What are you getting? – ustroetz Oct 28 '13 at 18:09
  • I am getting 'gdal.VersionInfo' is not recognized as an internal or external command, operable program or batch file. – user2757128 Oct 28 '13 at 18:15
  • Do you want to use it in Python? If so, you have to import gdal and then try gdal.VersionInfo() with parentheses. – ustroetz Oct 28 '13 at 18:19
  • Yes I want to use Python. The command 'gdal.Version()' gives me '1100100'. So in python how would I use 'gdal_translate'. – user2757128 Oct 28 '13 at 18:29

On Windows, you have to load the GDAL environment variable to make the command-line utilities to work. With MS4W, for example, you have to run setenv.bat. This set some GDAL environment variables. I suspect your script doesn't have those variable set. You could probably run it before your script.

| improve this answer | |

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