Sign up ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Is there a straight way to clone or "deepcopy" a QgsVectorLayer Object with python? Unfortunately the python module "copy" is not successfull with that.

Thanks in advance! nikolaus

share|improve this question
In the QGIS 1.9 nightly build is a new function which allows to copy a layer from the layerbox via a simple mouseclick (rightclick on layer, copy). Maybe you can search for the respective function in the QGIS api – Curlew Nov 7 '12 at 9:48
I have to solve it for Version 1.8. But otherwise this might work. Thank you! – klausb Nov 7 '12 at 10:17

1 Answer 1

up vote 4 down vote accepted

The QgsVectorLayer class is just a view into the underlying data source so you can just do this to make a new layer:

newlayer = QgsVectorLayer(layer.source(),, layer.providerType())

where layer is a instance of another QgsVectorLayer

share|improve this answer
Great, it's exactly what i needed. Thanks! – klausb Nov 7 '12 at 14:25
They really should add a copy method... – nickves Oct 30 at 15:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.