Hi all, <br><br>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. <br>
<br>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:<br><br>#---------------------------------------------------------------------------------------------------------<br>
from qgis.core import QgsFeature, QgsVectorLayer<br>from qgis.gui import QgsRubberBand<br><br>def loadGMLAsRubberBands(fileName):<br> featList = [] <br> rb = QgsRubberBand(qgis.utils.iface.mapCanvas(), True)<br>
<br>
vlayer = QgsVectorLayer(fileName, "layer", "ogr")<br> allAttrs = vlayer.dataProvider().attributeIndexes()<br> vlayer.select(allAttrs) <br> f = QgsFeature()<br> <br> while vlayer.dataProvider().nextFeature(f):<br>
featList.append(f) <br> rb.addGeometry(featList[-1].geometry(), None) <br><br>loadGMLAsRubberBands("/tmp/gml/sample_three_features.gml")<br>#---------------------------------------------------------------------------------------------------------<br>
<br>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].<br><br>Do you have any hint?<br><br><br>
Regards, <br>
<br>Germán<br><br>-------------------<br>[1] <a href="http://lists.osgeo.org/pipermail/qgis-developer/2012-May/020143.html">http://lists.osgeo.org/pipermail/qgis-developer/2012-May/020143.html</a><br clear="all">[2] <a href="http://ifgibox.de/g_carr02/sample_three_features.gml">http://ifgibox.de/g_carr02/sample_three_features.gml</a><br>
<br>-- <br>-----------<br> |\__ <br>(:>__)(<br> |/ <br><br>Soluciones Geoinformáticas Libres <br><a href="http://geotux.tuxfamily.org/">http://geotux.tuxfamily.org/</a><br><a href="http://twitter.com/GeoTux2">http://twitter.com/GeoTux2</a><br>
<br>