mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-01 00:46:20 -05:00
98 lines
3.9 KiB
Python
98 lines
3.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
***************************************************************************
|
|
ogrinfo.py
|
|
---------------------
|
|
Date : November 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. *
|
|
* *
|
|
***************************************************************************
|
|
"""
|
|
|
|
__author__ = 'Victor Olaya'
|
|
__date__ = 'November 2012'
|
|
__copyright__ = '(C) 2012, Victor Olaya'
|
|
|
|
# This will get replaced with a git SHA1 when you do a git archive
|
|
|
|
__revision__ = '$Format:%H$'
|
|
|
|
|
|
from qgis.core import (QgsProcessingParameterFeatureSource,
|
|
QgsProcessingParameterBoolean,
|
|
QgsProcessingParameterFileDestination,
|
|
QgsProcessingOutputHtml)
|
|
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
|
|
from processing.algs.gdal.GdalUtils import GdalUtils
|
|
|
|
|
|
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(QgsProcessingParameterFeatureSource(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('Vector information')
|
|
|
|
def group(self):
|
|
return self.tr('Vector miscellaneous')
|
|
|
|
def group(self):
|
|
return 'vectormiscellaneous'
|
|
|
|
def getConsoleCommands(self, parameters, context, feedback, executing=True):
|
|
arguments = ['ogrinfo']
|
|
arguments.append('-al')
|
|
|
|
if self.parameterAsBool(parameters, self.SUMMARY_ONLY, context):
|
|
arguments.append('-so')
|
|
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, 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}
|