2013-09-15 17:47:27 +03:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
***************************************************************************
|
|
|
|
proximity.py
|
|
|
|
---------------------
|
|
|
|
Date : August 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__ = 'August 2012'
|
|
|
|
__copyright__ = '(C) 2012, Victor Olaya'
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2013-09-15 17:47:27 +03:00
|
|
|
# This will get replaced with a git SHA1 when you do a git archive
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2013-09-15 17:47:27 +03:00
|
|
|
__revision__ = '$Format:%H$'
|
|
|
|
|
2016-01-25 15:42:11 +02:00
|
|
|
import os
|
|
|
|
|
2016-04-22 10:38:48 +02:00
|
|
|
from qgis.PyQt.QtGui import QIcon
|
2016-01-25 15:42:11 +02: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 ParameterRaster
|
|
|
|
from processing.core.parameters import ParameterString
|
|
|
|
from processing.core.parameters import ParameterSelection
|
|
|
|
from processing.core.parameters import ParameterNumber
|
|
|
|
from processing.core.outputs import OutputRaster
|
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
|
|
|
from processing.tools.system import isWindows
|
2014-04-17 01:41:25 +02:00
|
|
|
from processing.algs.gdal.GdalUtils import GdalUtils
|
2013-09-15 17:47:27 +03:00
|
|
|
|
2016-01-25 15:42:11 +02:00
|
|
|
pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0]
|
|
|
|
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2014-06-02 00:35:49 +02:00
|
|
|
class proximity(GdalAlgorithm):
|
2013-09-15 17:47:27 +03:00
|
|
|
|
2013-10-01 20:52:22 +03:00
|
|
|
INPUT = 'INPUT'
|
|
|
|
VALUES = 'VALUES'
|
|
|
|
UNITS = 'UNITS'
|
|
|
|
MAX_DIST = 'MAX_DIST'
|
|
|
|
NODATA = 'NODATA'
|
|
|
|
BUF_VAL = 'BUF_VAL'
|
|
|
|
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']
|
2013-09-15 17:47:27 +03:00
|
|
|
|
2013-10-01 20:52:22 +03:00
|
|
|
DISTUNITS = ['GEO', 'PIXEL']
|
2013-09-15 17:47:27 +03:00
|
|
|
|
2016-01-25 15:42:11 +02:00
|
|
|
def getIcon(self):
|
|
|
|
return QIcon(os.path.join(pluginPath, 'images', 'gdaltools', 'proximity.png'))
|
|
|
|
|
2013-10-06 13:25:01 +02:00
|
|
|
def commandLineName(self):
|
|
|
|
return "gdalogr:proximity"
|
2013-09-15 17:47:27 +03:00
|
|
|
|
|
|
|
def defineCharacteristics(self):
|
2015-07-26 03:48:27 +02:00
|
|
|
self.name, self.i18n_name = self.trAlgorithm('Proximity (raster distance)')
|
|
|
|
self.group, self.i18n_group = self.trAlgorithm('[GDAL] Analysis')
|
2015-01-13 10:49:08 +02:00
|
|
|
self.addParameter(ParameterRaster(self.INPUT,
|
2015-08-22 14:29:41 +02:00
|
|
|
self.tr('Input layer'), False))
|
2015-01-13 10:49:08 +02:00
|
|
|
self.addParameter(ParameterString(self.VALUES,
|
2015-08-22 14:29:41 +02:00
|
|
|
self.tr('Values'), ''))
|
2015-01-13 10:49:08 +02:00
|
|
|
self.addParameter(ParameterSelection(self.UNITS,
|
2015-08-22 14:29:41 +02:00
|
|
|
self.tr('Distance units'), self.DISTUNITS, 0))
|
2013-10-01 20:52:22 +03:00
|
|
|
self.addParameter(ParameterNumber(self.MAX_DIST,
|
2015-08-22 14:29:41 +02:00
|
|
|
self.tr('Max distance (negative value to ignore)'), -1, 9999, -1))
|
2013-10-01 20:52:22 +03:00
|
|
|
self.addParameter(ParameterNumber(self.NODATA,
|
2015-08-22 14:29:41 +02:00
|
|
|
self.tr('Nodata (negative value to ignore)'), -1, 9999, -1))
|
2013-10-01 20:52:22 +03:00
|
|
|
self.addParameter(ParameterNumber(self.BUF_VAL,
|
2015-08-22 14:29:41 +02:00
|
|
|
self.tr('Fixed buf value (negative value to ignore)'),
|
|
|
|
-1, 9999, -1))
|
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-04-10 09:44:20 +02:00
|
|
|
self.addOutput(OutputRaster(self.OUTPUT, self.tr('Distance')))
|
2013-09-15 17:47:27 +03:00
|
|
|
|
2015-05-07 13:14:01 +02:00
|
|
|
def getConsoleCommands(self):
|
2013-09-15 17:47:27 +03:00
|
|
|
output = self.getOutputValue(self.OUTPUT)
|
|
|
|
|
|
|
|
arguments = []
|
2014-10-21 12:34:16 +01:00
|
|
|
arguments.append('-ot')
|
2014-11-13 23:13:13 +01:00
|
|
|
arguments.append(self.TYPE[self.getParameterValue(self.RTYPE)])
|
2013-09-15 17:47:27 +03:00
|
|
|
arguments.append(self.getParameterValue(self.INPUT))
|
|
|
|
arguments.append(output)
|
|
|
|
|
2013-10-01 20:52:22 +03:00
|
|
|
arguments.append('-of')
|
2013-09-15 17:47:27 +03:00
|
|
|
arguments.append(GdalUtils.getFormatShortNameFromFilename(output))
|
|
|
|
|
2013-10-01 20:52:22 +03:00
|
|
|
arguments.append('-distunits')
|
2013-09-15 17:47:27 +03:00
|
|
|
arguments.append(self.DISTUNITS[self.getParameterValue(self.UNITS)])
|
|
|
|
|
|
|
|
values = self.getParameterValue(self.VALUES)
|
|
|
|
if len(values) > 0:
|
2013-10-01 20:52:22 +03:00
|
|
|
arguments.append('-values')
|
2013-09-15 17:47:27 +03:00
|
|
|
arguments.append(values)
|
|
|
|
|
2015-08-16 20:57:24 +02:00
|
|
|
values = unicode(self.getParameterValue(self.MAX_DIST))
|
2013-09-15 17:47:27 +03:00
|
|
|
if values < 0:
|
2013-10-01 20:52:22 +03:00
|
|
|
arguments.append('-maxdist')
|
2013-09-15 17:47:27 +03:00
|
|
|
arguments.append(values)
|
|
|
|
|
2015-08-16 20:57:24 +02:00
|
|
|
values = unicode(self.getParameterValue(self.NODATA))
|
2013-09-15 17:47:27 +03:00
|
|
|
if values < 0:
|
2013-10-01 20:52:22 +03:00
|
|
|
arguments.append('-nodata')
|
2013-09-15 17:47:27 +03:00
|
|
|
arguments.append(values)
|
|
|
|
|
2015-08-16 20:57:24 +02:00
|
|
|
values = unicode(self.getParameterValue(self.BUF_VAL))
|
2013-09-15 17:47:27 +03:00
|
|
|
if values < 0:
|
2013-10-01 20:52:22 +03:00
|
|
|
arguments.append('-fixed-buf-val')
|
2013-09-15 17:47:27 +03:00
|
|
|
arguments.append(values)
|
|
|
|
|
|
|
|
commands = []
|
|
|
|
if isWindows():
|
2013-10-01 20:52:22 +03:00
|
|
|
commands = ['cmd.exe', '/C ', 'gdal_proximity.bat',
|
|
|
|
GdalUtils.escapeAndJoin(arguments)]
|
2013-09-15 17:47:27 +03:00
|
|
|
else:
|
2013-10-01 20:52:22 +03:00
|
|
|
commands = ['gdal_proximity.py',
|
|
|
|
GdalUtils.escapeAndJoin(arguments)]
|
2013-09-15 17:47:27 +03:00
|
|
|
|
2015-05-07 13:14:01 +02:00
|
|
|
return commands
|