|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | + |
| 3 | +""" |
| 4 | +*************************************************************************** |
| 5 | + SagaAlgorithm230.py |
| 6 | + --------------------- |
| 7 | + Date : March 2017 |
| 8 | + Copyright : (C) 2017 by Victor Olaya |
| 9 | + Email : volayaf at gmail dot com |
| 10 | +*************************************************************************** |
| 11 | +* * |
| 12 | +* This program is free software; you can redistribute it and/or modify * |
| 13 | +* it under the terms of the GNU General Public License as published by * |
| 14 | +* the Free Software Foundation; either version 2 of the License, or * |
| 15 | +* (at your option) any later version. * |
| 16 | +* * |
| 17 | +*************************************************************************** |
| 18 | +""" |
| 19 | + |
| 20 | +__author__ = 'Victor Olaya' |
| 21 | +__date__ = 'March 2017' |
| 22 | +__copyright__ = '(C) 2017, Victor Olaya' |
| 23 | + |
| 24 | +# This will get replaced with a git SHA1 when you do a git archive |
| 25 | + |
| 26 | +__revision__ = '$Format:%H$' |
| 27 | + |
| 28 | +import os |
| 29 | +from SagaAlgorithm214 import SagaAlgorithm214 |
| 30 | +from processing.tools import dataobjects |
| 31 | +from processing.tools.system import getTempFilenameInTempFolder |
| 32 | + |
| 33 | +sessionExportedLayers = {} |
| 34 | + |
| 35 | + |
| 36 | +class SagaAlgorithm230(SagaAlgorithm214): |
| 37 | + |
| 38 | + def getCopy(self): |
| 39 | + newone = SagaAlgorithm230(self.descriptionFile) |
| 40 | + newone.provider = self.provider |
| 41 | + return newone |
| 42 | + |
| 43 | + def exportRasterLayer(self, source): |
| 44 | + global sessionExportedLayers |
| 45 | + if source in sessionExportedLayers: |
| 46 | + exportedLayer = sessionExportedLayers[source] |
| 47 | + if os.path.exists(exportedLayer): |
| 48 | + self.exportedLayers[source] = exportedLayer |
| 49 | + return None |
| 50 | + else: |
| 51 | + del sessionExportedLayers[source] |
| 52 | + layer = dataobjects.getObjectFromUri(source, False) |
| 53 | + if layer: |
| 54 | + filename = layer.name() |
| 55 | + else: |
| 56 | + filename = os.path.basename(source) |
| 57 | + validChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:' |
| 58 | + filename = ''.join(c for c in filename if c in validChars) |
| 59 | + if len(filename) == 0: |
| 60 | + filename = 'layer' |
| 61 | + destFilename = getTempFilenameInTempFolder(filename + '.sgrd') |
| 62 | + self.exportedLayers[source] = destFilename |
| 63 | + sessionExportedLayers[source] = destFilename |
| 64 | + return 'io_gdal 0 -TRANSFORM 1 -RESAMPLING 0 -GRIDS "' + destFilename + '" -FILES "' + source + '"' |
0 commit comments