Skip to content
Permalink
Browse files

Port GDAL info alg to new API

  • Loading branch information
nyalldawson committed Aug 30, 2017
1 parent 12e69d0 commit d0fea64b236759ed7c7e2952d507798721764109
@@ -37,10 +37,10 @@
from .aspect import aspect
from .buildvrt import buildvrt
from .ColorRelief import ColorRelief
from .information import information
from .tri import tri
from .warp import warp
from .nearblack import nearblack
# from .information import information
# from .rgb2pct import rgb2pct
# from .translate import translate
# from .pct2rgb import pct2rgb
@@ -140,12 +140,12 @@ def svgIconPath(self):

def loadAlgorithms(self):
self.algs = [
nearblack(),
# information(),
AssignProjection(),
aspect(),
buildvrt(),
ColorRelief(),
information(),
nearblack(),
tri(),
warp(),
# translate(),
@@ -29,10 +29,11 @@
import os

from qgis.PyQt.QtGui import QIcon

from qgis.core import (QgsProcessingParameterRasterLayer,
QgsProcessingParameterBoolean,
QgsProcessingParameterFileDestination,
QgsProcessingOutputHtml)
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

@@ -53,14 +54,15 @@ def __init__(self):
super().__init__()

def initAlgorithm(self, config=None):
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')))
self.addParameter(QgsProcessingParameterRasterLayer(information.INPUT,
self.tr('Input layer'), optional=False))
self.addParameter(QgsProcessingParameterBoolean(information.NOGCP,
self.tr('Suppress GCP info'), defaultValue=False))
self.addParameter(QgsProcessingParameterBoolean(information.NOMETADATA,
self.tr('Suppress metadata info'), defaultValue=False))

self.addParameter(QgsProcessingParameterFileDestination(self.OUTPUT, self.tr('Layer information'), self.tr('HTML files (*.html)')))
self.addOutput(QgsProcessingOutputHtml(self.OUTPUT, self.tr('Layer information')))

def name(self):
return 'gdalinfo'
@@ -73,18 +75,20 @@ def group(self):

def getConsoleCommands(self, parameters, context, feedback):
arguments = []
if self.getParameterValue(information.NOGCP):
if self.parameterAsBool(parameters, information.NOGCP, context):
arguments.append('-nogcp')
if self.getParameterValue(information.NOMETADATA):
if self.parameterAsBool(parameters, information.NOMETADATA, context):
arguments.append('-nomd')
arguments.append(self.getParameterValue(information.INPUT))
arguments.append(self.parameterAsRasterLayer(parameters, information.INPUT, context).source())
return ['gdalinfo', GdalUtils.escapeAndJoin(arguments)]

def processAlgorithm(self, parameters, context, feedback):
GdalUtils.runGdal(self.getConsoleCommands(parameters), feedback)
output = self.getOutputValue(information.OUTPUT)
GdalUtils.runGdal(self.getConsoleCommands(parameters, context, feedback), feedback)
output = self.parameterAsFileOutput(parameters, self.OUTPUT, context)
with open(output, 'w') as f:
f.write('<pre>')
for s in GdalUtils.getConsoleOutput()[1:]:
f.write(str(s))
f.write('</pre>')

return {self.OUTPUT: output}
@@ -1,23 +1,23 @@
# See ../README.md for a description of the file format

tests:
# - algorithm: gdal:gdalinfo
# name: gdalinfo
# params:
# INPUT:
# name: raster.tif
# type: raster
# NOGCP: false
# NOMETADATA: false
# results:
# OUTPUT:
# name: expected/gdal/raster_info.html
# type: regex
# rules:
# - 'Origin = \(270736.067325068172067,4459029.574521748349071\)'
# - 'Band 1 Block=16x14 Type=Float32, ColorInterp=Gray'
# - ' NoData Value=-32768'
#
- algorithm: gdal:gdalinfo
name: gdalinfo
params:
INPUT:
name: raster.tif
type: raster
NOGCP: false
NOMETADATA: false
results:
OUTPUT:
name: expected/gdal/raster_info.html
type: regex
rules:
- 'Origin = \(270736.067325068172067,4459029.574521748349071\)'
- 'Band 1 Block=16x14 Type=Float32, ColorInterp=Gray'
- ' NoData Value=-32768'

# - algorithm: gdal:ogrinfo
# name: ogrinfo
# params:

0 comments on commit d0fea64

Please sign in to comment.
You can’t perform that action at this time.