|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | + |
| 3 | +""" |
| 4 | +*************************************************************************** |
| 5 | + GridNearest.py |
| 6 | + --------------------- |
| 7 | + Date : October 2013 |
| 8 | + Copyright : (C) 2013 by Alexander Bruy |
| 9 | + Email : alexander dot bruy at gmail dot com |
| 10 | +*************************************************************************** |
| 11 | +* * |
| 12 | +* This program is free software; you can redistribute it and/or modify * |
| 13 | +* it under the terms of the GNU General Public License as published by * |
| 14 | +* the Free Software Foundation; either version 2 of the License, or * |
| 15 | +* (at your option) any later version. * |
| 16 | +* * |
| 17 | +*************************************************************************** |
| 18 | +""" |
| 19 | + |
| 20 | +__author__ = 'Alexander Bruy' |
| 21 | +__date__ = 'October 2013' |
| 22 | +__copyright__ = '(C) 2013, Alexander Bruy' |
| 23 | + |
| 24 | +# This will get replaced with a git SHA1 when you do a git archive |
| 25 | + |
| 26 | +__revision__ = '$Format:%H$' |
| 27 | + |
| 28 | + |
| 29 | +from PyQt4.QtGui import * |
| 30 | + |
| 31 | +from processing.core.GeoAlgorithm import GeoAlgorithm |
| 32 | +from processing.parameters.ParameterVector import ParameterVector |
| 33 | +from processing.parameters.ParameterTableField import ParameterTableField |
| 34 | +from processing.parameters.ParameterNumber import ParameterNumber |
| 35 | +from processing.outputs.OutputRaster import OutputRaster |
| 36 | +from processing.gdal.GdalUtils import GdalUtils |
| 37 | +from processing.tools.system import * |
| 38 | + |
| 39 | + |
| 40 | +class GridNearest(GeoAlgorithm): |
| 41 | + |
| 42 | + INPUT = 'INPUT' |
| 43 | + Z_FIELD = 'Z_FIELD' |
| 44 | + RADIUS_1 = 'RADIUS_1' |
| 45 | + RADIUS_2 = 'RADIUS_2' |
| 46 | + ANGLE = 'ANGLE' |
| 47 | + NODATA = 'NODATA' |
| 48 | + OUTPUT = 'OUTPUT' |
| 49 | + |
| 50 | + #def getIcon(self): |
| 51 | + # filepath = os.path.dirname(__file__) + '/icons/dem.png' |
| 52 | + # return QIcon(filepath) |
| 53 | + |
| 54 | + def defineCharacteristics(self): |
| 55 | + self.name = 'Grid (Nearest neighbor)' |
| 56 | + self.group = '[GDAL] Analysis' |
| 57 | + self.addParameter(ParameterVector(self.INPUT, 'Input layer', |
| 58 | + [ParameterVector.VECTOR_TYPE_POINT])) |
| 59 | + self.addParameter(ParameterTableField(self.Z_FIELD, 'Z field', |
| 60 | + self.INPUT, ParameterTableField.DATA_TYPE_NUMBER, |
| 61 | + True)) |
| 62 | + self.addParameter(ParameterNumber(self.RADIUS_1, 'Radius 1', |
| 63 | + 0.0, 99999999.999999, 0.0)) |
| 64 | + self.addParameter(ParameterNumber(self.RADIUS_2, 'Radius 2', |
| 65 | + 0.0, 99999999.999999, 0.0)) |
| 66 | + self.addParameter(ParameterNumber(self.ANGLE, 'Angle', |
| 67 | + 0.0, 359.0, 0.0)) |
| 68 | + self.addParameter(ParameterNumber(self.NODATA, 'Nodata', |
| 69 | + 0.0, 99999999.999999, 0.0)) |
| 70 | + |
| 71 | + self.addOutput(OutputRaster(self.OUTPUT, 'Output file')) |
| 72 | + |
| 73 | + def processAlgorithm(self, progress): |
| 74 | + arguments = ['-l'] |
| 75 | + arguments.append( |
| 76 | + os.path.basename(os.path.splitext( |
| 77 | + unicode(self.getParameterValue(self.INPUT)))[0])) |
| 78 | + |
| 79 | + fieldName = self.getParameterValue(self.Z_FIELD) |
| 80 | + if fieldName is not None and fieldName != '': |
| 81 | + arguments.append('-zfield') |
| 82 | + arguments.append(fieldName) |
| 83 | + |
| 84 | + params = 'nearest' |
| 85 | + params += ':radius1=%s' % self.getParameterValue(self.RADIUS_1) |
| 86 | + params += ':radius2=%s' % self.getParameterValue(self.RADIUS_2) |
| 87 | + params += ':angle=%s' % self.getParameterValue(self.ANGLE) |
| 88 | + params += ':nodata=%s' % self.getParameterValue(self.NODATA) |
| 89 | + |
| 90 | + arguments.append('-a') |
| 91 | + arguments.append(params) |
| 92 | + |
| 93 | + arguments.append(unicode(self.getParameterValue(self.INPUT))) |
| 94 | + arguments.append(unicode(self.getOutputValue(self.OUTPUT))) |
| 95 | + |
| 96 | + GdalUtils.runGdal(['gdal_grid', |
| 97 | + GdalUtils.escapeAndJoin(arguments)], progress) |
0 commit comments