[Qgis-developer] Command to avoid one layer replacing last layer

Echavarria Gregory, Maria Angelica m.echavarriagregory at umiami.edu
Wed Nov 25 19:00:56 EST 2009


Developers Group,

I have developed my PyQGIS application using OSGeo4W 1.0 Kore python 2.5 bindings for win32.  I have a method that loads vector layers (ogr's shapefiles) and another method that loads rasters (png's with pgw's) to my canvas. Both work nice but loading either layer replaces the other and biceversa. The idea is that the raster stays below the shapefile as if the raster was the background... like it happens in the Stand Alone QGis when loading multiple vectors and rasters using the buttons... My question is: is there a command line that I am missing? or could the problem be my canvas background color? below are my two methods in their simplest way:


def MyRasterLoad(self, file, fileName):
        """Load any raster layer specifying its file string"""
        layer = QgsRasterLayer(file, fileName)
        if not layer.isValid():
            return
        QgsMapLayerRegistry.instance().addMapLayer(layer)
        self.canvas.setExtent(layer.extent())
        cl = QgsMapCanvasLayer(layer)
        layers = [cl]
        self.canvas.setLayerSet(layers)


def MyWorldLoad(self, file, fileName, ext=bool):
        """add the base map layer and zoom to its extent or add graticule for the delimited area"""
        layer = QgsVectorLayer(file, fileName, "ogr")
        if not layer.isValid():
            return
        symbols = layer.renderer().symbols()
        symbol = symbols[0]
        symbol.setFillColor(QColor.fromRgb(0,100,0))
        QgsMapLayerRegistry.instance().addMapLayer(layer);
        if ext == True:
            self.canvas.setExtent(layer.extent())
        if ext == False:
            rect = QgsRectangle(float(self.x_min), float(self.y_min), float(self.x_max), float(self.y_max))
            self.canvas.setExtent(rect)
        cl = QgsMapCanvasLayer(layer)
        layers = [cl]
        self.canvas.setLayerSet(layers)

Thanks so much!,
Angelica.



More information about the Qgis-developer mailing list