I need a temporary layer with the geometry created from selected features for a processing tool. The temporary layer is created but the geometry is missing. The attribute table is blank.
But when I printed the geometry it's showing on console.
Below is the code I am using:
layer = iface.activeLayer() # layer which has a selection
feat = layer.selectedFeatures()
fields = layer.fields()
selection = QgsVectorLayer('Point', 'temp', 'memory')
dp = selection.dataProvider()
dp.addAttributes(fields)
feats = selection.selectedFeatures()
for feat in feats:
geom = feat.geometry()
wkt = geom.asPoint()
print(wkt)
selection.commitChanges()
selection.updateExtents()
QgsProject.instance().addMapLayer(selection)
temp = QgsVectorLayer("D:\satya\cp.shp", "premises", "ogr")

