2013-10-13 16:19:20 +03:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
***************************************************************************
|
|
|
|
GridNearest.py
|
|
|
|
---------------------
|
|
|
|
Date : October 2013
|
|
|
|
Copyright : (C) 2013 by Alexander Bruy
|
|
|
|
Email : alexander dot bruy 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__ = 'Alexander Bruy'
|
|
|
|
__date__ = 'October 2013'
|
|
|
|
__copyright__ = '(C) 2013, Alexander Bruy'
|
|
|
|
|
|
|
|
# This will get replaced with a git SHA1 when you do a git archive
|
|
|
|
|
|
|
|
__revision__ = '$Format:%H$'
|
|
|
|
|
|
|
|
|
fix python pep8 warnings and fix some revealed errors
pep8 --ignore=E111,E128,E201,E202,E203,E211,E221,E222,E225,E226,E227,E231,E241,E261,E265,E272,E302,E303,E501,E701 \
--exclude="ui_*.py,debian/*,python/ext-libs/*" \
.
2015-02-01 14:15:42 +01:00
|
|
|
import os
|
2013-10-13 16:19:20 +03:00
|
|
|
|
2014-06-02 00:35:49 +02:00
|
|
|
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
|
2014-07-14 14:19:09 +02:00
|
|
|
from processing.core.parameters import ParameterVector
|
|
|
|
from processing.core.parameters import ParameterTableField
|
|
|
|
from processing.core.parameters import ParameterNumber
|
2014-10-21 12:34:16 +01:00
|
|
|
from processing.core.parameters import ParameterSelection
|
2014-07-14 14:19:09 +02:00
|
|
|
from processing.core.outputs import OutputRaster
|
2014-04-17 01:41:25 +02:00
|
|
|
from processing.algs.gdal.GdalUtils import GdalUtils
|
2013-10-13 16:19:20 +03:00
|
|
|
|
|
|
|
|
2014-06-02 00:35:49 +02:00
|
|
|
class GridNearest(GdalAlgorithm):
|
2013-10-13 16:19:20 +03:00
|
|
|
|
|
|
|
INPUT = 'INPUT'
|
|
|
|
Z_FIELD = 'Z_FIELD'
|
|
|
|
RADIUS_1 = 'RADIUS_1'
|
|
|
|
RADIUS_2 = 'RADIUS_2'
|
|
|
|
ANGLE = 'ANGLE'
|
|
|
|
NODATA = 'NODATA'
|
|
|
|
OUTPUT = 'OUTPUT'
|
2014-10-21 12:34:16 +01:00
|
|
|
RTYPE = 'RTYPE'
|
2014-11-13 23:13:13 +01:00
|
|
|
|
2015-01-31 21:28:01 +00:00
|
|
|
TYPE = ['Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64']
|
2014-11-13 23:13:13 +01:00
|
|
|
|
2014-06-05 14:08:38 +02:00
|
|
|
def commandLineName(self):
|
|
|
|
return "gdalogr:gridnearestneighbor"
|
2014-06-13 09:03:15 +02:00
|
|
|
|
2013-10-13 16:19:20 +03:00
|
|
|
def defineCharacteristics(self):
|
2015-07-26 03:48:27 +02:00
|
|
|
self.name, self.i18n_name = self.trAlgorithm('Grid (Nearest neighbor)')
|
|
|
|
self.group, self.i18n_group = self.trAlgorithm('[GDAL] Analysis')
|
2015-01-13 10:49:08 +02:00
|
|
|
self.addParameter(ParameterVector(self.INPUT,
|
2015-08-22 14:29:41 +02:00
|
|
|
self.tr('Input layer'), [ParameterVector.VECTOR_TYPE_POINT]))
|
2015-01-13 10:49:08 +02:00
|
|
|
self.addParameter(ParameterTableField(self.Z_FIELD,
|
2015-08-22 14:29:41 +02:00
|
|
|
self.tr('Z field'), self.INPUT,
|
|
|
|
ParameterTableField.DATA_TYPE_NUMBER, True))
|
2015-01-13 10:49:08 +02:00
|
|
|
self.addParameter(ParameterNumber(self.RADIUS_1,
|
2015-08-22 14:29:41 +02:00
|
|
|
self.tr('Radius 1'), 0.0, 99999999.999999, 0.0))
|
2015-01-13 10:49:08 +02:00
|
|
|
self.addParameter(ParameterNumber(self.RADIUS_2,
|
2015-08-22 14:29:41 +02:00
|
|
|
self.tr('Radius 2'), 0.0, 99999999.999999, 0.0))
|
2015-01-13 10:49:08 +02:00
|
|
|
self.addParameter(ParameterNumber(self.ANGLE,
|
2015-08-22 14:29:41 +02:00
|
|
|
self.tr('Angle'), 0.0, 359.0, 0.0))
|
2015-01-13 10:49:08 +02:00
|
|
|
self.addParameter(ParameterNumber(self.NODATA,
|
2015-08-22 14:29:41 +02:00
|
|
|
self.tr('Nodata'), 0.0, 99999999.999999, 0.0))
|
2015-01-13 10:49:08 +02:00
|
|
|
self.addParameter(ParameterSelection(self.RTYPE,
|
2015-08-22 14:29:41 +02:00
|
|
|
self.tr('Output raster type'), self.TYPE, 5))
|
2015-01-13 10:49:08 +02:00
|
|
|
|
2015-04-10 09:44:20 +02:00
|
|
|
self.addOutput(OutputRaster(self.OUTPUT, self.tr('Interpolated nearest neighbor')))
|
2013-10-13 16:19:20 +03:00
|
|
|
|
2015-05-07 13:14:01 +02:00
|
|
|
def getConsoleCommands(self):
|
2013-10-13 16:19:20 +03:00
|
|
|
arguments = ['-l']
|
|
|
|
arguments.append(
|
fix python pep8 warnings and fix some revealed errors
pep8 --ignore=E111,E128,E201,E202,E203,E211,E221,E222,E225,E226,E227,E231,E241,E261,E265,E272,E302,E303,E501,E701 \
--exclude="ui_*.py,debian/*,python/ext-libs/*" \
.
2015-02-01 14:15:42 +01:00
|
|
|
os.path.basename(os.path.splitext(
|
|
|
|
unicode(self.getParameterValue(self.INPUT)))[0]))
|
2013-10-13 16:19:20 +03:00
|
|
|
|
|
|
|
fieldName = self.getParameterValue(self.Z_FIELD)
|
|
|
|
if fieldName is not None and fieldName != '':
|
|
|
|
arguments.append('-zfield')
|
|
|
|
arguments.append(fieldName)
|
|
|
|
|
|
|
|
params = 'nearest'
|
|
|
|
params += ':radius1=%s' % self.getParameterValue(self.RADIUS_1)
|
|
|
|
params += ':radius2=%s' % self.getParameterValue(self.RADIUS_2)
|
|
|
|
params += ':angle=%s' % self.getParameterValue(self.ANGLE)
|
|
|
|
params += ':nodata=%s' % self.getParameterValue(self.NODATA)
|
|
|
|
|
|
|
|
arguments.append('-a')
|
|
|
|
arguments.append(params)
|
2014-10-21 12:34:16 +01:00
|
|
|
arguments.append('-ot')
|
2014-10-21 12:38:44 +01:00
|
|
|
arguments.append(self.TYPE[self.getParameterValue(self.RTYPE)])
|
2013-10-13 16:19:20 +03:00
|
|
|
arguments.append(unicode(self.getParameterValue(self.INPUT)))
|
|
|
|
arguments.append(unicode(self.getOutputValue(self.OUTPUT)))
|
|
|
|
|
2015-05-07 13:14:01 +02:00
|
|
|
return ['gdal_grid', GdalUtils.escapeAndJoin(arguments)]
|