I want to create a new shapefile (vector layer) from selected features. I select one feature then save that feature to a new shapefile.
When I use following code, I got a new shapefile but it's blank (blank attribute table, only field names available in the table). I want row entries based on the feature which is selected.
filename = 'C:/temp/outputs/select_001.shp'
selectedLayer = self.dlg.comboBox.currentLayer()
selectedField = self.dlg.comboBox_2.currentField()
selectedFeature = self.dlg.comboBox_3.currentText()
selectedLayer.selectByExpression( "\"FIELD\"='{}' = \"FEAT\"='{}'".format( selectedField, selectedFeature ))
#selection = layer.getFeatures(request)
writer = QgsVectorFileWriter.writeAsVectorFormat(selectedLayer, filename, 'utf-8', driverName='ESRI Shapefile', onlySelected=True)
selected_layer = self.iface.addVectorLayer(filename, '', 'ogr')
del(writer)