[Qgis-developer] Display raster layer on own Map Canvas
Hello, I am new to python and the QGIS API and writing a plugin in python to simulate/model insect dispersal. I am using .ui files and Qt Designer. And i placed a QWidget on the form and promote it to a new class: set QgsMapCanvas as class name and set qgis.gui as header file. I load a raster layer, set canvas color and so on. But the layer only displays if i use QgsMapLayerRegistry.instance().addMapLayer(self.layer). Without these code line my plugin only displays the rubber band, but not the raster layer. But if i use ...addMapLayer() it also loads the layer in QGIS. I want to have a behaviour like in the GDAL - Georeferenzierung plugin. There you could add a raster layer and the plugin displays it only in the plugin window, not in the QGIS MainWindow. Here is the method code: def addRasterLayer(self): fileName = NE2_50M_SR.tif fileInfo = QFileInfo(fileName) baseName = fileInfo.baseName() self.layer = QgsRasterLayer(fileName, baseName) if not self.layer.isValid(): #error #only with this line of code the raster layer will be displayed: QgsMapLayerRegistry.instance().addMapLayer(self.layer) self.canvas = self.dlg.ui.mapCanvasWidget self.canvas.setCanvasColor(Qt.white) self.canvas.setExtent(self.layer.extent()) self.canvas.setLayerSet( [ QgsMapCanvasLayer(self.layer) ] ) r = QgsRubberBand(self.dlg.ui.mapCanvasWidget, True) points = [ [ QgsPoint(-10,-10), QgsPoint(0,10), QgsPoint(10,-10) ] ] r.setToGeometry(QgsGeometry.fromPolygon(points), None) self.canvas.setCurrentLayer (self.layer) self.canvas.setVisible(True); self.canvas.refresh() best regards, Daniel ___ Qgis-developer mailing list Qgis-developer@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/qgis-developer
Re: [Qgis-developer] Display raster layer on own Map Canvas
I have a similar problem with vector layer. See http://osgeo-org.1560.n6.nabble.com/secondary-mapCanvas-and-memory-layer-tt5001051.html and I'm still looking for a solution. Regards, Massimo -- View this message in context: http://osgeo-org.1560.n6.nabble.com/Display-raster-layer-on-own-Map-Canvas-tp5002935p5002974.html Sent from the Quantum GIS - Developer mailing list archive at Nabble.com. ___ Qgis-developer mailing list Qgis-developer@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/qgis-developer
Re: [Qgis-developer] Display raster layer on own Map Canvas
Hi On Wed, Sep 19, 2012 at 2:36 PM, Daniel Klich daniel.kl...@gmx.de wrote: Hello, I am new to python and the QGIS API and writing a plugin in python to simulate/model insect dispersal. I am using .ui files and Qt Designer. And i placed a QWidget on the form and promote it to a new class: set QgsMapCanvas as class name and set qgis.gui as header file. I load a raster layer, set canvas color and so on. But the layer only displays if i use QgsMapLayerRegistry.instance().addMapLayer(self.layer). Without these code line my plugin only displays the rubber band, but not the raster layer. But if i use ...addMapLayer() it also loads the layer in QGIS. I want to have a behaviour like in the GDAL - Georeferenzierung plugin. There you could add a raster layer and the plugin displays it only in the plugin window, not in the QGIS MainWindow. Try passing False to QgsMapLayerRegistry.instance().addMapLayer(layer, [bool]) The bool options should suppress it being added to the main canvas. Then manually add it to the map canvas by wrapping it as a mapcanvaslayer and explicitly passing a set of mapcanvaslayers using QgsMapCanvas.setLayerSet() Regards Tim PS QgsMapLayerRegistry.instance().addMapLayer(layer, [bool]) is deprecated, use addMapLayers(list, bool) rather. Here is the method code: def addRasterLayer(self): fileName = NE2_50M_SR.tif fileInfo = QFileInfo(fileName) baseName = fileInfo.baseName() self.layer = QgsRasterLayer(fileName, baseName) if not self.layer.isValid(): #error #only with this line of code the raster layer will be displayed: QgsMapLayerRegistry.instance().addMapLayer(self.layer) self.canvas = self.dlg.ui.mapCanvasWidget self.canvas.setCanvasColor(Qt.white) self.canvas.setExtent(self.layer.extent()) self.canvas.setLayerSet( [ QgsMapCanvasLayer(self.layer) ] ) r = QgsRubberBand(self.dlg.ui.mapCanvasWidget, True) points = [ [ QgsPoint(-10,-10), QgsPoint(0,10), QgsPoint(10,-10) ] ] r.setToGeometry(QgsGeometry.fromPolygon(points), None) self.canvas.setCurrentLayer (self.layer) self.canvas.setVisible(True); self.canvas.refresh() best regards, Daniel ___ Qgis-developer mailing list Qgis-developer@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/qgis-developer -- Tim Sutton - QGIS Project Steering Committee Member (Release Manager) == Please do not email me off-list with technical support questions. Using the lists will gain more exposure for your issues and the knowledge surrounding your issue will be shared with all. Visit http://linfiniti.com to find out about: * QGIS programming and support services * Mapserver and PostGIS based hosting plans * FOSS Consulting Services Skype: timlinux Irc: timlinux on #qgis at freenode.net == ___ Qgis-developer mailing list Qgis-developer@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/qgis-developer
Re: [Qgis-developer] Display raster layer on own Map Canvas
Tim Sutton-4 wrote I load a raster layer, set canvas color and so on. But the layer only displays if i use QgsMapLayerRegistry.instance().addMapLayer(self.layer). Without these code line my plugin only displays the rubber band, but not the raster layer. But if i use ...addMapLayer() it also loads the layer in QGIS. I want to have a behaviour like in the GDAL - Georeferenzierung plugin. There you could add a raster layer and the plugin displays it only in the plugin window, not in the QGIS MainWindow. Try passing False to QgsMapLayerRegistry.instance().addMapLayer( layer , [bool]) The bool options should suppress it being added to the main canvas. Then manually add it to the map canvas by wrapping it as a mapcanvaslayer and explicitly passing a set of mapcanvaslayers using QgsMapCanvas.setLayerSet() Thank you. That worked for me. ( QgsMapLayerRegistry.instance().addMapLayer(self.layer, False) ) Tim Sutton-4 wrote PS QgsMapLayerRegistry.instance().addMapLayer( layer , [bool]) is deprecated, use addMapLayers( list , bool) rather. I am using Version 1.7.4. addMapLayers(list, bool) only works in 1.8., right ? best regards, Daniel -- View this message in context: http://osgeo-org.1560.n6.nabble.com/Display-raster-layer-on-own-Map-Canvas-tp5002935p5002986.html Sent from the Quantum GIS - Developer mailing list archive at Nabble.com. ___ Qgis-developer mailing list Qgis-developer@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/qgis-developer
Re: [Qgis-developer] Display raster layer on own Map Canvas
Hi On Sep 19, 2012 5:33 PM, DanielK daniel.kl...@gmx.de wrote: Tim Sutton-4 wrote I load a raster layer, set canvas color and so on. But the layer only displays if i use QgsMapLayerRegistry.instance().addMapLayer(self.layer). Without these code line my plugin only displays the rubber band, but not the raster layer. But if i use ...addMapLayer() it also loads the layer in QGIS. I want to have a behaviour like in the GDAL - Georeferenzierung plugin. There you could add a raster layer and the plugin displays it only in the plugin window, not in the QGIS MainWindow. Try passing False to QgsMapLayerRegistry.instance().addMapLayer( layer , [bool]) The bool options should suppress it being added to the main canvas. Then manually add it to the map canvas by wrapping it as a mapcanvaslayer and explicitly passing a set of mapcanvaslayers using QgsMapCanvas.setLayerSet() Thank you. That worked for me. ( QgsMapLayerRegistry.instance().addMapLayer(self.layer, False) ) Tim Sutton-4 wrote PS QgsMapLayerRegistry.instance().addMapLayer( layer , [bool]) is deprecated, use addMapLayers( list , bool) rather. I am using Version 1.7.4. addMapLayers(list, bool) only works in 1.8., right ? Correct. Regards Tim best regards, Daniel -- View this message in context: http://osgeo-org.1560.n6.nabble.com/Display-raster-layer-on-own-Map-Canvas-tp5002935p5002986.html Sent from the Quantum GIS - Developer mailing list archive at Nabble.com. ___ Qgis-developer mailing list Qgis-developer@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/qgis-developer ___ Qgis-developer mailing list Qgis-developer@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/qgis-developer