From b497fdb3bd618224f39779d06e163fcb62add13b Mon Sep 17 00:00:00 2001 From: Mika Sorvoja <134925837+msorvoja@users.noreply.github.com> Date: Thu, 5 Dec 2024 09:41:53 +0200 Subject: [PATCH] Add search radius parameter to IDW interpolation (#292) * feat(IDW): Add search radius parameter --- .../vector_processing/idw_interpolation.py | 11 +++++++++- .../mineral_proxies/workflows/interpolate.py | 10 ++++------ .../proxy_workflow2_interpolation.ui | 20 ++++++++++++++++--- .../proxy_workflow4_interpolation_anomaly.ui | 16 ++++++++++++++- 4 files changed, 46 insertions(+), 11 deletions(-) diff --git a/eis_qgis_plugin/eis_processing/algorithms/vector_processing/idw_interpolation.py b/eis_qgis_plugin/eis_processing/algorithms/vector_processing/idw_interpolation.py index 3f9a943c..96a24e8d 100644 --- a/eis_qgis_plugin/eis_processing/algorithms/vector_processing/idw_interpolation.py +++ b/eis_qgis_plugin/eis_processing/algorithms/vector_processing/idw_interpolation.py @@ -32,6 +32,7 @@ def initAlgorithm(self, config=None): "pixel_size", "extent", "power", + "search_radius", "output_raster", ] @@ -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) diff --git a/eis_qgis_plugin/eis_wizard/mineral_proxies/workflows/interpolate.py b/eis_qgis_plugin/eis_wizard/mineral_proxies/workflows/interpolate.py index 23bda5dc..5d634668 100644 --- a/eis_qgis_plugin/eis_wizard/mineral_proxies/workflows/interpolate.py +++ b/eis_qgis_plugin/eis_wizard/mineral_proxies/workflows/interpolate.py @@ -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 @@ -68,7 +69,7 @@ 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) @@ -76,7 +77,8 @@ def initialize(self): 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 @@ -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): diff --git a/eis_qgis_plugin/resources/ui/mineral_proxies/proxy_workflow2_interpolation.ui b/eis_qgis_plugin/resources/ui/mineral_proxies/proxy_workflow2_interpolation.ui index d32cf802..cd1a4e05 100644 --- a/eis_qgis_plugin/resources/ui/mineral_proxies/proxy_workflow2_interpolation.ui +++ b/eis_qgis_plugin/resources/ui/mineral_proxies/proxy_workflow2_interpolation.ui @@ -7,7 +7,7 @@ 0 0 746 - 896 + 901 @@ -157,6 +157,20 @@ + + + + Search radius + + + + + + + None + + + @@ -434,8 +448,8 @@ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;"> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html> +</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;"> +<p style="-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;"><br /></p></body></html> diff --git a/eis_qgis_plugin/resources/ui/mineral_proxies/proxy_workflow4_interpolation_anomaly.ui b/eis_qgis_plugin/resources/ui/mineral_proxies/proxy_workflow4_interpolation_anomaly.ui index fd8f9704..1813f02b 100644 --- a/eis_qgis_plugin/resources/ui/mineral_proxies/proxy_workflow4_interpolation_anomaly.ui +++ b/eis_qgis_plugin/resources/ui/mineral_proxies/proxy_workflow4_interpolation_anomaly.ui @@ -7,7 +7,7 @@ 0 0 749 - 817 + 752 @@ -164,6 +164,20 @@ + + + + Search radius + + + + + + + None + + +