[Qgis-developer] Can not load a shp file with QgsVectorLayer

Martin Dobias wonder.sk at gmail.com
Fri Oct 16 05:38:52 EDT 2009


On Fri, Oct 16, 2009 at 10:59 AM, Lutfi Oduncuoglu
<lutfioduncuoglu at gmail.com> wrote:
> [...]
>
>       vlayer = QgsVectorLayer( fileName, "hebe", "ogr")
>       provider = vlayer.dataProvider()
>       feat = QgsFeature()
>       allAttrs = provider.attributeIndexes()
>       provider.select(allAttrs)
>
>       while provider.nextFeature(feat):
>         geom = feat.geometry()
>         print "Feature ID %d: " % feat.id()
>
> This piece of code returns nothing to me. What is wrong here.

Hi

first of all you should check whether the vector layer has been opened
correctly - this is the most common problem:
if not vlayer.isValid():
  print "Couldn't open the layer"

If the layer is valid and it still doesn't print anything, try doing
some checks - find out feature count etc.

Regards
Martin


More information about the Qgis-developer mailing list