Skip to content
Permalink
Browse files

[processing] Make set m value accept dynamic m values

  • Loading branch information
nyalldawson committed Dec 2, 2017
1 parent c5f6535 commit 8c9147eabd42e95ec62da66d095200e107629e26
Showing with 17 additions and 3 deletions.
  1. +17 −3 python/plugins/processing/algs/qgis/SetMValue.py
@@ -29,6 +29,8 @@

from qgis.core import (QgsGeometry,
QgsWkbTypes,
QgsPropertyDefinition,
QgsProcessingParameters,
QgsProcessingParameterNumber)


@@ -47,6 +49,8 @@ def group(self):
def __init__(self):
super().__init__()
self.m_value = 0
self.dynamic_m = False
self.m_property = None

def name(self):
return 'setmvalue'
@@ -61,14 +65,21 @@ def tags(self):
return self.tr('set,add,m,measure,values').split(',')

def initParameters(self, config=None):
self.addParameter(QgsProcessingParameterNumber(self.M_VALUE,
self.tr('M Value'), QgsProcessingParameterNumber.Double, defaultValue=0.0))
m_param = QgsProcessingParameterNumber(self.M_VALUE,
self.tr('M Value'), QgsProcessingParameterNumber.Double, defaultValue=0.0)
m_param.setIsDynamic(True)
m_param.setDynamicLayerParameterName('INPUT')
m_param.setDynamicPropertyDefinition(QgsPropertyDefinition(self.M_VALUE, self.tr("M Value"), QgsPropertyDefinition.Double))
self.addParameter(m_param)

def outputWkbType(self, inputWkb):
return QgsWkbTypes.addM(inputWkb)

def prepareAlgorithm(self, parameters, context, feedback):
self.m_value = self.parameterAsDouble(parameters, self.M_VALUE, context)
self.dynamic_m = QgsProcessingParameters.isDynamic(parameters, self.M_VALUE)
if self.dynamic_m:
self.m_property = parameters[self.M_VALUE]
return True

def processFeature(self, feature, context, feedback):
@@ -79,7 +90,10 @@ def processFeature(self, feature, context, feedback):
# addMValue won't alter existing M values, so drop them first
new_geom.dropMValue()

new_geom.addMValue(self.m_value)
m = self.m_value
if self.dynamic_m:
m, ok = self.m_property.valueAsDouble(context.expressionContext(), m)
new_geom.addMValue(m)

feature.setGeometry(QgsGeometry(new_geom))

0 comments on commit 8c9147e

Please sign in to comment.
You can’t perform that action at this time.