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.
3 Answers 3
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– Tom2015年01月02日 22:11:23 +00:00Commented Jan 2, 2015 at 22:11 -
1maybe you should add the full path to your gdal_translate.exeradouxju– radouxju2015年01月03日 19:32:29 +00:00Commented Jan 3, 2015 at 19:32
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.
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.
Explore related questions
See similar questions with these tags.
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 folderC:\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?