mirror of
				https://github.com/qgis/QGIS.git
				synced 2025-10-30 00:07:09 -04:00 
			
		
		
		
	
		
			
				
	
	
		
			89 lines
		
	
	
		
			3.2 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			89 lines
		
	
	
		
			3.2 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| # -*- 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.                                   *
 | |
| *                                                                         *
 | |
| ***************************************************************************
 | |
| """
 | |
| from builtins import str
 | |
| 
 | |
| __author__ = 'Victor Olaya'
 | |
| __date__ = 'August 2012'
 | |
| __copyright__ = '(C) 2012, Victor Olaya'
 | |
| 
 | |
| # This will get replaced with a git SHA1 when you do a git archive
 | |
| 
 | |
| __revision__ = '$Format:%H$'
 | |
| 
 | |
| import os
 | |
| 
 | |
| from qgis.PyQt.QtGui import QIcon
 | |
| 
 | |
| from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
 | |
| from processing.core.parameters import ParameterRaster
 | |
| from processing.core.parameters import ParameterBoolean
 | |
| from processing.core.outputs import OutputHTML
 | |
| from processing.algs.gdal.GdalUtils import GdalUtils
 | |
| 
 | |
| pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0]
 | |
| 
 | |
| 
 | |
| class information(GdalAlgorithm):
 | |
| 
 | |
|     INPUT = 'INPUT'
 | |
|     OUTPUT = 'OUTPUT'
 | |
|     NOGCP = 'NOGCP'
 | |
|     NOMETADATA = 'NOMETADATA'
 | |
| 
 | |
|     def icon(self):
 | |
|         return QIcon(os.path.join(pluginPath, 'images', 'gdaltools', 'raster-info.png'))
 | |
| 
 | |
|     def __init__(self):
 | |
|         super().__init__()
 | |
|         self.addParameter(ParameterRaster(information.INPUT,
 | |
|                                           self.tr('Input layer'), False))
 | |
|         self.addParameter(ParameterBoolean(information.NOGCP,
 | |
|                                            self.tr('Suppress GCP info'), False))
 | |
|         self.addParameter(ParameterBoolean(information.NOMETADATA,
 | |
|                                            self.tr('Suppress metadata info'), False))
 | |
|         self.addOutput(OutputHTML(information.OUTPUT,
 | |
|                                   self.tr('Layer information')))
 | |
| 
 | |
|     def name(self):
 | |
|         return 'gdalinfo'
 | |
| 
 | |
|     def displayName(self):
 | |
|         return self.tr('Information')
 | |
| 
 | |
|     def group(self):
 | |
|         return self.tr('Raster miscellaneous')
 | |
| 
 | |
|     def getConsoleCommands(self, parameters):
 | |
|         arguments = []
 | |
|         if self.getParameterValue(information.NOGCP):
 | |
|             arguments.append('-nogcp')
 | |
|         if self.getParameterValue(information.NOMETADATA):
 | |
|             arguments.append('-nomd')
 | |
|         arguments.append(self.getParameterValue(information.INPUT))
 | |
|         return ['gdalinfo', GdalUtils.escapeAndJoin(arguments)]
 | |
| 
 | |
|     def processAlgorithm(self, parameters, context, feedback):
 | |
|         GdalUtils.runGdal(self.getConsoleCommands(parameters), feedback)
 | |
|         output = self.getOutputValue(information.OUTPUT)
 | |
|         with open(output, 'w') as f:
 | |
|             f.write('<pre>')
 | |
|             for s in GdalUtils.getConsoleOutput()[1:]:
 | |
|                 f.write(str(s))
 | |
|             f.write('</pre>')
 |