2016-01-25 20:41:56 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
***************************************************************************
|
|
|
|
self.py
|
|
|
|
---------------------
|
|
|
|
Date : January 2016
|
|
|
|
Copyright : (C) 2016 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__ = 'January 2016'
|
|
|
|
__copyright__ = '(C) 2016, Alexander Bruy'
|
|
|
|
|
|
|
|
# This will get replaced with a git SHA1 when you do a git archive
|
|
|
|
|
|
|
|
__revision__ = '$Format:%H$'
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
2016-04-22 10:38:48 +02:00
|
|
|
from qgis.PyQt.QtGui import QIcon
|
2016-01-25 20:41:56 +02:00
|
|
|
|
2018-05-06 10:29:01 +10:00
|
|
|
from qgis.core import (QgsProcessingException,
|
|
|
|
QgsProcessingParameterRasterLayer,
|
2017-08-14 05:41:54 +10:00
|
|
|
QgsProcessingParameterCrs,
|
|
|
|
QgsProcessingOutputRasterLayer)
|
2016-01-25 20:41:56 +02:00
|
|
|
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
|
|
|
|
from processing.algs.gdal.GdalUtils import GdalUtils
|
|
|
|
|
|
|
|
from processing.tools.system import isWindows
|
|
|
|
|
|
|
|
pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0]
|
|
|
|
|
|
|
|
|
|
|
|
class AssignProjection(GdalAlgorithm):
|
2017-09-06 16:59:48 +03:00
|
|
|
|
2016-01-25 20:41:56 +02:00
|
|
|
INPUT = 'INPUT'
|
|
|
|
CRS = 'CRS'
|
|
|
|
OUTPUT = 'OUTPUT'
|
|
|
|
|
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-06 16:59:48 +03:00
|
|
|
self.addParameter(QgsProcessingParameterRasterLayer(self.INPUT,
|
|
|
|
self.tr('Input layer')))
|
2017-08-14 05:41:54 +10:00
|
|
|
self.addParameter(QgsProcessingParameterCrs(self.CRS,
|
2017-08-14 05:55:50 +10:00
|
|
|
self.tr('Desired CRS')))
|
2017-05-15 13:40:38 +10:00
|
|
|
|
2017-09-06 16:59:48 +03:00
|
|
|
self.addOutput(QgsProcessingOutputRasterLayer(self.OUTPUT,
|
|
|
|
self.tr('Layer with projection')))
|
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 'assignprojection'
|
2017-03-29 12:51:59 +10:00
|
|
|
|
|
|
|
def displayName(self):
|
|
|
|
return self.tr('Assign projection')
|
|
|
|
|
2017-03-29 10:42:42 +10:00
|
|
|
def icon(self):
|
2016-01-25 20:41:56 +02:00
|
|
|
return QIcon(os.path.join(pluginPath, 'images', 'gdaltools', 'projection-add.png'))
|
|
|
|
|
2017-03-29 12:04:09 +10:00
|
|
|
def group(self):
|
|
|
|
return self.tr('Raster projections')
|
|
|
|
|
2017-12-20 12:07:32 +01:00
|
|
|
def groupId(self):
|
2017-12-14 12:05:40 +02:00
|
|
|
return 'rasterprojections'
|
|
|
|
|
2018-05-05 19:18:41 +10:00
|
|
|
def commandName(self):
|
|
|
|
return 'gdal_edit'
|
|
|
|
|
2017-12-08 13:51:30 +10:00
|
|
|
def getConsoleCommands(self, parameters, context, feedback, executing=True):
|
2017-08-14 05:41:54 +10:00
|
|
|
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
|
2018-05-06 10:29:01 +10:00
|
|
|
if inLayer is None:
|
|
|
|
raise QgsProcessingException(self.invalidRasterError(parameters, self.INPUT))
|
|
|
|
|
2017-08-14 05:41:54 +10:00
|
|
|
fileName = inLayer.source()
|
|
|
|
|
|
|
|
crs = self.parameterAsCrs(parameters, self.CRS, context).authid()
|
2016-01-25 20:41:56 +02:00
|
|
|
|
|
|
|
arguments = []
|
|
|
|
arguments.append('-a_srs')
|
|
|
|
arguments.append(crs)
|
|
|
|
|
|
|
|
arguments.append(fileName)
|
|
|
|
|
|
|
|
commands = []
|
|
|
|
if isWindows():
|
|
|
|
commands = ['cmd.exe', '/C ', 'gdal_edit.bat',
|
|
|
|
GdalUtils.escapeAndJoin(arguments)]
|
|
|
|
else:
|
|
|
|
commands = ['gdal_edit.py', GdalUtils.escapeAndJoin(arguments)]
|
|
|
|
|
|
|
|
self.setOutputValue(self.OUTPUT, fileName)
|
|
|
|
return commands
|