<p dir="ltr"><br>
On 16 Mar 2016 20:56, "Tom Chadwin" <<a href="mailto:tom.chadwin@nnpa.org.uk">tom.chadwin@nnpa.org.uk</a>> wrote:<br>
></p>
<p dir="ltr">> def writeTmpLayer(layer, popup):<br>
> usedFields = getUsedFields(layer)<br>
> if popup != ALL_ATTRIBUTES:<br>
> uri = TYPE_MAP[layer.wkbType()]<br>
> crs = layer.crs()<br>
> if crs.isValid():<br>
> uri += '?crs=' + crs.authid()<br>
> if popup != NO_POPUP:<br>
> usedFields.append(popup)<br>
> for field in usedFields:<br>
> fieldType = layer.pendingFields().field(field).type()<br>
> fieldType = "double" if (fieldType == QVariant.Double or<br>
> fieldType == QVariant.Int) else (<br>
> "string")<br>
> uri += '&field=' + unicode(field) + ":" + fieldType<br>
> newlayer = QgsVectorLayer(uri, <a href="http://layer.name">layer.name</a>(), 'memory')<br>
> writer = newlayer.dataProvider()<br>
> outFeat = QgsFeature()<br>
> for feature in layer.getFeatures():<br>
> outFeat.setGeometry(feature.geometry())<br>
> attrs = [feature[f] for f in usedFields]<br>
> if attrs:<br>
> outFeat.setAttributes(attrs)<br>
> writer.addFeatures([outFeat])<br>
> layer = newlayer<br>
> return layer<br>
><br>
> The snippet which calls the function above and is meant to add the fields to<br>
> the memory layer is:<br>
><br>
> if (layer.type() == layer.VectorLayer)<br>
> cleanLayer = writeTmpLayer(layer, popup)<br>
> if is25d(layer, canvas):<br>
> provider = cleanLayer.dataProvider()<br>
> provider.addAttributes([QgsField("height", QVariant.Double),<br>
> QgsField("wallColor", QVariant.String),<br>
> QgsField("roofColor",<br>
> QVariant.String)])<br>
> cleanLayer.updateFields()<br></p>
<p dir="ltr">></p>
<p dir="ltr">If popup == ALL_ATTRIBUTES then your writeTmpLayer function is returning the original layer.</p>
<p dir="ltr">Nyall</p>