I want to create a layer which use the same CRS as another layer I already have in the project. The idea is to avoid the CRS dialog.
I tried the things in this link: How to define layer's CRS and avoid the CRS dialog in PyQGIS?
But it doesn't work because as soon as I create the layer the program launches the dialog.
qgis.utils.iface.addVectorLayer("shapefile_path", "Layer_name", "ogr")
#Use loaded layer as active layer to set the CRS
myLayer = qgis.utils.iface.activeLayer()
myLayer.setCrs(QgsCoordinateReferenceSystem(4326, QgsCoordinateReferenceSystem.EpsgCrsId))
I tried something like
crs = originalLayer().crs().authid()
layer2 = QgsVectorLayer("Point", "auxlayer", "memory")
layer2.setCrs(QgsCoordinateReferenceSystem(crs))
And it works but only after the dialog appears.