[processing] restore ogrinfo algorithm

This commit is contained in:
Alexander Bruy 2017-09-08 15:48:54 +03:00
parent 7c9d634323
commit 105222ea8c
2 changed files with 49 additions and 36 deletions

View File

@ -26,56 +26,69 @@ __copyright__ = '(C) 2012, Victor Olaya'
__revision__ = '$Format:%H$'
from processing.core.parameters import ParameterVector
from processing.core.parameters import ParameterBoolean
from processing.core.outputs import OutputHTML
from processing.algs.gdal.GdalUtils import GdalUtils
from qgis.core import (QgsProcessingParameterVectorLayer,
QgsProcessingParameterBoolean,
QgsProcessingParameterFileDestination,
QgsProcessingOutputHtml)
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
from processing.algs.gdal.GdalUtils import GdalUtils
class OgrInfo(GdalAlgorithm):
class ogrinfo(GdalAlgorithm):
INPUT = 'INPUT'
SUMMARY_ONLY = 'SUMMARY_ONLY'
NO_METADATA = 'NO_METADATA'
OUTPUT = 'OUTPUT'
def __init__(self):
super().__init__()
def initAlgorithm(self, config=None):
self.addParameter(ParameterVector(self.INPUT, self.tr('Input layer')))
self.addParameter(ParameterBoolean(self.SUMMARY_ONLY,
self.tr('Summary output only'),
True))
self.addParameter(QgsProcessingParameterVectorLayer(self.INPUT,
self.tr('Input layer')))
self.addParameter(QgsProcessingParameterBoolean(self.SUMMARY_ONLY,
self.tr('Summary output only'),
defaultValue=True))
self.addParameter(QgsProcessingParameterBoolean(self.NO_METADATA,
self.tr('Suppress metadata info'),
defaultValue=False))
self.addOutput(OutputHTML(self.OUTPUT, self.tr('Layer information')))
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 'ogrinfo'
def displayName(self):
return self.tr('Information')
return self.tr('Vector information')
def group(self):
return self.tr('Vector miscellaneous')
def getConsoleCommands(self, parameters, context, feedback):
arguments = ["ogrinfo"]
arguments = ['ogrinfo']
arguments.append('-al')
if self.getParameterValue(self.SUMMARY_ONLY):
if self.parameterAsBool(parameters, self.SUMMARY_ONLY, context):
arguments.append('-so')
layer = self.getParameterValue(self.INPUT)
conn = GdalUtils.ogrConnectionString(layer, context)
arguments.append(conn)
if self.parameterAsBool(parameters, self.NO_METADATA, context):
arguments.append('-nomd')
inLayer = self.parameterAsVectorLayer(parameters, self.INPUT, context)
connectionString = GdalUtils.ogrConnectionString(inLayer.source(), context)
arguments.append(connectionString)
return arguments
def processAlgorithm(self, parameters, context, feedback):
GdalUtils.runGdal(self.getConsoleCommands(parameters), feedback)
output = self.getOutputValue(self.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(s)
f.write(str(s))
f.write('</pre>')
return {self.OUTPUT: output}

View File

@ -306,21 +306,21 @@ tests:
# hash: 2d0585dc8166fbe3cec7d9e6fd66e95cc9bdb1043b3b0fa7cbdfef4c
# type: rasterhash
# - algorithm: gdal:ogrinfo
# name: ogrinfo
# params:
# INPUT:
# name: lines.gml
# type: vector
# SUMMARY_ONLY: 'True'
# results:
# OUTPUT:
# name: expected/gdal/vector_info.html
# type: regex
# rules:
# - 'Extent: \(-1.000000, -3.000000\) - \(11.000000, 5.000000\)'
# - 'Geometry: Line String'
# - 'Feature Count: [6|7]' # On some platforms returns 6 instead of 7...
- algorithm: gdal:ogrinfo
name: ogrinfo
params:
INPUT:
name: lines.gml
type: vector
SUMMARY_ONLY: 'True'
results:
OUTPUT:
name: expected/gdal/vector_info.html
type: regex
rules:
- 'Extent: \(-1.000000, -3.000000\) - \(11.000000, 5.000000\)'
- 'Geometry: Line String'
- 'Feature Count: [6|7]' # On some platforms returns 6 instead of 7...
- algorithm: gdal:pointsalonglines
name: Points along lines