I have a vector layer, which I ma adding it to a subgroup "streets_greoup". My code also save it to the disk. But it still show temporary layer when I close my project and saved feature data lost. Below is my code.
How can I remove this temporary storage symbol and save data in this layer? Data should not removed after closed project. It should save permanently.
project_dir_path = str(QFileDialog.getExistingDirectory(None,"Select Directory"))
project = QgsProject.instance()
project.write(project_dir_path +"/qgs_design_test.qgs")
root = QgsProject.instance().layerTreeRoot()
master_group = root.addGroup('streets_group')
mygroup = root.findGroup("streets_group") # We assume the group exists
layer_name = 'terminal'
Fl_ou = project_dir_path + '/' + layer_name + ".shp"
mylayer = QgsVectorLayer("Point", layer_name, "memory")
QgsProject.instance().addMapLayer(mylayer, False)
mygroup.addLayer(mylayer)
options = QgsVectorFileWriter.SaveVectorOptions()
options.driverName = "ESRI Shapefile"
options.overrideGeometryType = QgsWkbTypes.PointZ
QgsVectorFileWriter.writeAsVectorFormatV2(mylayer, Fl_ou, QgsCoordinateTransformContext(), options)