I am trying to create a memory layer, I followed the directions from the page below but no points appeared on my map. First I tried typing each line into the python console and I also create a plugin with the same code and still nothing appeared on the map. At some point while I was typing the code into the console, it asked for the projection, so I specified my typical projection (epsg 2272, a state plane coordinate system)

How to create a new empty vector layer programmatically?

I also reviewed http://www.qgis.org/pyqgis-cookbook/vector.html#memory-provider

I am experimenting with memory layers because I want to include it into a plugin I am developing.

  • Please provide your script so far
    – underdark
    Commented Nov 15, 2012 at 14:42

1 Answer 1


I needed to add the layer to the interface using:


from PyQt4.QtCore import *

vl = QgsVectorLayer("Point", "temporary_points", "memory")
pr = vl.dataProvider()
pr.addAttributes( [ QgsField("name", QVariant.String), QgsField("age",  QVariant.Int),    QgsField("size", QVariant.Double) ] )

fet = QgsFeature()
fet.setGeometry( QgsGeometry.fromPoint(QgsPoint(1260179,432083)) )
fet.setAttributeMap( { 0 : QVariant("Johny"), 1 : QVariant(20), 2 : QVariant(0.3) } )
pr.addFeatures( [ fet ] )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.