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?

Taras
  • 32,823
  • 4
  • 66
  • 137
applebrown
  • 725
  • 7
  • 24

1 Answers1

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!

applebrown
  • 725
  • 7
  • 24