From bf08b7b871ac51b9d7ea0e8b98e4ca2e959c1005 Mon Sep 17 00:00:00 2001 From: Giovanni Manghi Date: Tue, 24 Feb 2015 00:05:55 +0000 Subject: [PATCH] processing: add gdal tileindex --- .../algs/gdal/GdalOgrAlgorithmProvider.py | 3 +- .../processing/algs/gdal/gdaltindex.py | 70 +++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 python/plugins/processing/algs/gdal/gdaltindex.py diff --git a/python/plugins/processing/algs/gdal/GdalOgrAlgorithmProvider.py b/python/plugins/processing/algs/gdal/GdalOgrAlgorithmProvider.py index d1bb3932d148..a29b2c31c137 100644 --- a/python/plugins/processing/algs/gdal/GdalOgrAlgorithmProvider.py +++ b/python/plugins/processing/algs/gdal/GdalOgrAlgorithmProvider.py @@ -64,6 +64,7 @@ from GridAverage import GridAverage from GridNearest import GridNearest from GridDataMetrics import GridDataMetrics +from gdaltindex import gdaltindex from ogr2ogr import Ogr2Ogr from ogr2ogrclip import Ogr2OgrClip @@ -121,7 +122,7 @@ def createAlgsList(self): sieve(), fillnodata(), ExtractProjection(), gdal2xyz(), hillshade(), slope(), aspect(), tri(), tpi(), roughness(), ColorRelief(), GridInvDist(), GridAverage(), GridNearest(), - GridDataMetrics(), + GridDataMetrics(), gdaltindex(), # ----- OGR tools ----- OgrInfo(), Ogr2Ogr(), Ogr2OgrClip(), Ogr2OgrClipExtent(), Ogr2OgrToPostGis(), Ogr2OgrToPostGisList(), OgrSql(), diff --git a/python/plugins/processing/algs/gdal/gdaltindex.py b/python/plugins/processing/algs/gdal/gdaltindex.py new file mode 100644 index 000000000000..ef042d2465f2 --- /dev/null +++ b/python/plugins/processing/algs/gdal/gdaltindex.py @@ -0,0 +1,70 @@ +# -*- coding: utf-8 -*- + +""" +*************************************************************************** + gdaltindex.py + --------------------- + Date : February 2015 + Copyright : (C) 2015 by Pedro Venancio + Email : pedrongvenancio 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__ = 'Pedro Venancio' +__date__ = 'February 2015' +__copyright__ = '(C) 2015, Pedro Venancio' + +# This will get replaced with a git SHA1 when you do a git archive + +__revision__ = '$Format:%H$' + + +from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm +from processing.core.outputs import OutputVector +from processing.core.parameters import ParameterBoolean +from processing.core.parameters import ParameterMultipleInput +from processing.core.parameters import ParameterString +from processing.algs.gdal.GdalUtils import GdalUtils + +import os + +class gdaltindex(GdalAlgorithm): + + INPUT = 'INPUT' + OUTPUT = 'OUTPUT' + FIELD_NAME = 'FIELD_NAME' + PROJ_DIFFERENCE = 'PROJ_DIFFERENCE' + + def defineCharacteristics(self): + self.name = 'Tile Index' + self.group = '[GDAL] Miscellaneous' + self.addParameter(ParameterMultipleInput(self.INPUT, + self.tr('Input layers'), ParameterMultipleInput.TYPE_RASTER)) + self.addParameter(ParameterString(self.FIELD_NAME, + self.tr('Tile index field'), + 'location', optional=True)) + self.addParameter(ParameterBoolean(self.PROJ_DIFFERENCE, + self.tr('Skip files with different projection reference'), False)) + self.addOutput(OutputVector(gdaltindex.OUTPUT, self.tr('Output layer'))) + + def processAlgorithm(self, progress): + fieldName = str(self.getParameterValue(self.FIELD_NAME)) + + arguments = [] + if len(fieldName) > 0: + arguments.append('-tileindex') + arguments.append(fieldName) + if self.getParameterValue(gdaltindex.PROJ_DIFFERENCE): + arguments.append('-skip_different_projection') + arguments.append(unicode(self.getOutputValue(gdaltindex.OUTPUT))) + arguments.extend(unicode(self.getParameterValue(gdaltindex.INPUT)).split(';')) + + + GdalUtils.runGdal(['gdaltindex', GdalUtils.escapeAndJoin(arguments)], progress)