1

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)
    os.system(string)

Many thanks

6
  • Do these run without wrapping them in a python script? What is the output of gdalinfo <some raster> via the command line?
    – Jay Laura
    Commented Oct 28, 2013 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
    Commented Oct 28, 2013 at 18:09
  • I am getting 'gdal.VersionInfo' is not recognized as an internal or external command, operable program or batch file. Commented Oct 28, 2013 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
    Commented Oct 28, 2013 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'. Commented Oct 28, 2013 at 18:29

1 Answer 1

0

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.

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