Skip to content

Commit 860f370

Browse files
committed
correctly handle WMS rasters in Random Points tool (fix #5202)
1 parent c94269c commit 860f370

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

python/plugins/fTools/tools/doRandPoints.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def update(self, inputLayer):
7979
self.cmbField.setEnabled(False)
8080
self.label_4.setEnabled(False)
8181

82-
# when 'OK' button is pressed, gather required inputs, and initiate random points generation
82+
# when 'OK' button is pressed, gather required inputs, and initiate random points generation
8383
def accept(self):
8484
self.buttonOk.setEnabled( False )
8585
if self.inShape.currentText() == "":
@@ -100,7 +100,7 @@ def accept(self):
100100
self.progressBar.setValue(5)
101101
mLayer = ftools_utils.getMapLayerByName(unicode(inName))
102102
if mLayer.type() == mLayer.VectorLayer:
103-
inLayer = QgsVectorLayer(unicode(mLayer.source()), unicode(mLayer.name()), unicode(mLayer.dataProvider().name()))
103+
inLayer = ftools_utils.getVectorLayerByName(unicode(inName))
104104
if self.rdoUnstratified.isChecked():
105105
design = self.tr("unstratified")
106106
value = self.spnUnstratified.value()
@@ -114,7 +114,7 @@ def accept(self):
114114
design = self.tr("field")
115115
value = unicode(self.cmbField.currentText())
116116
elif mLayer.type() == mLayer.RasterLayer:
117-
inLayer = QgsRasterLayer(unicode(mLayer.source()), unicode(mLayer.name()))
117+
inLayer = ftools_utils.getRasterLayerByName(unicode(inName))
118118
design = self.tr("unstratified")
119119
value = self.spnUnstratified.value()
120120
else:

python/plugins/fTools/tools/ftools_utils.py

+10
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,16 @@ def getVectorLayerByName( myName ):
206206
else:
207207
return None
208208

209+
# Return QgsRasterLayer from a layer name ( as string )
210+
def getRasterLayerByName( myName ):
211+
layermap = QgsMapLayerRegistry.instance().mapLayers()
212+
for name, layer in layermap.iteritems():
213+
if layer.type() == QgsMapLayer.RasterLayer and layer.name() == myName:
214+
if layer.isValid():
215+
return layer
216+
else:
217+
return None
218+
209219
# Return QgsMapLayer from a layer name ( as string )
210220
def getMapLayerByName( myName ):
211221
layermap = QgsMapLayerRegistry.instance().mapLayers()

0 commit comments

Comments
 (0)