[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()
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
-------------- 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