[Qgis-developer] Accessing Features from API

Germán Carrillo carrillo.german at gmail.com
Mon Aug 24 21:16:49 EDT 2009


You missed the provider select method:
http://www.qgis.org/wiki/Python_Bindings#Using_vector_layer

Germán

2009/8/24 <ahmed at elegantdesigns.ca>

> The output of the attached code is:
>
> Layer: "test_shp_layer"
> field: "test_shp_field"
> v_provider: "<qgis.core.QgsFeature object at 0xab50dac>"
> rows: []
>
>
> Even if I add a dummy string to the list, it will only return that value.
> For some reason, I cannot seem to fetch the features from the layer and
> load them into the list. I was wondering, what did my fragile brain do
> wrong? and how can i fix it?
>
> cheers,
> dassouki
>
> # CODE:
>
>  # loads a field into a python list
>  def field_to_list( self, layer_name, field_name ):
>    v_layer = self.get_vector_layer_by_name( layer_name ) )
>    v_provider = v_layer.dataProvider()
>    id = v_provider.fieldNameIndex( field_name )
>    rows = []
>    feat = QgsFeature()
>    while v_provider.nextFeature( feat ):
>      data = feat.attributeMap()[ id ]
>      row = [ data ]
>      rows.append( row )
>    QMessageBox.warning( self, "window title", str( ",".join( rows ) ) )
>    return rows
>
>  def get_vector_layer_by_name( self, myName ):
>    layermap = QgsMapLayerRegistry.instance().mapLayers()
>    for name, layer in layermap.iteritems():
>      if layer.type() == QgsMapLayer.VectorLayer and layer.name() ==
> myName:
>        if layer.isValid():
>          return layer
>        else:
>          return None
>
>
>
>
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-developer
>

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

Soluciones Geoinformáticas Libres
http://geotux.tuxfamily.org/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/qgis-developer/attachments/20090824/2f8471c7/attachment-0001.html


More information about the Qgis-developer mailing list