In a plugin I want to save the selected features in a new shapefile. I search and I try (How can I create a new layer from the currrent selection? to create a new layer and write the selected fields and features in that:
vl = QgsVectorLayer("Polygon", "temporary_points", "memory") pr = vl.dataProvider() # add geometry and fields pr.addAttributes(fields) pr.addFeatures(features)
In this image, the selected polygon is yellow and the pink polygon is the saved one as another shapefile. So the geometry is not completely correct and I need the perfect copy of the original.
Anyone knows how to get it?
I can use the algorithm from Processing Toolbox, "Save selected features".