I've got a layer (
difflayer) that has been created in memory. Basically, all the layers I've got in this project are in memory and the layer creation/manipulation is all being handled via a plugin.
Now, from looking around it seems the best way to move a layer around is to
clone() it, use
insertChildNode to add the clone, and then delete the original. Which I'd have no problem doing, except that layers in memory don't support
Does anyone have any ideas? I've also tried to duplicate the layer using the below code but get the following error:
feats = [feat for feat in difflayer.getFeatures()] mem_layer = QgsVectorLayer("Polygon?crs=EPSG:4283&field=ID:integer", "dup layer", "memory") mem_layer_data = mem_layer.dataProvider() attr = difflayer.dataProvider().fields().toList() mem_layer_data.addAttributes(attr) mem_layer.updateFields() mem_layer_data.addFeatures(feats) root = QgsProject.instance().layerTreeRoot() root.insertChildNode(2,mem_layer)
TypeError: QgsLayerTreeGroup.insertChildNode(int, QgsLayerTreeNode): argument 2 has unexpected type 'QgsVectorLayer'