I recently started using Qgis python console for Qgis development. My first task is to load the layer and print its attributes.I firstly load a point layer using code
mylr = QgsVectorLayer("/home/ali/Python Work/work for centerline/","pnt.shp", "ogr")
iter = mylr.getFeatures()
for feature in iter:
geom = feature.geometry()
print "Feature ID %d: " % feature.id()
if geom.type() == QGis.Point:
x = geom.asPoint()
print "Point: " + str(x)
elif geom.type() == QGis.Line:
x = geom.asPolyline()
print "Line: %d points" % len(x)
elif geom.type() == 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 = feature.attributes()
print attrs
it printed the attributes of the layer pnt.shp.Then i changed the layer name
mylr = QgsVectorLayer("/home/ali/Python Work/work for centerline/","pgon.shp", "ogr")
all the following code was same.When i run the script it printed the attributes of the layer i loaded before pnt.shp. Every time i run my script it always print the attributes of pnt.shp and do not load the current layer Even if i change the veriables it always print the same layer attributes Please help me to solve this problem