You missed the provider select method:<br><a href="http://www.qgis.org/wiki/Python_Bindings#Using_vector_layer">http://www.qgis.org/wiki/Python_Bindings#Using_vector_layer</a><br><br>Germán<br><br><div class="gmail_quote">
2009/8/24 <span dir="ltr"><<a href="mailto:ahmed@elegantdesigns.ca">ahmed@elegantdesigns.ca</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
The output of the attached code is:<br>
<br>
Layer: "test_shp_layer"<br>
field: "test_shp_field"<br>
v_provider: "<qgis.core.QgsFeature object at 0xab50dac>"<br>
rows: []<br>
<br>
<br>
Even if I add a dummy string to the list, it will only return that value.<br>
For some reason, I cannot seem to fetch the features from the layer and<br>
load them into the list. I was wondering, what did my fragile brain do<br>
wrong? and how can i fix it?<br>
<br>
cheers,<br>
dassouki<br>
<br>
# CODE:<br>
<br>
# loads a field into a python list<br>
def field_to_list( self, layer_name, field_name ):<br>
v_layer = self.get_vector_layer_by_name( layer_name ) )<br>
v_provider = v_layer.dataProvider()<br>
id = v_provider.fieldNameIndex( field_name )<br>
rows = []<br>
feat = QgsFeature()<br>
while v_provider.nextFeature( feat ):<br>
data = feat.attributeMap()[ id ]<br>
row = [ data ]<br>
rows.append( row )<br>
QMessageBox.warning( self, "window title", str( ",".join( rows ) ) )<br>
return rows<br>
<br>
def get_vector_layer_by_name( self, myName ):<br>
layermap = QgsMapLayerRegistry.instance().mapLayers()<br>
for name, layer in layermap.iteritems():<br>
if layer.type() == QgsMapLayer.VectorLayer and <a href="http://layer.name" target="_blank">layer.name</a>() ==<br>
myName:<br>
if layer.isValid():<br>
return layer<br>
else:<br>
return None<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
Qgis-developer mailing list<br>
<a href="mailto:Qgis-developer@lists.osgeo.org">Qgis-developer@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/qgis-developer" target="_blank">http://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
</blockquote></div><br>-- <br>-----------<br> |\__ <br>(:>__)(<br> |/ <br><br>Soluciones Geoinformáticas Libres <br><a href="http://geotux.tuxfamily.org/">http://geotux.tuxfamily.org/</a><br>