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

Echavarria Gregory, Maria Angelica m.echavarriagregory at umiami.edu
Thu Nov 26 19:32:32 EST 2009


Thanks Aaron and German,

My code worked with German's solution and the reorganization of layers in futher loads worked pretty well using the global layers list also.

Angelica.

________________________________
From: Germán Carrillo [carrillo.german at gmail.com]
Sent: Thursday, November 26, 2009 9:19 AM
To: Echavarria Gregory, Maria Angelica; qgis-developer at lists.osgeo.org
Subject: Re: [Qgis-developer] Re: Command to avoid one layer replacing last layer

You can define self.layers on __init__ method this way:

self.layers = []

And then just add every new layer:

self.layers.insert( 0, QgsMapCanvasLayer( newLayer ) )
self.canvas.setLayerSet( self.layers )

Regards.

2009/11/25 Echavarria Gregory, Maria Angelica <m.echavarriagregory at umiami.edu<mailto:m.echavarriagregory at umiami.edu>>
>Angelica,
>Try replacing:
>layers = [cl]
>self.canvas.setLayerSet(layers)
>With:
>layers = self.canvas.mapRenderer().layerSet()
>layers.insert(0,cl)
>self.canvas.setLayerSet(layers)

Aaron, thanks for your answer,

I tried the replacement you recommended and got a Type error (cl must be QStringList type), then I tried correcting the issue with the following in the vector layer method:

 cl= QgsMapCanvasLayer (layer)
layers = list (self.canvas.mapRenderer ( ).layerSet ( ) )
 layers.insert(0, cl)
self.canvas.setLayerSet(layers)

And I got no error message for the Vector layer method any more, but I did the same correction in the same part of the raster layer method and when using it, I'm getting that the argument in
 self.canvas.setLayerSet(layers) has an invalid type. Could you please tell me what's wrong? I was thinking I may have to make "layers" a global variable and call it from my raster method to keep inserting in it... but it doesn't have the type I'd need to do so... I'm not quite understanding how this "appending" of layers works...     :-|

I need to upload the vector first because it is the base map, then add the raster, and then I do have to reorganize my layers as you said when I get the layerset ok, thank you.

Thanks a lot,
Angelica._______________________________________________
Qgis-developer mailing list
Qgis-developer at lists.osgeo.org<mailto:Qgis-developer at lists.osgeo.org>
http://lists.osgeo.org/mailman/listinfo/qgis-developer

--
-----------
  |\__
(:>__)(
  |/

Soluciones Geoinformáticas  Libres
http://geotux.tuxfamily.org/


More information about the Qgis-developer mailing list