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

Germán Carrillo carrillo.german at gmail.com
Thu Nov 26 09:19:22 EST 2009


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>

> >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
> http://lists.osgeo.org/mailman/listinfo/qgis-developer
>

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

Soluciones Geoinformáticas Libres
http://geotux.tuxfamily.org/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/qgis-developer/attachments/20091126/16d126c5/attachment.html


More information about the Qgis-developer mailing list