Skip to content

Commit

Permalink
Fix exception in interpolation algorithm widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 7, 2023
1 parent cf61c16 commit f38b735
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
9 changes: 6 additions & 3 deletions python/plugins/processing/algs/qgis/ui/HeatmapWidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,9 @@ def recalculate_bounds(self):

def pixelSizeChanged(self):
cell_size = self.mCellXSpinBox.value()
if cell_size <= 0:
if cell_size <= 0 or self.raster_bounds.isNull():
return

self.mCellYSpinBox.blockSignals(True)
self.mCellYSpinBox.setValue(cell_size)
self.mCellYSpinBox.blockSignals(False)
Expand All @@ -115,8 +116,9 @@ def pixelSizeChanged(self):

def rowsChanged(self):
rows = self.mRowsSpinBox.value()
if rows <= 0:
if rows <= 0 or self.raster_bounds.isNull():
return

cell_size = self.raster_bounds.height() / rows
cols = max(round(self.raster_bounds.width() / cell_size) + 1, 1)
self.mColumnsSpinBox.blockSignals(True)
Expand All @@ -129,8 +131,9 @@ def rowsChanged(self):

def columnsChanged(self):
cols = self.mColumnsSpinBox.value()
if cols < 2:
if cols < 2 or self.raster_bounds.isNull():
return

cell_size = self.raster_bounds.width() / (cols - 1)
rows = max(round(self.raster_bounds.height() / cell_size), 1)
self.mRowsSpinBox.blockSignals(True)
Expand Down
14 changes: 6 additions & 8 deletions python/plugins/processing/algs/qgis/ui/InterpolationWidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,7 @@ def setLayers(self, layersData: str):
layer = QgsProcessingUtils.variantToSource(v[0], self.context)
if layer:
self.layers.append(layer)
bbox = layer.sourceExtent()
if self.extent.isEmpty():
self.extent = bbox
else:
self.extent.combineExtentWith(bbox)
self.extent.combineExtentWith(layer.sourceExtent())

self.pixelSizeChanged()

Expand All @@ -307,7 +303,7 @@ def setExtent(self, extent: Optional[str]):

def pixelSizeChanged(self):
cell_size = self.mCellXSpinBox.value()
if cell_size <= 0:
if cell_size <= 0 or self.extent.isNull():
return

self.mCellYSpinBox.blockSignals(True)
Expand All @@ -324,8 +320,9 @@ def pixelSizeChanged(self):

def rowsChanged(self):
rows = self.mRowsSpinBox.value()
if rows <= 0:
if rows <= 0 or self.extent.isNull():
return

cell_size = self.extent.height() / rows
cols = max(round(self.extent.width() / cell_size) + 1, 1)
self.mColumnsSpinBox.blockSignals(True)
Expand All @@ -338,8 +335,9 @@ def rowsChanged(self):

def columnsChanged(self):
cols = self.mColumnsSpinBox.value()
if cols < 2:
if cols < 2 or self.extent.isNull():
return

cell_size = self.extent.width() / (cols - 1)
rows = max(round(self.extent.height() / cell_size), 1)
self.mRowsSpinBox.blockSignals(True)
Expand Down

0 comments on commit f38b735

Please sign in to comment.