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

Germán Carrillo carrillo.german at gmail.com
Tue May 29 03:17:38 PDT 2012


Hi QGIS devs,

could someone please give this thread's code a try?

I've already attempted several things with no success, namely to store
layers (vlayer), features, geometries and/or rubber bands in a list. Still
I'm unable to get the geometries displayed as rubber bands, is it possible
with QGIS?

I'm using QGIS 1.8.0-Lisboa, rev. a1255fc, Python v.2.7.2, GDAL/OGR v.1.7.3

Thanks in advance,

Germán


---------- Forwarded message ----------
From: Germán Carrillo <carrillo.german at gmail.com>
Date: 2012/5/21
Subject: Displaying local file's geometries as rubber bands
To: qgis-developer <qgis-developer at lists.osgeo.org>


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()
    vlayer.select(allAttrs)
    f = QgsFeature()

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

loadGMLAsRubberBands("/tmp/gml/sample_three_features.gml")
#---------------------------------------------------------------------------------------------------------

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?


Regards,

Germán

-------------------
[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
http://geotux.tuxfamily.org/
http://twitter.com/GeoTux2


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

Soluciones Geoinformáticas Libres
http://geotux.tuxfamily.org/
http://twitter.com/GeoTux2
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20120529/74f44ac3/attachment.html>


More information about the Qgis-developer mailing list