Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #3891 from alexbruy/processing-interpolation
[processing] add remaining functionalify from the interpolation plugin
  • Loading branch information
alexbruy committed Dec 22, 2016
2 parents 835abb9 + ea4f05d commit ffd67f1
Show file tree
Hide file tree
Showing 29 changed files with 499 additions and 2,255 deletions.
1 change: 0 additions & 1 deletion debian/qgis.install
@@ -1,6 +1,5 @@
usr/lib/qgis/plugins/libgeorefplugin.so
usr/lib/qgis/plugins/libgpsimporterplugin.so
usr/lib/qgis/plugins/libinterpolationplugin.so
usr/lib/qgis/plugins/libcoordinatecaptureplugin.so
usr/lib/qgis/plugins/liboracleplugin.so
usr/lib/qgis/plugins/libevis.so
Expand Down
1 change: 0 additions & 1 deletion ms-windows/osgeo4w/package.cmd
Expand Up @@ -385,7 +385,6 @@ tar -C %OSGEO4W_ROOT% -cjf %ARCH%/release/qgis/%PACKAGENAME%/%PACKAGENAME%-%VERS
"apps/%PACKAGENAME%/plugins/evis.dll" ^
"apps/%PACKAGENAME%/plugins/georefplugin.dll" ^
"apps/%PACKAGENAME%/plugins/gpsimporterplugin.dll" ^
"apps/%PACKAGENAME%/plugins/interpolationplugin.dll" ^
"apps/%PACKAGENAME%/plugins/offlineeditingplugin.dll" ^
"apps/%PACKAGENAME%/plugins/oracleplugin.dll" ^
"apps/%PACKAGENAME%/plugins/spatialqueryplugin.dll" ^
Expand Down
1 change: 0 additions & 1 deletion ms-windows/plugins.nsh
Expand Up @@ -14,7 +14,6 @@ WriteRegStr HKEY_CURRENT_USER "Software\QGIS\QGIS3\Plugins" "georefplugin" "true
WriteRegStr HKEY_CURRENT_USER "Software\QGIS\QGIS3\Plugins" "globeplugin" "false"
WriteRegStr HKEY_CURRENT_USER "Software\QGIS\QGIS3\Plugins" "gpsimporterplugin" "true"
WriteRegStr HKEY_CURRENT_USER "Software\QGIS\QGIS3\Plugins" "grassplugin" "true"
WriteRegStr HKEY_CURRENT_USER "Software\QGIS\QGIS3\Plugins" "interpolationplugin" "true"
WriteRegStr HKEY_CURRENT_USER "Software\QGIS\QGIS3\Plugins" "offlineeditingplugin" "true"
WriteRegStr HKEY_CURRENT_USER "Software\QGIS\QGIS3\Plugins" "oracleplugin" "true"
WriteRegStr HKEY_CURRENT_USER "Software\QGIS\QGIS3\Plugins" "spatialqueryplugin" "true"
Expand Down
Expand Up @@ -2,7 +2,7 @@

"""
***************************************************************************
IdwInterpolationZValue.py
IdwInterpolation.py
---------------------
Date : October 2016
Copyright : (C) 2016 by Alexander Bruy
Expand All @@ -29,28 +29,28 @@

from qgis.PyQt.QtGui import QIcon

from qgis.core import QgsRectangle, QgsWkbTypes
from qgis.core import QgsRectangle
from qgis.analysis import (QgsInterpolator,
QgsIDWInterpolator,
QgsGridFileWriter
)
)

from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from processing.core.parameters import ParameterVector
from processing.core.parameters import ParameterSelection
from processing.core.parameters import ParameterNumber
from processing.core.parameters import ParameterExtent
from processing.core.parameters import (Parameter,
ParameterNumber,
ParameterExtent,
_splitParameterOptions
)
from processing.core.outputs import OutputRaster
from processing.tools import dataobjects

pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0]


class IdwInterpolationZValue(GeoAlgorithm):
class IdwInterpolation(GeoAlgorithm):

INPUT_LAYER = 'INPUT_LAYER'
LAYER_TYPE = 'LAYER_TYPE'
INTERPOLATION_DATA = 'INTERPOLATION_DATA'
DISTANCE_COEFFICIENT = 'DISTANCE_COEFFICIENT'
COLUMNS = 'COLUMNS'
ROWS = 'ROWS'
Expand All @@ -63,20 +63,61 @@ def getIcon(self):
return QIcon(os.path.join(pluginPath, 'images', 'interpolation.png'))

def defineCharacteristics(self):
self.name, self.i18n_name = self.trAlgorithm('IDW interpolation (using Z-values)')
self.name, self.i18n_name = self.trAlgorithm('IDW interpolation')
self.group, self.i18n_group = self.trAlgorithm('Interpolation')

self.TYPES = [self.tr('Points'),
self.tr('Structure lines'),
self.tr('Break lines')
]

self.addParameter(ParameterVector(self.INPUT_LAYER,
self.tr('Vector layer')))
self.addParameter(ParameterSelection(self.LAYER_TYPE,
self.tr('Type'),
self.TYPES,
0))
class ParameterInterpolationData(Parameter):
default_metadata = {
'widget_wrapper': 'processing.algs.qgis.ui.InterpolationDataWidget.InterpolationDataWidgetWrapper'
}

def __init__(self, name='', description=''):
Parameter.__init__(self, name, description)

def setValue(self, value):
if value is None:
if not self.optional:
return False
self.value = None
return True

if value == '':
if not self.optional:
return False

if isinstance(value, str):
self.value = value if value != '' else None
else:
self.value = ParameterInterpolationData.dataToString(value)
return True

def getValueAsCommandLineParameter(self):
return '"{}"'.format(self.value)

def getAsScriptCode(self):
param_type = ''
param_type += 'interpolation data '
return '##' + self.name + '=' + param_type

@classmethod
def fromScriptCode(self, line):
isOptional, name, definition = _splitParameterOptions(line)
descName = _createDescriptiveName(name)
parent = definition.lower().strip()[len('interpolation data') + 1:]
return ParameterInterpolationData(name, description, parent)

@staticmethod
def dataToString(data):
s = ''
for d in data:
s += '{}, {}, {:d}, {:d};'.format(c[0],
c[1],
c[2],
c[3])
return s[:-1]

self.addParameter(ParameterInterpolationData(self.INTERPOLATION_DATA,
self.tr('Input layer(s)')))
self.addParameter(ParameterNumber(self.DISTANCE_COEFFICIENT,
self.tr('Distance coefficient P'),
0.0, 99.99, 2.0))
Expand All @@ -98,9 +139,7 @@ def defineCharacteristics(self):
self.tr('Interpolated')))

def processAlgorithm(self, progress):
layer = dataobjects.getObjectFromUri(
self.getParameterValue(self.INPUT_LAYER))
layerType = self.getParameterValue(self.LAYER_TYPE)
interpolationData = self.getParameterValue(self.INTERPOLATION_DATA)
coefficient = self.getParameterValue(self.DISTANCE_COEFFICIENT)
columns = self.getParameterValue(self.COLUMNS)
rows = self.getParameterValue(self.ROWS)
Expand All @@ -109,29 +148,32 @@ def processAlgorithm(self, progress):
extent = self.getParameterValue(self.EXTENT).split(',')
output = self.getOutputValue(self.OUTPUT_LAYER)

if not QgsWkbTypes.hasZ(layer.wkbType()):
if interpolationData is None:
raise GeoAlgorithmExecutionException(
self.tr('Geometries in input layer does not have Z coordinates.'))
self.tr('You need to specify at least one input layer.'))

xMin = float(extent[0])
xMax = float(extent[1])
yMin = float(extent[2])
yMax = float(extent[3])
bbox = QgsRectangle(xMin, yMin, xMax, yMax)

layerData = QgsInterpolator.LayerData()
layerData.vectorLayer = layer
layerData.zCoordInterpolation = True
layerData.interpolationAttribute = -1

if layerType == 0:
layerData.mInputType = QgsInterpolator.POINTS
elif layerType == 1:
layerData.mInputType = QgsInterpolator.STRUCTURE_LINES
else:
layerData.mInputType = QgsInterpolator.BREAK_LINES

interpolator = QgsIDWInterpolator([layerData])
layerData = []
for row in interpolationData.split(';'):
v = row.split(',')
data = QgsInterpolator.LayerData()
data.vectorLayer = dataobjects.getObjectFromUri(v[0])
data.zCoordInterpolation = bool(v[1])
data.interpolationAttribute = int(v[2])
if v[3] == '0':
data.mInputType = QgsInterpolator.POINTS
elif v[3] == '1':
data.mInputType = QgsInterpolator.STRUCTURE_LINES
else:
data.mInputType = QgsInterpolator.BREAK_LINES
layerData.append(data)

interpolator = QgsIDWInterpolator(layerData)
interpolator.setDistanceCoefficient(coefficient)

writer = QgsGridFileWriter(interpolator,
Expand Down
147 changes: 0 additions & 147 deletions python/plugins/processing/algs/qgis/IdwInterpolationAttribute.py

This file was deleted.

9 changes: 3 additions & 6 deletions python/plugins/processing/algs/qgis/QGISAlgorithmProvider.py
Expand Up @@ -167,10 +167,8 @@
from .Ruggedness import Ruggedness
from .Hillshade import Hillshade
from .Relief import Relief
from .IdwInterpolationZValue import IdwInterpolationZValue
from .IdwInterpolationAttribute import IdwInterpolationAttribute
from .TinInterpolationZValue import TinInterpolationZValue
from .TinInterpolationAttribute import TinInterpolationAttribute
from .IdwInterpolation import IdwInterpolation
from .TinInterpolation import TinInterpolation
from .ZonalStatisticsQgis import ZonalStatisticsQgis
from .RemoveNullGeometry import RemoveNullGeometry
from .ExtendLines import ExtendLines
Expand Down Expand Up @@ -248,8 +246,7 @@ def __init__(self):
SingleSidedBuffer(), PointsAlongGeometry(),
Aspect(), Slope(), Ruggedness(), Hillshade(),
Relief(), ZonalStatisticsQgis(),
IdwInterpolationZValue(), IdwInterpolationAttribute(),
TinInterpolationZValue(), TinInterpolationAttribute(),
IdwInterpolation(), TinInterpolation(),
RemoveNullGeometry(), ExtractByExpression(),
ExtendLines(), ExtractSpecificNodes(),
GeometryByExpression(), SnapGeometriesToLayer(),
Expand Down

0 comments on commit ffd67f1

Please sign in to comment.