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
|
|
|
|
2016-12-29 16:39:55 +02:00
|
|
|
def commandLineName(self):
|
|
|
|
return "gdal:ogrinfo"
|
|
|
|
|
2012-11-10 00:31:01 +01:00
|
|
|
def defineCharacteristics(self):
|
2015-07-26 03:48:27 +02:00
|
|
|
self.name, self.i18n_name = self.trAlgorithm('Information')
|
2017-02-28 12:37:48 +02:00
|
|
|
self.group, self.i18n_group = self.trAlgorithm('Vector miscellaneous')
|
2012-11-10 00:31:01 +01:00
|
|
|
|
2016-08-23 19:33:42 +03:00
|
|
|
self.addParameter(ParameterVector(self.INPUT, self.tr('Input layer')))
|
2015-10-08 23:01:21 +11:00
|
|
|
self.addParameter(ParameterBoolean(self.SUMMARY_ONLY,
|
|
|
|
self.tr('Summary output only'),
|
|
|
|
True))
|
2012-11-10 00:31:01 +01:00
|
|
|
|
2015-01-13 10:49:08 +02:00
|
|
|
self.addOutput(OutputHTML(self.OUTPUT, self.tr('Layer information')))
|
2013-10-24 15:26:39 +02:00
|
|
|
|
2015-05-07 13:14:01 +02:00
|
|
|
def getConsoleCommands(self):
|
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-01-06 20:04:00 +10:00
|
|
|
def processAlgorithm(self, feedback):
|
|
|
|
GdalUtils.runGdal(self.getConsoleCommands(), 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>')
|