2

I want GDAL translate in Pythonwin to process some GeoPDFs to GeoTiffs. I can't call up GDAL module in Pywin. I used the OSGeo4 installer for original GDAL install and can leverage GDAL properly from the OSGeo4W.bat file.

My Python and Pywin are from an install of Arc 10.2.2. I created a PythonPath User variable and added C:\Python27\ArcGIS10.2;C:\Python27\ArcGIS10.2\Lib;C:\Python27\ArcGIS10.2\DLLs;C:\Python27\ArcGIS10.2\Lib\lib-tk;C:\OSGeo4W;C:\OSGeo4W\lib;C:\OSGeo4W\lib\tk8.5;C:\OSGeo4W\bin

After a reboot I still can't call up the OSgeo/GDAL module.

While I would like to use GDAL commands in Pythonwin, I have also tried the work around

os.system("gdal_translate -of GTiff " + sourcefile + " " + destinationfile)

which is launching cmd prompts but not processing the files.

Can someone help with sorting out the GDAL module in Pywin or to clue me in on why the os.system command is not calling up GDAL translate.

  • UPDATE I got the GDAL module to import in PythonWin! I copied the osgeo site-package folder from the the GDAL library C:\GDAL\GDALlibrary\x86\release\gdal\gdal-python\gdal-python-1.11.1-5\apps\Python27\Lib\site-packages\osgeo to the PythonWin site-package folder C:\Python27\ArcGIS10.2\Lib\site-packages. That worked, however, it isn't the GDAL tools I am looking for. Translate isn't there and neither is OGR2OGR. Anyone have clues as to where I can find the actual tools I am looking for? – Tom Jan 1 '15 at 17:24
1

As another workaround, you can use the python module subprocess

import subprocess
subprocess.call(["gdal_translate","-of", "GTiff ", sourcefile , destinationfile])
  • Thank you for replying. However, I get the same results from the os.system call. Basically, command prompts open for each target but they don't process. – Tom Jan 2 '15 at 22:11
  • 1
    maybe you should add the full path to your gdal_translate.exe – radouxju Jan 3 '15 at 19:32
1

I never got the GDAL module to work but I was able to get os.system call to work. I just had to fix path issues, meaning I had to use sys.path.append to the location of gdal_translate executable for os.system to run the command correctly. In my case with the OSgeo4W installer this was C:\OSGeo4W\bin. I also had to pass full path names to the os.system command for the source and destination files. With these two fixes I got the script to run as expected.

1

It is more direct to actually use Python, rather than processing system calls, which can be tricky to figure out on different systems. Also, if you have ArcGIS installed on the computer, I highly recommend to install a different Python + GDAL + Pythonwin to avoid any clashes and DLL Hell.

See this answer to convert any GDAL raster dataset to a GeoTIFF file using Python.

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.