Graphics Reference
In-Depth Information
The following types of fields are currently supported:
integer
double
string
You can also specify the field length and precision by listing these in parentheses,
for example, field=height:double(10,2) or field=-
name:string(50) .
If you want to have multiple attributes, you simply have one field=... entry
for each of the attributes you want to define.
Note
The memory layer's data provider has an addAttributes() method, which
you might assume you'd use to define the attributes. However, the addAttrib-
utes() method only adds the attributes to the data provider, not the map layer,
which can cause QGIS to crash. To avoid this, it is better to define your attributes
within the path when you set up your map layer, rather than trying to add them
later.
• A spatial index for this layer's features:
index=yes
Let's use this to create a more complex memory layer that stores point geometries using a
specified coordinate reference system, a spatial index, and some attributes. Here is how
we might do this:
layer = QgsVectorLayer(
"Point?crs=EPSG:4326&field=height:double&field=name:string(255)&index=yes",
"Point Layer", "memory")
Once we've instantiated our memory layer, we can create the various features we want to
display, and then add them to the layer. The following pseudocode shows how this is
done:
provider = layer.dataProvider()
feature1 = ...
Search WWH ::




Custom Search