2012-10-04 19:33:47 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
***************************************************************************
|
|
|
|
GdalAlgorithm.py
|
|
|
|
---------------------
|
|
|
|
Date : August 2012
|
|
|
|
Copyright : (C) 2012 by Victor Olaya
|
|
|
|
Email : volayaf at gmail dot com
|
|
|
|
***************************************************************************
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
***************************************************************************
|
|
|
|
"""
|
2016-04-07 14:02:03 +02:00
|
|
|
from processing.tools import dataobjects
|
2012-10-04 19:33:47 +02:00
|
|
|
|
2015-05-07 13:14:01 +02:00
|
|
|
|
2012-10-04 19:33:47 +02:00
|
|
|
__author__ = 'Victor Olaya'
|
|
|
|
__date__ = 'August 2012'
|
|
|
|
__copyright__ = '(C) 2012, Victor Olaya'
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2012-10-04 19:33:47 +02:00
|
|
|
# This will get replaced with a git SHA1 when you do a git archive
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2012-10-04 19:33:47 +02:00
|
|
|
__revision__ = '$Format:%H$'
|
|
|
|
|
2012-09-15 18:25:25 +03:00
|
|
|
import os
|
2016-01-22 15:45:09 +02:00
|
|
|
|
2016-04-22 10:38:48 +02:00
|
|
|
from qgis.PyQt.QtGui import QIcon
|
2016-01-22 15:45:09 +02:00
|
|
|
|
2014-06-02 00:35:49 +02:00
|
|
|
from processing.core.GeoAlgorithm import GeoAlgorithm
|
2015-05-07 13:14:01 +02:00
|
|
|
from processing.algs.gdal.GdalAlgorithmDialog import GdalAlgorithmDialog
|
|
|
|
from processing.algs.gdal.GdalUtils import GdalUtils
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2015-05-18 19:51:26 +03:00
|
|
|
pluginPath = os.path.normpath(os.path.join(
|
|
|
|
os.path.split(os.path.dirname(__file__))[0], os.pardir))
|
|
|
|
|
2012-09-15 18:25:25 +03:00
|
|
|
|
2014-06-02 00:35:49 +02:00
|
|
|
class GdalAlgorithm(GeoAlgorithm):
|
2014-06-13 09:03:15 +02:00
|
|
|
|
2014-06-02 00:35:49 +02:00
|
|
|
def getIcon(self):
|
2016-03-25 12:56:17 +02:00
|
|
|
return QIcon(os.path.join(pluginPath, 'images', 'gdal.svg'))
|
2012-09-15 18:25:25 +03:00
|
|
|
|
2015-05-07 13:14:01 +02:00
|
|
|
def getCustomParametersDialog(self):
|
|
|
|
return GdalAlgorithmDialog(self)
|
|
|
|
|
|
|
|
def processAlgorithm(self, progress):
|
2016-04-07 14:02:03 +02:00
|
|
|
commands = self.getConsoleCommands()
|
|
|
|
layers = dataobjects.getVectorLayers()
|
2016-05-28 16:25:35 +02:00
|
|
|
supported = dataobjects.getSupportedOutputVectorLayerExtensions()
|
2016-04-07 14:02:03 +02:00
|
|
|
for i, c in enumerate(commands):
|
|
|
|
for layer in layers:
|
|
|
|
if layer.source() in c:
|
2016-05-28 16:25:35 +02:00
|
|
|
c = c.replace(layer.source(), dataobjects.exportVectorLayer(layer, supported))
|
2016-04-07 14:02:03 +02:00
|
|
|
|
|
|
|
commands[i] = c
|
|
|
|
GdalUtils.runGdal(commands, progress)
|
2015-08-22 14:29:41 +02:00
|
|
|
|
2016-01-08 08:27:22 +01:00
|
|
|
def shortHelp(self):
|
|
|
|
return self._formatHelp('''This algorithm is based on the GDAL %s module.
|
|
|
|
|
|
|
|
For more info, see the <a href = 'http://www.gdal.org/%s.html'> module help</a>
|
2016-03-21 04:58:12 +01:00
|
|
|
''' % (self.commandName(), self.commandName()))
|
2015-08-22 14:29:41 +02:00
|
|
|
|
2015-05-21 15:43:47 +02:00
|
|
|
def commandName(self):
|
|
|
|
alg = self.getCopy()
|
|
|
|
for output in alg.outputs:
|
|
|
|
output.setValue("dummy")
|
|
|
|
for param in alg.parameters:
|
|
|
|
param.setValue("1")
|
|
|
|
name = alg.getConsoleCommands()[0]
|
|
|
|
if name.endswith(".py"):
|
|
|
|
name = name[:-3]
|
|
|
|
return name
|