Skip to content

Commit

Permalink
Add search radius parameter to IDW interpolation (#292)
Browse files Browse the repository at this point in the history
* feat(IDW): Add search radius parameter
  • Loading branch information
msorvoja authored Dec 5, 2024
1 parent b5bb7c0 commit e9fc720
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def initAlgorithm(self, config=None):
"pixel_size",
"extent",
"power",
"search_radius",
"output_raster",
]

Expand Down Expand Up @@ -80,8 +81,16 @@ def initAlgorithm(self, config=None):
As power increases, the weights for distant points decrease rapidly.")
self.addParameter(power_param)

search_radius_param = QgsProcessingParameterNumber(
name=self.alg_parameters[6], description="Search radius", minValue=0.0, optional=True
)
search_radius_param.setHelp(
"The search radius within which to consider points for interpolation. If left empty, all points are used."
)
self.addParameter(search_radius_param)

output_raster_param = QgsProcessingParameterRasterDestination(
name=self.alg_parameters[6], description="Output raster"
name=self.alg_parameters[7], description="Output raster"
)
output_raster_param.setHelp("Output interpolation raster.")
self.addParameter(output_raster_param)
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def __init__(self,
self.interpolation_method: QComboBox
self.interpolation_method_pages: QComboBox
self.power: QgsDoubleSpinBox
self.search_radius: QgsDoubleSpinBox
self.kriging_method: QComboBox
self.variogram_model: QComboBox
self.coordinates_type: QComboBox
Expand All @@ -68,15 +69,16 @@ def initialize(self):
self.vector_layer.layerChanged.connect(self.attribute.setLayer)
self.interpolation_method.currentIndexChanged.connect(self.on_interpolation_method_changed)
self.attribute.setLayer(self.vector_layer.currentLayer())
self.interpolation_method_pages.setMaximumHeight(50) # IDW is the default
self.search_radius.setMaximum(99999)

super().initialize(self.process_type)


def get_interpolation_alg_and_parameters(self):
if self.interpolation_method.currentIndex() == 0: # IDW
params = {
"power": self.power.value()
"power": self.power.value(),
"search_radius": self.search_radius.value() if self.search_radius.value() > 0 else None,
}
return self.IDW_ALG_NAME, params
else: # Kriging
Expand All @@ -96,10 +98,6 @@ def on_output_raster_settings_changed(self, i):

def on_interpolation_method_changed(self, i):
self.interpolation_method_pages.setCurrentIndex(i)
if self.interpolation_method.currentText().lower() == "idw":
self.interpolation_method_pages.setMaximumHeight(50)
else:
self.interpolation_method_pages.setMaximumHeight(16777215) # Unrestricted


def run(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>746</width>
<height>896</height>
<height>901</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -157,6 +157,20 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="srach_radius_label">
<property name="text">
<string>Search radius</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QgsDoubleSpinBox" name="search_radius">
<property name="specialValueText">
<string>None</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="kriging_page">
Expand Down Expand Up @@ -434,8 +448,8 @@
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Ubuntu'; font-size:11pt;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>749</width>
<height>817</height>
<height>752</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -164,6 +164,20 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="search_radius_label">
<property name="text">
<string>Search radius</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QgsDoubleSpinBox" name="search_radius">
<property name="specialValueText">
<string>None</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="kriging_page">
Expand Down

0 comments on commit e9fc720

Please sign in to comment.