2012-10-04 19:33:47 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
***************************************************************************
|
|
|
|
information.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-09-21 18:24:26 +02:00
|
|
|
from builtins import str
|
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$'
|
|
|
|
|
2016-01-25 15:42:11 +02:00
|
|
|
import os
|
|
|
|
|
2016-04-22 10:38:48 +02:00
|
|
|
from qgis.PyQt.QtGui import QIcon
|
2016-01-25 15:42:11 +02:00
|
|
|
|
2014-06-02 00:35:49 +02:00
|
|
|
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
|
2014-07-14 14:19:09 +02:00
|
|
|
from processing.core.parameters import ParameterRaster
|
|
|
|
from processing.core.parameters import ParameterBoolean
|
|
|
|
from processing.core.outputs import OutputHTML
|
2014-04-17 01:41:25 +02:00
|
|
|
from processing.algs.gdal.GdalUtils import GdalUtils
|
2013-04-10 12:15:55 +04:00
|
|
|
|
2016-01-25 15:42:11 +02:00
|
|
|
pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0]
|
|
|
|
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2014-06-02 00:35:49 +02:00
|
|
|
class information(GdalAlgorithm):
|
2012-09-15 18:25:25 +03:00
|
|
|
|
2013-10-01 20:52:22 +03:00
|
|
|
INPUT = 'INPUT'
|
|
|
|
OUTPUT = 'OUTPUT'
|
|
|
|
NOGCP = 'NOGCP'
|
|
|
|
NOMETADATA = 'NOMETADATA'
|
2012-09-15 18:25:25 +03: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', 'raster-info.png'))
|
|
|
|
|
2017-05-15 13:40:38 +10:00
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
2015-01-13 10:49:08 +02:00
|
|
|
self.addParameter(ParameterRaster(information.INPUT,
|
2015-08-22 14:29:41 +02:00
|
|
|
self.tr('Input layer'), False))
|
2013-10-01 20:52:22 +03:00
|
|
|
self.addParameter(ParameterBoolean(information.NOGCP,
|
2015-08-22 14:29:41 +02:00
|
|
|
self.tr('Suppress GCP info'), False))
|
2013-10-01 20:52:22 +03:00
|
|
|
self.addParameter(ParameterBoolean(information.NOMETADATA,
|
2015-08-22 14:29:41 +02:00
|
|
|
self.tr('Suppress metadata info'), False))
|
2015-01-13 10:49:08 +02:00
|
|
|
self.addOutput(OutputHTML(information.OUTPUT,
|
2015-08-22 14:29:41 +02:00
|
|
|
self.tr('Layer information')))
|
2012-09-15 18:25:25 +03:00
|
|
|
|
2017-05-15 13:40:38 +10:00
|
|
|
def name(self):
|
|
|
|
return 'gdalinfo'
|
|
|
|
|
|
|
|
def displayName(self):
|
|
|
|
return self.tr('Information')
|
|
|
|
|
|
|
|
def group(self):
|
|
|
|
return self.tr('Raster miscellaneous')
|
|
|
|
|
2015-05-07 13:14:01 +02:00
|
|
|
def getConsoleCommands(self):
|
2013-04-10 12:15:55 +04:00
|
|
|
arguments = []
|
2012-09-15 18:25:25 +03:00
|
|
|
if self.getParameterValue(information.NOGCP):
|
2013-10-01 20:52:22 +03:00
|
|
|
arguments.append('-nogcp')
|
2012-09-15 18:25:25 +03:00
|
|
|
if self.getParameterValue(information.NOMETADATA):
|
2013-10-01 20:52:22 +03:00
|
|
|
arguments.append('-nomd')
|
2013-04-10 12:15:55 +04:00
|
|
|
arguments.append(self.getParameterValue(information.INPUT))
|
2015-05-07 13:14:01 +02:00
|
|
|
return ['gdalinfo', GdalUtils.escapeAndJoin(arguments)]
|
|
|
|
|
2017-04-25 14:55:38 +10:00
|
|
|
def processAlgorithm(self, context, feedback):
|
2017-01-06 20:04:00 +10:00
|
|
|
GdalUtils.runGdal(self.getConsoleCommands(), feedback)
|
2012-09-15 18:25:25 +03:00
|
|
|
output = self.getOutputValue(information.OUTPUT)
|
2016-11-07 10:35:15 +10:00
|
|
|
with open(output, 'w') as f:
|
|
|
|
f.write('<pre>')
|
|
|
|
for s in GdalUtils.getConsoleOutput()[1:]:
|
|
|
|
f.write(str(s))
|
|
|
|
f.write('</pre>')
|