Skip to content

Commit

Permalink
[processing] restore ogrinfo algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Oct 11, 2017
1 parent 7c9d634 commit 105222e
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 37 deletions.
57 changes: 35 additions & 22 deletions python/plugins/processing/algs/gdal/ogrinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,56 +26,69 @@
__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.addOutput(OutputHTML(self.OUTPUT, self.tr('Layer information')))
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.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}
30 changes: 15 additions & 15 deletions python/plugins/processing/tests/testdata/gdal_algorithm_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 105222e

Please sign in to comment.