Graphics Reference
In-Depth Information
feature.setAttribute("height", 301)
feature.setAttribute("name", "Eiffel Tower")
Putting all this together, let's build a complete example program that creates a memory
layer, populates it with a few QgsPoint features, and updates the map canvas to show
those points. Here is this example program:
layer =
QgsVectorLayer("Point?crs=EPSG:4326&field=height:double&field=name:string(255)",
"Point Layer", "memory")
provider = layer.dataProvider()
QgsMapLayerRegistry.instance().addMapLayer(layer)
fields = provider.fields()
features = []
feature = QgsFeature()
feature.setGeometry(QgsGeometry.fromWkt("POINT (2.2945
48.8582)"))
feature.setFields(fields)
feature.setAttribute("height", 301)
feature.setAttribute("name", "Eiffel Tower")
features.append(feature)
feature = QgsFeature()
feature.setGeometry(QgsGeometry.fromWkt("POINT (0.0761
51.5081)"))
feature.setFields(fields)
feature.setAttribute("height", 27)
feature.setAttribute("name", "Tower of London")
features.append(feature)
feature = QgsFeature()
feature.setGeometry(QgsGeometry.fromWkt("POINT (10.3964
43.7231)"))
feature.setFields(fields)
feature.setAttribute("height", 56)
feature.setAttribute("name", "Leaning Tower of Pisa")
features.append(feature)
Search WWH ::




Custom Search