[Qgis-developer] Displaying local file's geometries as rubber bands

Germán Carrillo carrillo.german at gmail.com
Mon May 21 06:46:47 PDT 2012

Hi all,

I'd like to get geometries from a local file (e.g. GML) displayed as
QgsRubberBands. However, I wouldn't like to load the layer into the map
because in the real scenario there could be a large number of files to get
geometries from.

I've been attempting it with the following code (you can copy it directly
to the QGIS Python Console), but only the last feature is displayed:

from qgis.core import QgsFeature, QgsVectorLayer
from qgis.gui import QgsRubberBand

def loadGMLAsRubberBands(fileName):
    featList = []
    rb = QgsRubberBand(qgis.utils.iface.mapCanvas(), True)

    vlayer = QgsVectorLayer(fileName, "layer", "ogr")
    allAttrs = vlayer.dataProvider().attributeIndexes()
    f = QgsFeature()

    while vlayer.dataProvider().nextFeature(f):
        rb.addGeometry(featList[-1].geometry(), None)


Based on the solution given in this thread [1] I'm storing the features in
a list, but somehow it doesn't work in this scenario. A sample GML file can
be found at [2].

Do you have any hint?



[1] http://lists.osgeo.org/pipermail/qgis-developer/2012-May/020143.html
[2] http://ifgibox.de/g_carr02/sample_three_features.gml


Soluciones Geoinformáticas Libres
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/qgis-developer/attachments/20120521/931c5722/attachment.html

More information about the Qgis-developer mailing list