3

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.

Chris W
15.8k2 gold badges30 silver badges47 bronze badges
asked Dec 30, 2014 at 21:26
1
  • 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? Commented Jan 1, 2015 at 17:24

3 Answers 3

1

As another workaround, you can use the python module subprocess

import subprocess
subprocess.call(["gdal_translate","-of", "GTiff ", sourcefile , destinationfile])
answered Jan 2, 2015 at 20:49
2
  • 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. Commented Jan 2, 2015 at 22:11
  • 1
    maybe you should add the full path to your gdal_translate.exe Commented Jan 3, 2015 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.

answered Jan 6, 2015 at 20:20
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.

answered Jan 6, 2015 at 23:24

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.