Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have some Python code to get the ids and georeference from a shapefile:

canvas = qgis.utils.iface.mapCanvas()
allLayers = canvas.layers()
nos = QgsFeature()
for i in allLayers:
        path_nodes = i

nodedata  = path_nodes.dataProvider()

while nodedata.nextFeature(nos):
    i = i + 1
    print str(no.gid())

It does not return all of the ids. Can anyone help?

share|improve this question
How many ids did it miss? – R.K. May 21 '13 at 3:57
up vote 0 down vote accepted

As @bananafish noted, no should be nos. You might also want to set i=0 before the loop.

nos = QgsFeature()
while nodedata.nextFeature(nos):
    i = i + 1
    print str(nos.gid())
share|improve this answer

In the while loop, no doesn't refer to anything, you need to assign it to the current feature. I don't know how the QGIS API works, so here's a somewhat ugly approach:

while True:
        no = nodedata.nextFeature(nos)
    print str(no.gid())
share|improve this answer
Thank you very much. Done – user1573901 May 21 '13 at 9:26
@user1573901: no problem! Please consider accepting the answer (click the tick mark under the down arrow) if it solved your problem. – bananafish May 21 '13 at 21:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.