Skip to content

Commit 83782cc

Browse files
committed
[processing] fixed conversion to unsupported raster formats after running algorithm
1 parent 61d81f0 commit 83782cc

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

python/plugins/processing/core/GeoAlgorithm.py

+27-7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
***************************************************************************
1818
"""
1919

20+
2021
__author__ = 'Victor Olaya'
2122
__date__ = 'August 2012'
2223
__copyright__ = '(C) 2012, Victor Olaya'
@@ -27,10 +28,11 @@
2728

2829
import os.path
2930
import traceback
31+
import subprocess
3032
import copy
3133

3234
from PyQt4.QtGui import QIcon
33-
from PyQt4.QtCore import QCoreApplication
35+
from PyQt4.QtCore import QCoreApplication, QSettings
3436
from qgis.core import QGis, QgsRasterFileWriter
3537

3638
from processing.core.ProcessingLog import ProcessingLog
@@ -294,13 +296,31 @@ def convertUnsupportedFormats(self, progress):
294296
elif isinstance(out, OutputRaster):
295297
if out.compatible is not None:
296298
layer = dataobjects.getObjectFromUri(out.compatible)
297-
provider = layer.dataProvider()
298-
writer = QgsRasterFileWriter(out.value)
299299
format = self.getFormatShortNameFromFilename(out.value)
300-
writer.setOutputFormat(format)
301-
writer.writeRaster(layer.pipe(), layer.width(),
302-
layer.height(), layer.extent(),
303-
layer.crs())
300+
orgFile = out.compatible
301+
destFile = out.value
302+
crsid = layer.crs().authid()
303+
settings = QSettings()
304+
path = unicode(settings.value('/GdalTools/gdalPath', ''))
305+
envval = unicode(os.getenv('PATH'))
306+
if not path.lower() in envval.lower().split(os.pathsep):
307+
envval += '%s%s' % (os.pathsep, path)
308+
os.putenv('PATH', envval)
309+
command = 'gdal_translate -of %s -a_srs %s %s %s' % (format, crsid, orgFile, destFile)
310+
if os.name == 'nt':
311+
command = command.split(" ")
312+
else:
313+
command = [command]
314+
subprocess.Popen(
315+
command,
316+
shell=True,
317+
stdout=subprocess.PIPE,
318+
stdin=subprocess.PIPE,
319+
stderr=subprocess.STDOUT,
320+
universal_newlines=False,
321+
)
322+
323+
304324
elif isinstance(out, OutputTable):
305325
if out.compatible is not None:
306326
layer = dataobjects.getObjectFromUri(out.compatible)

0 commit comments

Comments
 (0)