<blockquote style='border-left:2px solid #CCCCCC;padding:0 1em' class="quote dark-border-color"><div class="quote light-border-color">
<div class="quote-author" style="font-weight: bold;">Matthias Kuhn-2 wrote</div>
<div class="quote-message">
Are you working with an attribute table (or an attribute table model) there?
</div>
</div></blockquote>


<p>Yes. This code takes categorized 2.5d render roof colours, wall colours, and heights, and adds them as fields into cleanedLayer, which is GeoJSON from <code>writeAsVectorFormat()</code>:</p>

<pre>provider = cleanedLayer.dataProvider()
provider.addAttributes([QgsField("height", QVariant.Double),
    QgsField("wallColor", QVariant.String),
    QgsField("roofColor", QVariant.String)])
cleanedLayer.updateFields()
fields = cleanedLayer.pendingFields()
renderer = dirtyLayer.rendererV2()
renderContext = QgsRenderContext.fromMapSettings(
        canvas.mapSettings())

heightField = fields.indexFromName("height")
wallField = fields.indexFromName("wallColor")
roofField = fields.indexFromName("roofColor")

feats = dirtyLayer.getFeatures()
cleanedLayer.startEditing()
for feat in feats:
    classAttribute = renderer.classAttribute()
    attrValue = feat.attribute(classAttribute)
    catIndex = renderer.categoryIndexForValue(attrValue)
    categories = renderer.categories()
    symbol = categories[catIndex].symbol()

    wallColor = symbol.symbolLayer(1).subSymbol().color().name()
    roofColor = symbol.symbolLayer(2).subSymbol().color().name()
    cleanedLayer.changeAttributeValue(feat.id() + 1,
                                      heightField, height)
    cleanedLayer.changeAttributeValue(feat.id() + 1,
                                      wallField, wallColor)
    cleanedLayer.changeAttributeValue(feat.id() + 1,
                                      roofField, roofColor)
cleanedLayer.commitChanges()</pre>

<p>Before adding those three "+ 1"s from that commit, the colours and height were applying to the wrong feature - the id (I think) off by one. Hence the hacky fix, and my comment that this works, but I don't understand why I have to do it.</p>


        
        
        
<br/><hr align="left" width="300" />
View this message in context: <a href="http://osgeo-org.1560.x6.nabble.com/The-first-column-in-the-attribute-table-tp5271947p5272186.html">Re: The first column in the attribute table</a><br/>
Sent from the <a href="http://osgeo-org.1560.x6.nabble.com/Quantum-GIS-Developer-f4099106.html">Quantum GIS - Developer mailing list archive</a> at Nabble.com.<br/>