Update: Here's a version to try to avoid the memory errors from storing everything in a single list. Now, when the list has grown to the maximum possible size then the features will beare added to the layer and the list clearedonce per row. It's not as fast as the above method, but less memory hungry:
vl = QgsVectorLayer("Point?crs=", "temporary_points2", "memory")
vl.dataProvider().addAttributes([ QgsField("X_coord", QVariant.Int), QgsField("Y_coord", QVariant.Int), QgsField("Azimuth", QVariant.Int) ])
for row in range(0,rows):
new_features = []
for col in range(0,cols):
rspnt = pixel2coord(col,row)
fet = QgsFeature()
fet.setGeometry(QgsGeometry.fromPoint(QgsPoint(rspnt[0], rspnt[1])))
fet.initAttributes(3)
fet.setAttribute(0, rspnt[0] )
fet.setAttribute(1, rspnt[1])
az = pntxy.azimuth(QgsPoint(rspnt[0], rspnt[1]))
if az < 0.0:
azim = 360 + az
else:
azim = az
fet.setAttribute(2, azim)
try:
new_features.append(fet)
except:
vl.dataProvider().addFeatures( new_features )
new_features = []
vl.dataProvider().addFeatures( new_features )
vl.updateExtents()
vl.updateFields()
QgsMapLayerRegistry.instance().addMapLayers([vl])
it will be