Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

share|improve this question
    
Please provide your script so far –  underdark Nov 15 '12 at 14:42
add comment

1 Answer 1

I needed to add the layer to the interface using:

QgsMapLayerRegistry.instance().addMapLayer(vl)

from PyQt4.QtCore import *

vl = QgsVectorLayer("Point", "temporary_points", "memory")
pr = vl.dataProvider()
vl.startEditing()
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 ] )
vl.commitChanges()
QgsMapLayerRegistry.instance().addMapLayer(vl)
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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