Skip to content

Commit

Permalink
correctly handle WMS rasters in Random Points tool (fix #5202)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed May 22, 2012
1 parent c94269c commit 860f370
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 3 additions & 3 deletions python/plugins/fTools/tools/doRandPoints.py
Expand Up @@ -79,7 +79,7 @@ def update(self, inputLayer):
self.cmbField.setEnabled(False)
self.label_4.setEnabled(False)

# when 'OK' button is pressed, gather required inputs, and initiate random points generation
# when 'OK' button is pressed, gather required inputs, and initiate random points generation
def accept(self):
self.buttonOk.setEnabled( False )
if self.inShape.currentText() == "":
Expand All @@ -100,7 +100,7 @@ def accept(self):
self.progressBar.setValue(5)
mLayer = ftools_utils.getMapLayerByName(unicode(inName))
if mLayer.type() == mLayer.VectorLayer:
inLayer = QgsVectorLayer(unicode(mLayer.source()), unicode(mLayer.name()), unicode(mLayer.dataProvider().name()))
inLayer = ftools_utils.getVectorLayerByName(unicode(inName))
if self.rdoUnstratified.isChecked():
design = self.tr("unstratified")
value = self.spnUnstratified.value()
Expand All @@ -114,7 +114,7 @@ def accept(self):
design = self.tr("field")
value = unicode(self.cmbField.currentText())
elif mLayer.type() == mLayer.RasterLayer:
inLayer = QgsRasterLayer(unicode(mLayer.source()), unicode(mLayer.name()))
inLayer = ftools_utils.getRasterLayerByName(unicode(inName))
design = self.tr("unstratified")
value = self.spnUnstratified.value()
else:
Expand Down
10 changes: 10 additions & 0 deletions python/plugins/fTools/tools/ftools_utils.py
Expand Up @@ -206,6 +206,16 @@ def getVectorLayerByName( myName ):
else:
return None

# Return QgsRasterLayer from a layer name ( as string )
def getRasterLayerByName( myName ):
layermap = QgsMapLayerRegistry.instance().mapLayers()
for name, layer in layermap.iteritems():
if layer.type() == QgsMapLayer.RasterLayer and layer.name() == myName:
if layer.isValid():
return layer
else:
return None

# Return QgsMapLayer from a layer name ( as string )
def getMapLayerByName( myName ):
layermap = QgsMapLayerRegistry.instance().mapLayers()
Expand Down

0 comments on commit 860f370

Please sign in to comment.