from qgis.core import QgsProject project = QgsProject.instance() # get the QGIS project instance project.setCrs(3857) # set the project CRS to EPSG:3857 project.write() # save the changes
from qgis.core import QgsProject, QgsVectorLayer project = QgsProject.instance() layer = QgsVectorLayer("/path/to/shapefile.shp", "layer_name", "ogr") project.addMapLayer(layer, False)In this example, we create a new `QgsVectorLayer` instance from a shapefile, then we add the layer to the current project using the `addMapLayer()` method of the `QgsProject` instance. The second argument of this method controls whether the layer should be added to the legend or not. This example demonstrates how to add a new layer to an existing QGIS project using the `QgsProject` instance. Package library: `qgis.core`