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
|
|
|
|
2012-12-02 00:03:21 +01:00
|
|
|
# This will get replaced with a git SHA1 when you do a git archive
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2012-12-02 00:03:21 +01:00
|
|
|
__revision__ = '$Format:%H$'
|
|
|
|
|
2013-01-26 14:16:39 +01:00
|
|
|
|
2014-07-14 14:19:09 +02:00
|
|
|
from processing.core.parameters import ParameterVector
|
2015-10-08 23:01:21 +11:00
|
|
|
from processing.core.parameters import ParameterBoolean
|
|
|
|
|
2014-07-14 14:19:09 +02:00
|
|
|
from processing.core.outputs import OutputHTML
|
2014-07-08 20:08:31 +03:00
|
|
|
|
|
|
|
from processing.algs.gdal.GdalUtils import GdalUtils
|
2016-01-22 15:45:09 +02:00
|
|
|
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
|
2012-11-10 00:31:01 +01:00
|
|
|
|
2016-01-22 15:45:09 +02:00
|
|
|
from processing.tools.vector import ogrConnectionString
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2016-01-22 15:45:09 +02: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'
|
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__()
|
|
|
|
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')))
|
|
|
|
|
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):
|
|
|
|
return self.tr('Information')
|
|
|
|
|
2017-03-29 12:04:09 +10:00
|
|
|
def group(self):
|
|
|
|
return self.tr('Vector miscellaneous')
|
|
|
|
|
2017-05-15 16:19:46 +10:00
|
|
|
def getConsoleCommands(self, parameters):
|
2015-06-12 17:58:51 -06:00
|
|
|
arguments = ["ogrinfo"]
|
2014-07-08 20:08:31 +03:00
|
|
|
arguments.append('-al')
|
2015-10-08 23:01:21 +11:00
|
|
|
if self.getParameterValue(self.SUMMARY_ONLY):
|
|
|
|
arguments.append('-so')
|
2014-07-08 20:08:31 +03:00
|
|
|
layer = self.getParameterValue(self.INPUT)
|
2016-01-22 15:45:09 +02:00
|
|
|
conn = ogrConnectionString(layer)
|
2014-07-08 20:08:31 +03:00
|
|
|
arguments.append(conn)
|
2015-05-07 13:14:01 +02:00
|
|
|
return arguments
|
|
|
|
|
2017-05-15 16:19:46 +10:00
|
|
|
def processAlgorithm(self, parameters, context, feedback):
|
|
|
|
GdalUtils.runGdal(self.getConsoleCommands(parameters), feedback)
|
2012-11-10 00:31:01 +01:00
|
|
|
output = self.getOutputValue(self.OUTPUT)
|
2016-04-17 17:01:45 +02:00
|
|
|
with open(output, 'w') as f:
|
|
|
|
f.write('<pre>')
|
|
|
|
for s in GdalUtils.getConsoleOutput()[1:]:
|
|
|
|
f.write(s)
|
|
|
|
f.write('</pre>')
|