[Qgis-developer] I got exceptions.AttributeError: vectorType error and can not solve it

Lutfi Oduncuoglu lutfioduncuoglu at gmail.com
Tue Oct 20 03:55:25 EDT 2009


Hello,

I am triying to write apython plugin to qgis and I got

exceptions.AttributeError: vectorType error what may be the problem I
couldn't find it. The feautre count turns value of 5 and I tried to check if
my layer is valid or not.


My code is below:



vlayer = QgsVectorLayer("/home/lutfi/Desktop/deneme/borders.shp", "hebe",
"ogr")


print vlayer.featureCount()


if not vlayer.isValid():
print "Couldn't open the layer"

else:
# QMessageBox.information(None, "Cancel", "File selection canceled")

provider = vlayer.dataProvider()
feat = QgsFeature()
allAttrs = provider.attributeIndexes()
provider.select(allAttrs)

while provider.nextFeature(feat):
geom = feat.geometry()
print "Feature ID %d: " % feat.id()
if geom.vectorType() == QGis.Point:
x = geom.asPoint()
print "Point: " + str(x)

elif geom.vectorType() == QGis.Line:

x = geom.asPolyline()
print "Line: %d points" % len(x)

elif geom.vectorType() == QGis.Polygon:

x = geom.asPolygon()
numPts = 0
for ring in x:
numPts += len(ring)
print "Polygon: %d rings with %d points" % (len(x), numPts)
else:
print "Unknown"
attrs = feat.attributeMap()

for (k,attr) in attrs.iteritems():
print "%d: %s" % (k, attr.toString())
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/qgis-developer/attachments/20091020/e8ee142d/attachment-0001.html


More information about the Qgis-developer mailing list