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

motta.luiz at gmail.com motta.luiz at gmail.com
Tue Oct 20 06:33:45 EDT 2009


Lutfi,

Change:
 'geom.vectorType()'
 TO
 'geom.type()'

API doc:
http://doc.qgis.org/head/classQgsGeometry.html#d57348e8a59d162a8a24226aa319d7f6


PS: I run with QGIS 1.03-3 (Windows XP)

Lutfi Oduncuoglu escreveu:
> 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 <http://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())
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-developer
>   



More information about the Qgis-developer mailing list