3

I am currently creating a vector layer like following:

outLayer = QgsVectorLayer('Linestring?crs='+ crs, 'graph_with_azimuth_ogr' , 'memory')

The outLayer is now stored in memory, which means it only stores the layer temporarily. If I restart QGIS, the layer will be deleted again.

My question is: How is it possible to create a vector layer which is permanently stored or which storage provider do I need to achieve this?

I have already tried it with the "ogr" storage provider, but it does not work. Any suggestions?

2

1 Answer 1

2

As Joseph suggested in the comments, the solution is to add the following line to your python script:

_writer = QgsVectorFileWriter.writeAsVectorFormat(outLayer ,r"C:/Users/yourUser/yourPath/something.shp","utf-8",None,"ESRI Shapefile")

This line will export your outputlayer into a shapefile. If you want to export it into another format, you will have to specify it (in the last parameter).

Thank you Joseph!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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