# -*- 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 sextante.outputs.OutputHTML import OutputHTML from sextante.parameters.ParameterVector import ParameterVector from qgis.core import * from PyQt4.QtCore import * from PyQt4.QtGui import * import string import re import ogr from sextante.gdal.OgrAlgorithm import OgrAlgorithm class OgrInfo(OgrAlgorithm): #constants used to refer to parameters and outputs. #They will be used when calling the algorithm from another algorithm, #or when calling SEXTANTE from the QGIS console. OUTPUT = "OUTPUT" INPUT_LAYER = "INPUT_LAYER" def defineCharacteristics(self): self.name = "ogrinfo" 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 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 = '' 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)) == "