With PyQGIS I am having trouble programming how to copy features between layers.
Goal: from a robust layer (with more fields) copy its features to a 'simple' version layer.
from qgis.core import *
mapLayer = QgsProject.instance().mapLayersByName("MySQL:forexeasy,host=localhost,port=3306 authcfg='z4s291g',tables=avenida_rua|layername=avenida_rua")[0]
selecionar estrutura dos fields name
criar um feature
clonar os
if (mapLayer.isValid()):
layer = QgsVectorLayer("D:\workstation\qgis\temp\fid_62.shp", 'lay', 'ogr')
if(layer.isValid()) :
print('init')
features = []
for feature in layer.getFeatures():
features.append(feature)
mapLayer.startEditing()
dataP = mapLayer.dataProvider()
dataP.addFeatures(features)
mapLayer.commitChanges()
Meanwhile, I get this error:
exec(open('C:/Users/LUISMH~1/AppData/Local/Temp/tmp2vbxv1cy.py'.encode('utf-8')).read()) Traceback (most recent call last): File "D:\OSGeo4W\apps\Python37\lib\code.py", line 90, in runcode exec(code, self.locals) File "<input>", line 1, in <module> File "<string>", line 3, in <module> IndexError: list index out of range ```
I don't know if I would have to create a feature for the destination layer. And pass on the attributes features from the layer to the destination feature. if so how?

