2014-10-06 16:58:24 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
***************************************************************************
|
|
|
|
merge.py
|
|
|
|
---------------------
|
|
|
|
Date : October 2014
|
|
|
|
Copyright : (C) 2014 by Radoslaw Guzinski
|
|
|
|
Email : rmgu at dhi-gras 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. *
|
|
|
|
* *
|
|
|
|
***************************************************************************
|
|
|
|
"""
|
|
|
|
|
|
|
|
__author__ = 'Radoslaw Guzinski'
|
|
|
|
__date__ = 'October 2014'
|
|
|
|
__copyright__ = '(C) 2014, Radoslaw Guzinski'
|
|
|
|
|
|
|
|
# This will get replaced with a git SHA1 when you do a git archive
|
|
|
|
|
|
|
|
__revision__ = '$Format:%H$'
|
|
|
|
|
2016-01-25 15:42:11 +02:00
|
|
|
import os
|
|
|
|
|
2018-03-11 11:29:07 +02:00
|
|
|
from qgis.PyQt.QtCore import QCoreApplication
|
2016-04-22 10:38:48 +02:00
|
|
|
from qgis.PyQt.QtGui import QIcon
|
2014-10-06 16:58:24 +02:00
|
|
|
|
2017-08-15 21:29:47 +10:00
|
|
|
from qgis.core import (QgsProcessing,
|
|
|
|
QgsProperty,
|
|
|
|
QgsProcessingParameterMultipleLayers,
|
|
|
|
QgsProcessingParameterEnum,
|
|
|
|
QgsProcessingParameterBoolean,
|
|
|
|
QgsProcessingParameterRasterDestination,
|
|
|
|
QgsProcessingOutputLayerDefinition,
|
|
|
|
QgsProcessingUtils)
|
2014-10-06 16:58:24 +02:00
|
|
|
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
|
|
|
|
from processing.algs.gdal.GdalUtils import GdalUtils
|
fix python pep8 warnings and fix some revealed errors
pep8 --ignore=E111,E128,E201,E202,E203,E211,E221,E222,E225,E226,E227,E231,E241,E261,E265,E272,E302,E303,E501,E701 \
--exclude="ui_*.py,debian/*,python/ext-libs/*" \
.
2015-02-01 14:15:42 +01:00
|
|
|
|
2016-01-25 15:42:11 +02:00
|
|
|
pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0]
|
2014-10-06 16:58:24 +02:00
|
|
|
|
2015-08-22 14:29:41 +02:00
|
|
|
|
2014-10-06 16:58:24 +02:00
|
|
|
class buildvrt(GdalAlgorithm):
|
|
|
|
|
|
|
|
INPUT = 'INPUT'
|
|
|
|
OUTPUT = 'OUTPUT'
|
|
|
|
RESOLUTION = 'RESOLUTION'
|
|
|
|
SEPARATE = 'SEPARATE'
|
|
|
|
PROJ_DIFFERENCE = 'PROJ_DIFFERENCE'
|
2014-11-30 10:26:17 +01:00
|
|
|
|
2014-10-06 16:58:24 +02:00
|
|
|
RESOLUTION_OPTIONS = ['average', 'highest', 'lowest']
|
|
|
|
|
2017-05-15 13:40:38 +10:00
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
2017-06-27 17:20:57 +10:00
|
|
|
|
|
|
|
def initAlgorithm(self, config=None):
|
2017-08-17 04:11:53 +10:00
|
|
|
|
|
|
|
class ParameterVrtDestination(QgsProcessingParameterRasterDestination):
|
|
|
|
|
|
|
|
def __init__(self, name, description):
|
|
|
|
super().__init__(name, description)
|
|
|
|
|
2017-08-18 00:37:58 +10:00
|
|
|
def clone(self):
|
|
|
|
copy = ParameterVrtDestination(self.name(), self.description())
|
|
|
|
return copy
|
|
|
|
|
2017-08-17 04:11:53 +10:00
|
|
|
def type(self):
|
|
|
|
return 'vrt_destination'
|
|
|
|
|
|
|
|
def defaultFileExtension(self):
|
|
|
|
return 'vrt'
|
|
|
|
|
2017-08-15 21:29:47 +10:00
|
|
|
self.addParameter(QgsProcessingParameterMultipleLayers(self.INPUT,
|
2018-03-11 11:29:07 +02:00
|
|
|
QCoreApplication.translate("ParameterVrtDestination", 'Input layers'),
|
2017-09-06 16:59:48 +03:00
|
|
|
QgsProcessing.TypeRaster))
|
2017-08-15 21:29:47 +10:00
|
|
|
self.addParameter(QgsProcessingParameterEnum(self.RESOLUTION,
|
2018-03-11 11:29:07 +02:00
|
|
|
QCoreApplication.translate("ParameterVrtDestination", 'Resolution'),
|
2017-09-06 16:59:48 +03:00
|
|
|
options=self.RESOLUTION_OPTIONS,
|
|
|
|
defaultValue=0))
|
2017-08-15 21:29:47 +10:00
|
|
|
self.addParameter(QgsProcessingParameterBoolean(self.SEPARATE,
|
2018-03-11 11:29:07 +02:00
|
|
|
QCoreApplication.translate("ParameterVrtDestination", 'Layer stack'),
|
2017-09-06 16:59:48 +03:00
|
|
|
defaultValue=True))
|
2017-08-15 21:29:47 +10:00
|
|
|
self.addParameter(QgsProcessingParameterBoolean(self.PROJ_DIFFERENCE,
|
2018-03-11 11:29:07 +02:00
|
|
|
QCoreApplication.translate("ParameterVrtDestination", 'Allow projection difference'),
|
2017-09-06 16:59:48 +03:00
|
|
|
defaultValue=False))
|
2018-03-11 11:29:07 +02:00
|
|
|
self.addParameter(ParameterVrtDestination(self.OUTPUT, QCoreApplication.translate("ParameterVrtDestination", 'Virtual')))
|
2017-05-15 13:40:38 +10:00
|
|
|
|
2017-03-29 12:51:59 +10:00
|
|
|
def name(self):
|
2017-03-29 17:09:39 +10:00
|
|
|
return 'buildvirtualraster'
|
2017-03-29 12:51:59 +10:00
|
|
|
|
|
|
|
def displayName(self):
|
2018-03-11 11:29:07 +02:00
|
|
|
return QCoreApplication.translate("buildvrt", 'Build Virtual Raster')
|
2017-03-29 12:51:59 +10:00
|
|
|
|
2017-03-29 10:42:42 +10:00
|
|
|
def icon(self):
|
2016-01-25 15:42:11 +02:00
|
|
|
return QIcon(os.path.join(pluginPath, 'images', 'gdaltools', 'vrt.png'))
|
|
|
|
|
2017-03-29 12:04:09 +10:00
|
|
|
def group(self):
|
2018-03-11 11:29:07 +02:00
|
|
|
return QCoreApplication.translate("buildvrt", 'Raster miscellaneous')
|
2017-03-29 12:04:09 +10:00
|
|
|
|
2017-12-14 12:05:40 +02:00
|
|
|
def groupId(self):
|
|
|
|
return 'rastermiscellaneous'
|
|
|
|
|
2018-05-14 11:32:55 +07:00
|
|
|
def commandName(self):
|
|
|
|
return "gdalbuildvrt"
|
|
|
|
|
2017-12-08 13:51:30 +10:00
|
|
|
def getConsoleCommands(self, parameters, context, feedback, executing=True):
|
2014-10-06 16:58:24 +02:00
|
|
|
arguments = []
|
|
|
|
arguments.append('-resolution')
|
2017-08-15 21:29:47 +10:00
|
|
|
arguments.append(self.RESOLUTION_OPTIONS[self.parameterAsEnum(parameters, self.RESOLUTION, context)])
|
|
|
|
if self.parameterAsBool(parameters, buildvrt.SEPARATE, context):
|
2014-10-06 16:58:24 +02:00
|
|
|
arguments.append('-separate')
|
2017-08-15 21:29:47 +10:00
|
|
|
if self.parameterAsBool(parameters, buildvrt.PROJ_DIFFERENCE, context):
|
2014-10-06 16:58:24 +02:00
|
|
|
arguments.append('-allow_projection_difference')
|
|
|
|
# Always write input files to a text file in case there are many of them and the
|
|
|
|
# length of the command will be longer then allowed in command prompt
|
2018-03-21 21:05:31 +10:00
|
|
|
list_file = GdalUtils.writeLayerParameterToTextFile(filename='buildvrtInputFiles.txt', alg=self, parameters=parameters, parameter_name=self.INPUT, context=context, executing=executing, quote=False)
|
2014-10-06 16:58:24 +02:00
|
|
|
arguments.append('-input_file_list')
|
2018-03-21 21:05:31 +10:00
|
|
|
arguments.append(list_file)
|
2017-08-15 21:29:47 +10:00
|
|
|
|
|
|
|
out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
|
2014-10-06 16:58:24 +02:00
|
|
|
arguments.append(out)
|
|
|
|
|
2018-05-14 11:32:55 +07:00
|
|
|
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
|