2013-09-30 16:14:56 +03:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
***************************************************************************
|
|
|
|
gdal2xyz.py
|
|
|
|
---------------------
|
|
|
|
Date : September 2013
|
|
|
|
Copyright : (C) 2013 by Alexander Bruy
|
|
|
|
Email : alexander dot bruy 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. *
|
|
|
|
* *
|
|
|
|
***************************************************************************
|
|
|
|
"""
|
|
|
|
|
|
|
|
__author__ = 'Alexander Bruy'
|
|
|
|
__date__ = 'September 2013'
|
|
|
|
__copyright__ = '(C) 2013, Alexander Bruy'
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2013-09-30 16:14:56 +03:00
|
|
|
# This will get replaced with a git SHA1 when you do a git archive
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2013-09-30 16:14:56 +03:00
|
|
|
__revision__ = '$Format:%H$'
|
|
|
|
|
2017-09-07 19:29:46 +03:00
|
|
|
from qgis.core import (QgsProcessing,
|
2018-05-06 10:29:01 +10:00
|
|
|
QgsProcessingException,
|
2017-09-07 19:29:46 +03:00
|
|
|
QgsProcessingParameterRasterLayer,
|
|
|
|
QgsProcessingParameterBand,
|
|
|
|
QgsProcessingParameterBoolean,
|
2018-03-01 10:37:55 +02:00
|
|
|
QgsProcessingParameterFileDestination
|
|
|
|
)
|
2014-06-02 00:35:49 +02:00
|
|
|
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
|
2014-04-17 01:41:25 +02:00
|
|
|
from processing.algs.gdal.GdalUtils import GdalUtils
|
2017-09-07 19:29:46 +03:00
|
|
|
from processing.tools.system import isWindows
|
2013-09-30 16:14:56 +03:00
|
|
|
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2014-06-02 00:35:49 +02:00
|
|
|
class gdal2xyz(GdalAlgorithm):
|
2013-09-30 16:14:56 +03:00
|
|
|
|
2013-10-01 20:52:22 +03:00
|
|
|
INPUT = 'INPUT'
|
|
|
|
BAND = 'BAND'
|
2017-09-07 19:29:46 +03:00
|
|
|
CSV = 'CSV'
|
2013-10-01 20:52:22 +03:00
|
|
|
OUTPUT = 'OUTPUT'
|
2013-09-30 16:14:56 +03:00
|
|
|
|
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-09-07 19:29:46 +03:00
|
|
|
self.addParameter(QgsProcessingParameterRasterLayer(self.INPUT,
|
|
|
|
self.tr('Input layer')))
|
|
|
|
self.addParameter(QgsProcessingParameterBand(self.BAND,
|
|
|
|
self.tr('Band number'),
|
|
|
|
parentLayerParameterName=self.INPUT))
|
|
|
|
self.addParameter(QgsProcessingParameterBoolean(self.CSV,
|
|
|
|
self.tr('Output comma-separated values'),
|
|
|
|
defaultValue=False))
|
|
|
|
self.addParameter(QgsProcessingParameterFileDestination(self.OUTPUT,
|
|
|
|
self.tr('XYZ ASCII file'),
|
|
|
|
self.tr('CSV files (*.csv)')))
|
2017-05-15 13:40:38 +10:00
|
|
|
|
2017-03-29 12:51:59 +10:00
|
|
|
def name(self):
|
|
|
|
return 'gdal2xyz'
|
|
|
|
|
|
|
|
def displayName(self):
|
|
|
|
return self.tr('gdal2xyz')
|
|
|
|
|
2017-03-29 12:04:09 +10:00
|
|
|
def group(self):
|
|
|
|
return self.tr('Raster conversion')
|
|
|
|
|
2017-12-14 12:05:40 +02:00
|
|
|
def groupId(self):
|
|
|
|
return 'rasterconversion'
|
|
|
|
|
2018-05-05 19:18:41 +10:00
|
|
|
def commandName(self):
|
|
|
|
return 'gdal2xyz'
|
|
|
|
|
2017-12-08 13:51:30 +10:00
|
|
|
def getConsoleCommands(self, parameters, context, feedback, executing=True):
|
2013-09-30 16:14:56 +03:00
|
|
|
arguments = []
|
2013-10-01 20:52:22 +03:00
|
|
|
arguments.append('-band')
|
2017-09-07 19:29:46 +03:00
|
|
|
arguments.append(str(self.parameterAsInt(parameters, self.BAND, context)))
|
|
|
|
|
|
|
|
if self.parameterAsBool(parameters, self.CSV, context):
|
|
|
|
arguments.append('-csv')
|
2013-09-30 16:14:56 +03:00
|
|
|
|
2018-05-06 10:29:01 +10:00
|
|
|
raster = self.parameterAsRasterLayer(parameters, self.INPUT, context)
|
|
|
|
if raster is None:
|
|
|
|
raise QgsProcessingException(self.invalidRasterError(parameters, self.INPUT))
|
|
|
|
|
|
|
|
arguments.append(raster.source())
|
2017-09-07 19:29:46 +03:00
|
|
|
arguments.append(self.parameterAsFileOutput(parameters, self.OUTPUT, context))
|
2013-09-30 16:14:56 +03:00
|
|
|
|
|
|
|
commands = []
|
|
|
|
if isWindows():
|
2013-10-01 20:52:22 +03:00
|
|
|
commands = ['cmd.exe', '/C ', 'gdal2xyz.bat',
|
|
|
|
GdalUtils.escapeAndJoin(arguments)]
|
2013-09-30 16:14:56 +03:00
|
|
|
else:
|
2013-10-01 20:52:22 +03:00
|
|
|
commands = ['gdal2xyz.py', GdalUtils.escapeAndJoin(arguments)]
|
2013-09-30 16:14:56 +03:00
|
|
|
|
2015-05-21 15:43:47 +02:00
|
|
|
return commands
|