# -*- 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$' import string import re try: from osgeo import ogr ogrAvailable = True except: ogrAvailable = False from PyQt4.QtCore import * from PyQt4.QtGui import * from qgis.core import * from processing.parameters.ParameterVector import ParameterVector from processing.outputs.OutputHTML import OutputHTML from processing.gdal.OgrAlgorithm import OgrAlgorithm class OgrInfo(OgrAlgorithm): OUTPUT = 'OUTPUT' INPUT_LAYER = 'INPUT_LAYER' def defineCharacteristics(self): self.name = 'Information' self.group = '[OGR] Miscellaneous' self.addParameter(ParameterVector(self.INPUT_LAYER, 'Input layer', [ParameterVector.VECTOR_TYPE_ANY], False)) self.addOutput(OutputHTML(self.OUTPUT, 'Layer information')) def commandLineName(self): return "gdalogr:vectorinfo" def processAlgorithm(self, progress): input = self.getParameterValue(self.INPUT_LAYER) ogrLayer = self.ogrConnectionString(input) output = self.getOutputValue(self.OUTPUT) self.ogrinfo(ogrLayer) f = open(output, 'w') f.write('
' + self.info + '') f.close() def out(self, text): self.info = self.info + text + '\n' def ogrinfo(self, pszDataSource): bVerbose = True bSummaryOnly = True self.info = '' if not ogrAvailable: self.info = 'OGR bindings not installed' return qDebug("Opening data source '%s'" % pszDataSource) poDS = ogr.Open(pszDataSource, False) if poDS is None: self.info = self.failure(pszDataSource) return poDriver = poDS.GetDriver() if bVerbose: self.out("INFO: Open of `%s'\n using driver `%s' successful." % (pszDataSource, poDriver.GetName())) poDS_Name = poDS.GetName() if str(type(pszDataSource)) == "