Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 5 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 '15 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.