[Qgis-developer] Can not load a shp file with QgsVectorLayer
Lutfi Oduncuoglu
lutfioduncuoglu at gmail.com
Fri Oct 16 04:59:04 EDT 2009
Hello,
I am a newbie about qgis I am trying to load a vector layer from a shape
file. I can load it from add layer button but can not load from the plugin I
am tryin to write. My code is below:
def unload(self):
# Remove the plugin menu item and icon
self.iface.removePluginMenu("&Read shp for calculations",self.action)
self.iface.removeToolBarIcon(self.action)
# run method that performs all the real work
def run(self):
fileName =
QFileDialog.getOpenFileName(None,QString.fromLocal8Bit("Select a file:"),"",
"*.shp *.gml")
if fileName.isNull():
QMessageBox.information(None, "Cancel", "File selection canceled")
else:
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.
Thanks for help
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/qgis-developer/attachments/20091016/1ce2ca3e/attachment.html
More information about the Qgis-developer
mailing list