2012-12-02 00:03:21 +01:00
|
|
|
# -*- 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'
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2013-01-26 14:16:39 +01:00
|
|
|
|
2018-05-06 10:29:01 +10:00
|
|
|
from qgis.core import (QgsProcessingException,
|
|
|
|
QgsProcessingParameterVectorLayer,
|
2017-09-08 15:48:54 +03:00
|
|
|
QgsProcessingParameterBoolean,
|
2018-03-01 10:37:55 +02:00
|
|
|
QgsProcessingParameterFileDestination)
|
2016-01-22 15:45:09 +02:00
|
|
|
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
|
2017-09-08 15:48:54 +03:00
|
|
|
from processing.algs.gdal.GdalUtils import GdalUtils
|
2012-11-10 00:31:01 +01:00
|
|
|
|
2016-01-22 15:45:09 +02:00
|
|
|
|
2017-09-08 15:48:54 +03:00
|
|
|
class ogrinfo(GdalAlgorithm):
|
2012-11-10 00:31:01 +01:00
|
|
|
|
2014-07-08 20:08:31 +03:00
|
|
|
INPUT = 'INPUT'
|
2015-10-08 23:01:21 +11:00
|
|
|
SUMMARY_ONLY = 'SUMMARY_ONLY'
|
2017-09-08 15:48:54 +03:00
|
|
|
NO_METADATA = 'NO_METADATA'
|
2013-10-01 20:52:22 +03:00
|
|
|
OUTPUT = 'OUTPUT'
|
2012-11-10 00:31:01 +01:00
|
|
|
|
2017-05-15 13:40:38 +10:00
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
2017-06-27 17:20:57 +10:00
|
|
|
|
|
|
|
def initAlgorithm(self, config=None):
|
2018-01-16 18:15:53 +07:00
|
|
|
self.addParameter(QgsProcessingParameterVectorLayer(self.INPUT,
|
|
|
|
self.tr('Input layer')))
|
2017-09-08 15:48:54 +03:00
|
|
|
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)')))
|
2017-05-15 13:40:38 +10:00
|
|
|
|
2017-03-29 12:51:59 +10:00
|
|
|
def name(self):
|
2017-03-29 17:09:39 +10:00
|
|
|
return 'ogrinfo'
|
2017-03-29 12:51:59 +10:00
|
|
|
|
|
|
|
def displayName(self):
|
2017-09-08 15:48:54 +03:00
|
|
|
return self.tr('Vector information')
|
2017-03-29 12:51:59 +10:00
|
|
|
|
2017-03-29 12:04:09 +10:00
|
|
|
def group(self):
|
|
|
|
return self.tr('Vector miscellaneous')
|
|
|
|
|
2017-12-20 12:07:32 +01:00
|
|
|
def groupId(self):
|
2017-12-14 12:05:40 +02:00
|
|
|
return 'vectormiscellaneous'
|
|
|
|
|
2018-05-05 19:18:41 +10:00
|
|
|
def commandName(self):
|
|
|
|
return 'ogrinfo'
|
|
|
|
|
2017-12-08 13:51:30 +10:00
|
|
|
def getConsoleCommands(self, parameters, context, feedback, executing=True):
|
2018-08-21 13:14:01 +10:00
|
|
|
arguments = ['-al']
|
2017-09-08 15:48:54 +03:00
|
|
|
|
2019-04-16 08:30:00 +02:00
|
|
|
if self.parameterAsBoolean(parameters, self.SUMMARY_ONLY, context):
|
2015-10-08 23:01:21 +11:00
|
|
|
arguments.append('-so')
|
2019-04-16 08:30:00 +02:00
|
|
|
if self.parameterAsBoolean(parameters, self.NO_METADATA, context):
|
2017-09-08 15:48:54 +03:00
|
|
|
arguments.append('-nomd')
|
|
|
|
|
|
|
|
inLayer = self.parameterAsVectorLayer(parameters, self.INPUT, context)
|
2018-05-06 10:29:01 +10:00
|
|
|
if inLayer is None:
|
|
|
|
raise QgsProcessingException(self.invalidSourceError(parameters, self.INPUT))
|
|
|
|
|
2018-09-28 12:55:06 +10:00
|
|
|
connectionString = GdalUtils.ogrConnectionStringFromLayer(inLayer)
|
2017-09-08 15:48:54 +03:00
|
|
|
arguments.append(connectionString)
|
2018-08-21 13:14:01 +10:00
|
|
|
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
|
2015-05-07 13:14:01 +02:00
|
|
|
|
2017-05-15 16:19:46 +10:00
|
|
|
def processAlgorithm(self, parameters, context, feedback):
|
2017-09-08 15:48:54 +03:00
|
|
|
GdalUtils.runGdal(self.getConsoleCommands(parameters, context, feedback), feedback)
|
|
|
|
output = self.parameterAsFileOutput(parameters, self.OUTPUT, context)
|
2016-04-17 17:01:45 +02:00
|
|
|
with open(output, 'w') as f:
|
|
|
|
f.write('<pre>')
|
|
|
|
for s in GdalUtils.getConsoleOutput()[1:]:
|
2017-09-08 15:48:54 +03:00
|
|
|
f.write(str(s))
|
2016-04-17 17:01:45 +02:00
|
|
|
f.write('</pre>')
|
2017-09-08 15:48:54 +03:00
|
|
|
|
|
|
|
return {self.OUTPUT: output}
|