Take the 2-minute tour ×
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
1  
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
add comment

1 Answer

up vote 3 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.name(), 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
add comment

Your Answer

 
discard

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.